Skip to main content

WebSocket stream

The GMX API streams oracle prices, trades, an order book, and hourly and daily candles with volume for every perpetual market on Arbitrum. The stream is served only at wss://arbitrum.gmxapi.io/v1/stream: gmxapi.ai hosts and other networks don't serve it. One connection can carry the trades, book, and candles of up to 16 markets. Use the stream to record GMX market data live, and the REST endpoints for history and one-off snapshots.

The stream is public and needs no API key. It has no SLA, and its limits can change at any time. GMX may require compression, add rate limits, and block or disconnect any client or IP address that loads it heavily or uses it abusively, without notice. The intervals and limits on this page are approximate and subject to change: don't depend on their exact values.

Connect​

wss://arbitrum.gmxapi.io/v1/stream
  • Only Arbitrum serves the stream, and only on the gmxapi.io host. Other networks and the gmxapi.ai hosts don't serve it.
  • No headers are required, User-Agent included.
  • Connect from a server. Browser connections from origins outside the GMX apps are refused. If a server client gets 403, stop it from sending an Origin header: in Python's websocket-client, pass suppress_origin=True.
  • We strongly recommend compression: offer permessage-deflate. Uncompressed connections receive about 3.5 times more bytes on the market channels and about 9 times more on prices, and GMX may stop accepting them.

When the server refuses the upgrade, the HTTP status tells why:

StatusReasonWhat to do
403An Origin header that the stream doesn't acceptSend no Origin header
429Too many connections from your IP addressUse fewer connections: one carries 16 markets
503The stream is temporarily unavailableRetry with backoff

Subscribe​

Send JSON text messages. List every channel in one message rather than one message per channel.

{
"op": "subscribe",
"channels": ["trades:0x47c031236e19d024b42f8AE6780E44A573170703", "book:0x47c031236e19d024b42f8AE6780E44A573170703"]
}
{ "op": "unsubscribe", "channels": ["book:0x47c031236e19d024b42f8AE6780E44A573170703"] }

The server answers each subscribe and unsubscribe with an ack that lists every channel the connection holds. Each new channel then starts with a snapshot: trades: at once, the other channels within about 5 seconds.

{
"op": "ack",
"channels": ["trades:0x47c031236e19d024b42f8AE6780E44A573170703", "book:0x47c031236e19d024b42f8AE6780E44A573170703"]
}

Problems come back as error messages, before the ack of the same subscribe. The rest of the message still applies.

messagechannelsCause
unknown channel(s) ignoredUp to 10 of the channels it doesn't serveA misspelled channel, a market address or token symbol in other letter case, a swap-only market, or a period that the channel doesn't serve
subscription limit reachedThe channels over a limitSee Limits
invalid JSON, invalid message, unknown opEmptyA malformed message

The channels of unknown channel(s) ignored leave out names longer than 64 characters.

Channels​

<market> is the market token address exactly as GET /markets and GET /pairs (pool_id) serve it. <symbol> is a token symbol exactly as GET /tokens serves it, such as BTC or ETH. Channel names are case-sensitive. Every market with an index token has channels; swap-only markets have none.

ChannelDataFrames
pricesThe oracle min and max price of every tokenA snapshot on each price change, at most every 250 ms
trades:<market>The market's fillsA snapshot of the recent fills on subscribe, then an update with each batch of new fills
book:<market>Levels of the market's price impact curveA snapshot when the price or the market data changes, at most every 250 ms
candles:<market>:1h, candles:<market>:1dThe market's current hourly or daily bar with volumeA snapshot when the bar changes, about every 5 seconds
candles:<symbol>:<period>The token's current price bar, without volumeA snapshot when the bar changes, about every 500 ms

Every frame has the same envelope:

{
"ch": "book:0x47c031236e19d024b42f8AE6780E44A573170703",
"type": "snapshot",
"seq": 4,
"serverTs": 1796124596994,
"originTs": 1796124594000,
"data": {}
}
FieldDescription
chThe channel
typesnapshot replaces what you hold for the channel: the prices, the book, or on candles: the bar with the same timestamp. On trades:, it replays recent fills instead: keep the fills you hold and add the ones with a new id. update adds new fills; only trades: sends updates. A channel can send a new snapshot at any time
seqbook: only, see Order book
serverTsWhen the server sent the frame, in Unix milliseconds
originTsWhen the source data was produced, in Unix milliseconds with whole-second precision. On prices and book:, the oldest timestamp among all token prices of the price snapshot, the same for every market; on trades:, the block time of the last fill. candles: frames and a trades: snapshot without fills don't carry it

Prices​

data maps each token address to its oracle minPrice and maxPrice. They are integer strings: divide them by 10^30 to get USD per whole token. For the oracle best bid and offer of a market, read its index token (indexTokenAddress on GET /markets): minPrice is the bid and maxPrice the ask. GET /prices/tickers serves the same prices.

This example keeps one of the 118 tokens, BTC at $61,250.43:

{
"ch": "prices",
"type": "snapshot",
"serverTs": 1796124593482,
"originTs": 1796124590000,
"data": {
"0x47904963fc8b2340414262125aF798B9655E58Cd": {
"minPrice": "61250426636492525000000000000000000",
"maxPrice": "61250426636492525000000000000000000"
}
}
}

Trades​

data.trades holds fills in the order that GMX indexed them, which is usually chain order. For chain order, sort by blockNumber, then logIndex.

FieldDescription
idThe order key. It is unique per fill: on GMX one order is one fill
tsThe block time, in Unix milliseconds. Arbitrum blocks carry whole seconds
priceThe fill price in USD per index token, price impact included
sizeIndex tokens: what an increase adds at the oracle price before price impact, or what a decrease removes from the position
sidebuy or sell, the trader's side. The trader is always the taker: buy opens a long or closes a short
notionalUsdThe USD size change that GMX counts as volume
typemarket_increase, limit_increase, stop_increase, market_decrease, limit_decrease, stop_loss_decrease, liquidation, or other. ADL fills come as market_decrease
bid, askThe oracle min and max price of the index token that the fill executed against, in USD per index token
priceImpactUsdThe fill's own price impact in USD, negative when it costs the trader
marketThe market token address
blockNumber, logIndex, transactionHashWhere the fill is on chain

price × size differs from notionalUsd. On an increase, the difference comes from the fill's price impact, which settles in proportion as the position decreases. On a decrease, the difference is the profit or loss of the removed size, the fill's own price impact included: positive for a long in profit, negative for a short in profit. It leaves out the impact that the increase left pending, so it can differ from the profit or loss that GMX reports for the fill. Read the price impact from priceImpactUsd, and sum notionalUsd for volume.

Fills usually reach the channel within about 11 seconds of their block, but they can arrive late. On subscribe, the snapshot replays up to 50 fills of the market from the last 10 minutes: drop the ids that you already hold. For history, use GET /markets/candles (see REST counterparts): each bar carries its volume and number of fills.

Example update:

{
"ch": "trades:0x70d95587d40A2caf56bd97485aB3Eec10Bee6336",
"type": "update",
"serverTs": 1796124307732,
"originTs": 1796124304000,
"data": {
"trades": [
{
"id": "0x0873d46f58801230b33b39ea8d97acd2686030cdab50ed6ea5dc092be578640d",
"ts": 1796124304000,
"price": "1709.918950703218",
"size": "0.37896999868905277",
"side": "buy",
"notionalUsd": "647.96337741543073143",
"type": "limit_increase",
"bid": "1709.80124985326",
"ask": "1709.80124985326",
"priceImpactUsd": "-0.044602020599928085125737208059",
"market": "0x70d95587d40A2caf56bd97485aB3Eec10Bee6336",
"blockNumber": 529135190,
"logIndex": 72,
"transactionHash": "0xf70c539fd9ccf95480eee638a32b10f3bb42a954d8c07ddafe6a8003aae374bf"
}
]
}
}

Order book​

GMX has no order book: a trade fills at the oracle price plus a price impact that grows with the trade size. book:<market> shows that curve as levels. data.bids and data.asks hold [price, size] levels, best first, with price in USD per index token and size in index tokens.

  • Levels end at cumulative order sizes: the market's minimum position size, then $1k, $2.5k, $5k, $10k, and so on (1, 2.5, and 5 × 10^n USD), up to the side's available liquidity, JIT liquidity included. The size of a level is the part between its end and the end of the level before it. Fees aren't in the levels.
  • The levels price an order that opens or increases a position: a long on the asks and a short on the bids. Such a market order of a level's cumulative size fills at the average price of the levels up to it, as the contract fills it, within rounding. An order that decreases a position can fill at a different price.
  • The number of levels follows the available liquidity. BTC/USD [BTC-USDC] has 17 per side, about 1.1 KB per frame before compression.
  • Prices keep 8 significant digits and get strictly worse level by level. The best bid stays below the best ask. Where the curve steps sharply, as when an order passes the balance of long and short open interest, the levels across the step merge at their average price, and a walk that ends inside the merged level gets that average price, which can be better or worse than the contract gives that size.
  • Positive price impact can put the best ask below the oracle bid, or the best bid above the oracle ask. The oracle prices on prices and the execution prices on book: are distinct.
  • For a best bid and offer with sizes, take the bid and ask from the index token on prices (see Prices), and their sizes from the first level of each side: bids[0][1] for the bid and asks[0][1] for the ask. The first level is usually the market's minimum position size, about $1. A side without levels has no quote. Keep the levels as they are for the depth behind them: the oracle prices added as levels can cross the book.
  • Every frame is a full snapshot. There are no incremental updates and no checksum: the next frame replaces the book.
  • seq increases by one per frame. Compare it only within one subscription: a gap means a missed frame. Two frames in a row can hold the same book.
  • A frame goes out when the price or the market data changes, at most every 250 ms. A market gets no frames while its data is unavailable: detect a dropped connection by WebSocket pings, not by a pause in frames. A disabled market gets one empty book.

Example, trimmed to 3 of 17 levels per side:

{
"ch": "book:0x47c031236e19d024b42f8AE6780E44A573170703",
"type": "snapshot",
"seq": 4,
"serverTs": 1796124596994,
"originTs": 1796124594000,
"data": {
"bids": [
["61250.056", "0.00001634"],
["61250.018", "0.0163102"],
["61249.93", "0.02448982"]
],
"asks": [
["61250.09", "0.00001632"],
["61250.127", "0.01631017"],
["61250.273", "0.02448968"]
]
}
}

Candles​

candles:<market>:1h and candles:<market>:1d send the market's current bar with volume:

FieldDescription
timestampThe bar's open time, in Unix milliseconds, UTC. Daily bars open at 00:00 UTC
open, high, low, closeThe oracle candles of the index token, in USD per token. Markets of one index token share them
volumeThe USD position size that the bar's fills changed: the figure GMX volume counts, one side, liquidations and ADL included, swaps and collateral-only changes excluded
tradesThe number of those fills
finaltrue once the indexed data is 2 minutes past the bar's close, so its volume and trades can't change. The channel sends the forming bar with false, but a closed bar that it sends late can carry true

candles:<symbol>:<period> sends the token's current price bar, the one that the GMX app's chart shows: only timestamp, open, high, low, and close, as above. The periods are 1m, 5m, 15m, 1h, 4h, and 1d. A token without oracle candles, such as GLV, gets an ack but no frames.

After a bar closes, a candle channel can send the closed bar again, alternating with the new bar, for about a minute. A frame can also carry an older state of the current bar. Keep each bar by its timestamp, and read closed bars from REST: GET /markets/candles for the market bars, GET /prices/ohlcv?symbol=<symbol>&timeframe=<period> for the price bars. GET /prices/ohlcv serves the newest bar first, and that bar can still be forming.

{
"ch": "candles:0x47c031236e19d024b42f8AE6780E44A573170703:1h",
"type": "snapshot",
"serverTs": 1796124594310,
"data": {
"timestamp": 1796122800000,
"open": "61233.65",
"high": "61422.23",
"low": "61182.94",
"close": "61251.4",
"volume": "12164.41948568036358235050564217387",
"trades": 18,
"final": false
}
}

Limits​

LimitValueOver the limit
trades:, book:, and candles:<market>: channels per connection64, the four channels of 16 marketsAn error with subscription limit reached. The other channels of the message still apply
prices and candles:<symbol>: channels per connection10The same
Connections per IP address50The upgrade is refused with 429
Size of a client message16 KB, about 300 channel namesThe connection is closed with code 1009
Client messages20 at once, then 2 per second. WebSocket pings don't countThe connection is closed with code 1008 and reason message rate limit exceeded
Connection age12 to 18 minutesThe connection is closed with code 1012: reconnect at once

Keepalive and reconnects​

  • The server sends a WebSocket ping every 30 seconds and drops a connection that hasn't answered by the next ping. Standard WebSocket clients answer pings on their own. The server also answers your pings.
  • The server closes every connection after 12 to 18 minutes, and when it restarts, with close code 1012 (Service Restart). Reconnect and subscribe again at once. A connection that the server drops closes without a close frame, 1006 on most clients: reconnect with backoff.
  • Read frames as soon as they arrive. A client that falls behind misses snapshot frames and gets disconnected.
  • After a reconnect, start from the new snapshots: book: and candles: send the current state, and trades: replays up to 50 fills from the last 10 minutes. Drop the fill ids that you already hold. Compare seq only within one subscription.

REST counterparts​

The base URL https://arbitrum.gmxapi.io/v1 serves what the stream doesn't carry and the history it doesn't keep. Only this host serves GET /markets/book and GET /markets/candles: arbitrum.gmxapi.ai and the other networks don't. The GMX API OpenAPI Reference has the schemas.

NeedEndpoint
Markets and their idsGET /pairs: take the Perpetual rows, whose pool_id is the market. GET /markets adds the index token
A book snapshotGET /markets/book?market=<market>&depth=<levels>: the latest book, with its seq. seq can be null. It answers 404 for a disabled market or one without a token price, and 503 while the market data is stale
Candle historyGET /markets/candles?market=<market>&period=1h&limit=1000&to=<ms>: the same bars, ascending, at most 1000 per call. Hourly bars reach back about 180 days, daily bars as far as the index token's oracle candles go, with zero volume before the market's first fill
Top of bookGET /markets/book?market=<market>&depth=1: the first level of each side, to check the book you hold against. GET /prices/tickers serves the oracle bid and ask
Open interest and fundingGET /pairs and GET /markets/info

A REST book can differ from the latest frame on your connection.

Errors come back as HTTP statuses with a JSON body, except a request cut by the 60-second timeout, which gets 503 with a plain-text body.

Units and conventions​

  • Prices are in USD per whole index token. On the stream, only prices uses integers scaled by 10^30; GET /prices/tickers uses the same scale.
  • GMX has no separate mark price: the oracle prices on prices serve as the mark and index price, and fills are priced from them.
  • Book and trade sizes are in index tokens. GMX has no contracts, tick size, or step size: positions are sized in USD.
  • Volume is the sum of notionalUsd, one side, each fill once. On a decrease, it is the USD value of the removed size at its entry price.
  • Open interest on GET /pairs is in USD, long and short separately: long_open_interest and short_open_interest.
  • funding_rate on GET /pairs is the hourly rate in percent, positive when longs pay shorts. Funding accrues every second. next_funding_rate_timestamp, in Unix seconds, is only the next hour mark.
  • Every timestamp is UTC. Candles are stamped at their open, and daily candles cover UTC days.