Gemini Crypto Exchange Logo
Multi Market Data

About

Multi market data is a public API which allows for multiple symbols to be streamed via a single endpoint.

The initial response message will show the existing state of the order books requested. Subsequent messages will show all executed trades, as well as all other changes to the order books from orders placed or canceled.


WebSocket Request

wss://api.gemini.com/v1/multimarketdata?symbols=BTCUSD,ETHUSD


URL Parameters

Parameter

Required

Default

Description

symbols

Yes

false

required. Will stream market data for symbols provided. Can provide data for multiple symbols on the same stream.

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:

  • If any entry type is specified as true or false, all of them must be explicitly flagged true to show up in the response
  • 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 that provides multiple symbols with each frame containing a JSON message of the following format:

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.

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.

symbol

string

Will return the order book for which the message type is for. Only symbols provided in the URL parameter will be present in the stream. BTCUSD, ETHUSD or any supported symbol


Examples

Multi Market Data Feed - BTCUSD & ETHUSD

import ssl
import websocket

def on_message(ws, message):
    print(message)

ws = websocket.WebSocketApp(
    "wss://api.gemini.com/v1/multimarketdata?symbols=BTCUSD,ETHUSD",
    on_message=on_message)
ws.run_forever(sslopt={"cert_reqs": ssl.CERT_NONE})
python
npm install -g wscat
wscat --connect wss://api.gemini.com/v1/v1/multimarketdata?symbols=BTCUSD,ETHUSD
< {"type":"update","eventId":773797793,"socket_sequence":0,"events":[{"type":"change","reason":"initial","price":"1.00","delta":"236.5","remaining":"236.5","side":"bid","symbol":"BTCUSD"},{"type":"change","reason":"initial","price":"2.00","delta":"176"},
...
{"type":"change","reason":"initial","price":"59137.50","delta":"0.00031","remaining":"0.00031","side":"ask","symbol":"BTCUSD"}]}
< {"type":"update","eventId":773797763,"socket_sequence":1,"events":[{"type":"change","reason":"initial","price":"6.95","delta":"9","remaining":"9","side":"bid","symbol":"ETHUSD"},
...
{"type":"change","reason":"initial","price":"1827.84","delta":"14.8","remaining":"14.8","side":"ask","symbol":"ETHUSD"}]}
< {"type":"update","eventId":773797906,"timestamp":1617045817,"timestampms":1617045817599,"socket_sequence":2,"events":[{"type":"trade","tid":773797906,"price":"57734.10","amount":"0.002","makerSide":"bid","symbol":"BTCUSD"},{"type":"change","side":"bid","price":"57734.10","remaining":"0.0107803","delta":"-0.002","reason":"trade","symbol":"BTCUSD"}]}
shell

Initial JSON response messages for BTCUSD and ETHUSD

{
    "type":"update",
    "eventId":773797793,"socket_sequence":0,
    "events":[
        {
            "type":"change",
            "reason":"initial",
            "price":"1.00",
            "delta":"236.5",
            "remaining":"236.5",
            "side":"bid",
            "symbol":"BTCUSD"
        },
...
        {
            "type":"change",
            "reason":"initial",
            "price":"59137.50",
            "delta":"0.00031",
            "remaining":"0.00031",
            "side":"ask",
            "symbol":"BTCUSD"
        }
    ]
}

{
    "type":"update",
    "eventId":773797763,"socket_sequence":1,
    "events":[
        {
            "type":"change",
            "reason":"initial",
            "price":"6.95",
            "delta":"9",
            "remaining":"9",
            "side":"bid",
            "symbol":"ETHUSD"
        },
...
        {
            "type":"change",
            "reason":"initial",
            "price":"1827.84",
            "delta":"14.8",
            "remaining":"14.8",
            "side":"ask",
            "symbol":"ETHUSD"
        }
    ]
}
json