PoffertSwapDocs
Open app

For developers

Live feed (WebSocket)

Subscribe to new tokens, trades, candles and price updates in real time over a single WebSocket.

On this page

The live feed pushes changes the moment the data service has recorded them, so you do not have to poll the REST API. It is what keeps the app's charts and lists moving.

Devnet address wss://api-devnet.poffertswap.fun/ws
Format JSON text messages.
Who may connect Browsers from an allowed origin (otherwise the connection is refused with 403). Scripts that send no Origin header are fine. New connections are rate limited per address (429 when exceeded).

The conversation#

When you connect, the server greets you, and then you choose what to listen to.

text
← { "type": "hello", "maxSubscriptions": 10 }

→ { "op": "subscribe",   "channel": "global" }
→ { "op": "subscribe",   "channel": "market", "id": "<token mint or pool address>" }
→ { "op": "unsubscribe", "channel": "market", "id": "<token mint or pool address>" }

← { "type": "subscribed",   "channel": "global" }
← { "type": "subscribed",   "channel": "market:<address>" }
← { "type": "unsubscribed", "channel": "market:<address>" }
← { "type": "error", "message": "…" }

→ ping                          (the plain text "ping"; the answer is the plain text "pong")
  • You can hold up to 10 subscriptions on one connection. The 11th is refused with an error message.
  • A message larger than 512 bytes from you, an unknown op or an invalid address also gets an error message. The connection stays open.
  • Send the literal text ping now and then as a heartbeat. The platform answers pong without waking the server, so it is cheap.

Channels#

Channel What you get
global A message whenever a token is created or a token graduates.
market:<mint> Everything about one token: its trades (curve and, after graduation, its pool), price and state updates, candles, and its graduation.
market:<pool> Everything about one pool: its swaps, candles and reserve changes.

For a token page, subscribing to the mint alone is enough, because after graduation the pool's trades are also sent to the mint's channel.

Messages you receive#

The data inside is the same shape as the REST API, so amounts are strings in raw units.

Message Channels When
{ "type": "trade", "market": "…", "data": { …a trade… } } market:<market>, market:<mint> Every curve trade and every pool swap.
{ "type": "candle", "market": "…", "interval": 60, "data": { …a bar… } } market:<market> After a trade: the current bar for each of the six intervals (the interval is in seconds).
{ "type": "token_update", "data": { "mint": "…", "status": "…", "priceSol": …, "marketCapSol": …, "progressBps": …, "realSol": "…" } } market:<mint> The token's curve state or status changed.
{ "type": "pool_update", "data": { …a pool… } } market:<pool>, market:<token mint> A pool's reserves or LP supply changed, or a pool was created.
{ "type": "new_token", "data": { …a token… } } global A token was created.
{ "type": "graduated", "data": { "mint": "…", "pool": "…" } } global, market:<mint> A curve moved into its pool.

A small example#

js
const ws = new WebSocket('wss://api-devnet.poffertswap.fun/ws')

ws.onmessage = (event) => {
  if (event.data === 'pong') return
  const msg = JSON.parse(event.data)
  if (msg.type === 'hello') {
    ws.send(JSON.stringify({ op: 'subscribe', channel: 'global' }))
  } else if (msg.type === 'new_token') {
    console.log('new token:', msg.data.name, msg.data.mint)
  }
}

setInterval(() => ws.readyState === WebSocket.OPEN && ws.send('ping'), 30_000)

Good to know#

  • Nothing is replayed. If your connection drops, messages sent while you were away are not resent. After you reconnect, fetch the current state from the REST API once, then continue with the live messages. The web app does exactly this.
  • Only fresh events are published. A transaction older than two minutes (a backfill or a replay) is stored but not announced, so a catch-up never floods the feed.
  • Best effort. The data is written to the database first, and the announcement follows. If an announcement ever fails, it is logged and not retried, because the data is already safely stored. The REST API always has the full picture.
  • Reconnect with a delay. Use a growing delay between attempts instead of reconnecting in a tight loop.