Gemini Crypto Exchange Logo
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.

NameData Description
l2Level 2 book data
candles_1m1 minute candle data
candles_5m5 minute candle data
candles_15m15 minute candle data
candles_30m30 minute candle data
candles_1h1 hour candle data
candles_6h6 hour candle data
candles_1d1 day candle data

To subcribe to a data feed, send a subscription message in the following format.

Field NameTypeValues
typestringsubscribe
subscriptionsarray
-- namestringl2, candle_1m, etc.
-- symbolsarray["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