Market data is a public API that streams all the market data on a given symbol.
The initial response message will show the existing state of the order book for both bids and offers, regardless of the additional parameters applied in the URL. Subsequent messages will show all executed trades, as well as all other changes to the order book from orders placed or canceled.
WebSocket Request
wss://api.gemini.com/v1/marketdata/:symbol
URL Parameters
Parameter Required Default Description heartbeat
No false Optionally add this parameter and set to true
to receive a heartbeat
every 5 seconds
top_of_book
No false If absent or false
, receive full order book depth; if present and
true
, receive top of book only. Only applies to bids and offers.
bids
No true Include bids in change
events offers
No true Include asks in change
events trades
No true Include trade
events
The semantics of entry type filtering is:
To be excluded from change
events in the response, an entry type must be explicitly flagged false
If no entry types filtering parameters are included in the url, then all entry types will appear in the response
Note : top_of_book
has no meaning and initial book events are empty when only trades
is specified
Response
A WebSocket stream with each frame containing a JSON message of the following format:
Shared fields
Field Type Description type
string heartbeat
or update
socket_sequence
integer Zero-indexed monotonic increasing sequence number attached to each
message sent — if there is a gap in this sequence, you have missed a
message. If you choose to enable heartbeats, then heartbeat
and
update
messages will share a single increasing sequence. See Sequence
Numbers for more information.
Messages with type heartbeat
have no additional fields.
update
-only fields
Messages of type update
have the following additional fields:
Field Type Description eventId
integer A monotonically increasing sequence number indicating when this change
occurred. These numbers are persistent and consistent between market
data connections.
events
array Either a change to the order book, or the indication that a trade has
occurred.
timestamp
timestamp The timestamp in seconds for this group of events (included for
compatibility reasons). We recommend using the timestampms
field
instead.
timestampms
timestampms The timestamp in milliseconds for this group of events.
Common fields
All elements of the events
share the following fields:
Field Type Description type
string Either trade
or change
.
Examples
BTC Market Data Feed
import ssl
import websocket
def on_message (ws, message):
print (message)
ws = websocket.WebSocketApp(
"wss://api.gemini.com/v1/marketdata/BTCUSD" ,
on_message = on_message)
ws.run_forever( sslopt = { "cert_reqs" : ssl. CERT_NONE })
npm install -g wscat
wscat --connect wss://api.gemini.com/v1/marketdata/btcusd
Offers only, top of book
import ssl
import websocket
def on_message (ws, message):
print (message)
ws = websocket.WebSocketApp(
"wss://api.gemini.com/v1/marketdata/btcusd?top_of_book=true&bids=false" ,
on_message = on_message)
ws.run_forever( sslopt = { "cert_reqs" : ssl. CERT_NONE })
$ wscat --connect=wss://api.gemini.com/v1/marketdata/btcusd ? top_of_book=true\&bids=false
connected (press CTRL+C to quit )
< { "type" : "update" , "eventId" :35015, "socket_sequence" :0, "events" : [{ " type ":" change "," reason ":" initial "," price ":" 6629.89 "," delta ":" 13.928195144 "," remaining ":" 13.928195144 "," side ":" ask "}]}
< {" type ":" update "," eventId ":35051," timestamp ":1528247534," timestampms ":1528247534252," socket_sequence ":1," events ":[{" type ":" top-of-book "," side ":" ask "," price ":" 6631.44 "," remaining ":" 33.96746891 "}]}
< {" type ":" update "," eventId ":35053," timestamp ":1528247534," timestampms ":1528247534252," socket_sequence ":2," events ":[{" type ":" top-of-book "," side ":" ask "," price ":" 6631.44 "," remaining ":" 28.267969234 "}]}
< {" type ":" update "," eventId ":35117," timestamp ":1528247538," timestampms ":1528247538541," socket_sequence ":3," events ":[{" type ":" top-of-book "," side ":" ask "," price ":" 6633.04 "," remaining ":" 23.53504107 "}]}
< {" type ":" update "," eventId ":35122," timestamp ":1528247538," timestampms ":1528247538745," socket_sequence ":4," events ":[{" type ":" top-of-book "," side ":" ask "," price ":" 6633.87 "," remaining ":" 19.15815988 "}]}
Trades only
import ssl
import websocket
def on_message (ws, message):
print (message)
ws = websocket.WebSocketApp(
"wss://api.gemini.com/v1/marketdata/btcusd?trades=true" ,
on_message = on_message)
ws.run_forever( sslopt = { "cert_reqs" : ssl. CERT_NONE })
$ wscat --connect=wss://api.gemini.com/v1/marketdata/btcusd ? trades=true
connected (press CTRL+C to quit )
< { "type" : "update" , "eventId" :62653, "socket_sequence" :0, "events" : []}
< { "type" : "update" , "eventId" :62711, "timestamp" :1528249346, "timestampms" :1528249346783, "socket_sequence" :1, "events" : [{ " type ":" trade "," tid ":62711," price ":" 6619.37 "," amount ":" 7.8662471812 "," makerSide ":" ask "}]}
< {" type ":" update "," eventId ":62713," timestamp ":1528249346," timestampms ":1528249346783," socket_sequence ":2," events ":[{" type ":" trade "," tid ":62713," price ":" 6619.46 "," amount ":" 13.9673234988 "," makerSide ":" ask "}]}
< {" type ":" update "," eventId ":62795," timestamp ":1528249351," timestampms ":1528249351276," socket_sequence ":3," events ":[{" type ":" trade "," tid ":62795," price ":" 6619.46 "," amount ":" 16.7321435012 "," makerSide ":" ask "}]}
< {" type ":" update "," eventId ":62797," timestamp ":1528249351," timestampms ":1528249351276," socket_sequence ":4," events ":[{" type ":" trade "," tid ":62797," price ":" 6619.70 "," amount ":" 2.3054248088 "," makerSide ":" ask "}]}
< {" type ":" update "," eventId ":62823," timestamp ":1528249352," timestampms ":1528249352909," socket_sequence ":5," events ":[{" type ":" trade "," tid ":62823," price ":" 6619.70 "," amount ":" 0.0002606894 "," makerSide ":" ask "}]}
< {" type ":" update "," eventId ":62830," timestamp ":1528249353," timestampms ":1528249353316," socket_sequence ":6," events ":[{" type ":" trade "," tid ":62830," price ":" 6610.15 "," amount ":" 0.00273253 "," makerSide ":" bid "}]}
Full depth, bids and offers only
import ssl
import websocket
def on_message (ws, message):
print (message)
ws = websocket.WebSocketApp(
"wss://api.gemini.com/v1/marketdata/btcusd?bids=true&offers=true" ,
on_message = on_message)
ws.run_forever( sslopt = { "cert_reqs" : ssl. CERT_NONE })
$ wscat --connect=wss://api.gemini.com/v1/marketdata/btcusd ? bids=true &offers = true
connected (press CTRL+C to quit )
< { "type" : "update" , "eventId" :64575, "socket_sequence" :0, "events" : [{ " type ":" change "," reason ":" initial "," price ":" 6511.13 "," delta ":" 26.93362206 "," remaining ":" 26.93362206 "," side ":" bid "},{" type ":" change "," reason ":" initial "," price ":" 6823.47 "," delta ":" 34.526471 "," remaining ":" 34.526471 "," side ":" ask "}]}
< {" type ":" update "," eventId ":64609," timestamp ":1528249465," timestampms ":1528249465320," socket_sequence ":1," events ":[{" type ":" change "," side ":" ask "," price ":" 6622.84 "," remaining ":" 16.49742094 "," delta ":" 16.49742094 "," reason ":" place "}]}
< {" type ":" update "," eventId ":64634," timestamp ":1528249466," timestampms ":1528249466750," socket_sequence ":2," events ":[{" type ":" change "," side ":" bid "," price ":" 6592.30 "," remaining ":" 18.97068216 "," delta ":" 18.97068216 "," reason ":" place "}]}
< {" type ":" update "," eventId ":64651," timestamp ":1528249467," timestampms ":1528249467565," socket_sequence ":3," events ":[{" type ":" change "," side ":" ask "," price ":" 6636.75 "," remaining ":" 16.10859393 "," delta ":" 16.10859393 "," reason ":" place "}]}
< {" type ":" update "," eventId ":64656," timestamp ":1528249467," timestampms ":1528249467975," socket_sequence ":4," events ":[{" type ":" change "," side ":" ask "," price ":" 6642.91 "," remaining ":" 23.553287 "," delta ":" 23.553287 "," reason ":" place "}]}
< {" type ":" update "," eventId ":64663," timestamp ":1528249468," timestampms ":1528249468587," socket_sequence ":5," events ":[{" type ":" change "," side ":" ask "," price ":" 6635.61 "," remaining ":" 17.97336167 "," delta ":" 17.97336167 "," reason ":" place "}]}
< {" type ":" update "," eventId ":64678," timestamp ":1528249469," timestampms ":1528249469405," socket_sequence ":6," events ":[{" type ":" change "," side ":" bid "," price ":" 6596.96 "," remaining ":" 21.93141551 "," delta ":" 21.93141551 "," reason ":" place "}]}
< {" type ":" update "," eventId ":64703," timestamp ":1528249471," timestampms ":1528249471450," socket_sequence ":7," events ":[{" type ":" change "," side ":" bid "," price ":" 6588.67 "," remaining ":" 17.66913232 "," delta ":" 17.66913232 "," reason ":" place "}]}
< {" type ":" update "," eventId ":64708," timestamp ":1528249471," timestampms ":1528249471858," socket_sequence ":8," events ":[{" type ":" change "," side ":" ask "," price ":" 6623.78 "," remaining ":" 16.44716907 "," delta ":" 16.44716907 "," reason ":" place "}]}
< {" type ":" update "," eventId ":64736," timestamp ":1528249474," timestampms ":1528249474104," socket_sequence ":9," events ":[{" type ":" change "," side ":" ask "," price ":" 6623.89 "," remaining ":" 36.91752526 "," delta ":" 36.91752526 "," reason ":" place "}]}
< {" type ":" update "," eventId ":64748," timestamp ":1528249475," timestampms ":1528249475127," socket_sequence ":10," events ":[{" type ":" change "," side ":" ask "," price ":" 6630.94 "," remaining ":" 17.8888451 "," delta ":" 17.8888451 "," reason ":" place "}]}
Initial JSON response message for BTC top of book
{
"type" : "update" ,
"eventId" : 5375461993 ,
"socket_sequence" : 0 ,
"events" : [
{
"type" : "change" ,
"reason" : "initial" ,
"price" : "3641.61" ,
"delta" : "0.83372051" ,
"remaining" : "0.83372051" ,
"side" : "bid"
},
{
"type" : "change" ,
"reason" : "initial" ,
"price" : "3641.62" ,
"delta" : "4.072" ,
"remaining" : "4.072" ,
"side" : "ask"
}
]
}
Heartbeat message
If heartbeat is enabled:
{
"type" : "heartbeat" ,
"socket_sequence" : 30
}
Last modified on October 1, 2025