Version 2
About
The initial response message will show the existing state of the order books and last 50 trades. Subsequent messages will show all executed trades, as well as all other changes to the order book from order placed or cancelled.
Level 2 Subscribe Message Fields
Send a JSON formatted message with the following fields upon connecting to v2/marketdata
Market data v2 is a public API that can stream all market and candle data across books. Market data v2 also supports multiple subscriptions in the same data feed.
WebSocket Request
wss://api.gemini.com/v2/marketdata
Subscription Message
After connecting to v2/marketdata
you can subscribe to any of the following data feeds.
Name | Data Description |
---|---|
l2 | Level 2 book data |
candles_1m | 1 minute candle data |
candles_5m | 5 minute candle data |
candles_15m | 15 minute candle data |
candles_30m | 30 minute candle data |
candles_1h | 1 hour candle data |
candles_6h | 6 hour candle data |
candles_1d | 1 day candle data |
To subcribe to a data feed, send a subscription message in the following format.
Field Name | Type | Values |
---|---|---|
type | string | subscribe |
subscriptions | array | |
-- name | string | l2 , candle_1m , etc. |
-- symbols | array | ["BTCUSD, "ETHBTC", ... ] |
Examples
BTC Market Data Feed
import ssl import websocket import _thread as thread def on_message(ws, message): print(message) def on_error(ws, error): print(error) def on_close(ws): print("### closed ###") def on_open(ws): def run(*args): ws.send(logon_msg) thread.start_new_thread(run, ()) if __name__ == "__main__": logon_msg = '{"type": "subscribe","subscriptions":[{"name":"l2","symbols":["BTCUSD","ETHUSD","ETHBTC"]}]}' websocket.enableTrace(True) ws = websocket.WebSocketApp("wss://api.gemini.com/v2/marketdata", on_message = on_message, on_error = on_error, on_close = on_close, on_open = on_open) ws.on_open = on_open ws.run_forever(sslopt={"cert_reqs": ssl.CERT_NONE})python
$ wscat --connect wss://api.gemini.com/v2/marketdata > connected (press CTRL+C to quit) > {"type": "subscribe","subscriptions":[{"name":"l2","symbols":["BTCUSD","ETHUSD","ETHBTC"]}]}shell