Real-time Bitcoin Market Data

To illustrate CoralMD, we launched a free server that provides aggregated and per exchange real-time Bitcoin market data. The exchanges we are currently connected to are: Coinbase and Okcoin. Below we explain the three choices of API and protocol you can use to receive live market data updates.

HTTP

Browsers and other http clients can make requests to the URLs below to get a full market data book snapshot in JSON format. The server caches the response for 2 seconds, so any successive requests less than 2 seconds apart will return the same data. This is enough for GUIs and other higher-latency applications. For low-latency real-time updates you should use the TCP or the FIX API.

{
    "success":			true,
    "last updated":		"20151022-03:28:18.676",
    "time zone":		"America/New_York",
    "symbol":			"BTC-USD",
    "exchange code":		"AGGR",
    "exchange name":		"Aggregated",
    "spread":			-2.06,
    "best bid size":		0.02000000,
    "best bid price":		270.60,
    "best ask size":		0.90000000,
    "best ask price":		268.54,

    "bids": [

        [ "BASE",		0.02000000,		270.60],
        [ "BASE",		0.02000000,		270.59],
        [ "BASE",		0.02000000,		270.58],
        ...
    ],

    "asks": [

        [ "OKCN",		0.90000000,		268.54],
        [ "OKCN",		0.86100000,		268.58],
        [ "OKCN",		2.34470000,		268.60],
        ...
    ]
}


FIX

We use FIX version 4.4. The standard FIX header (i.e. BeginString, MsgType, MsgSeqNum, SenderCompID and SendingTime) must be present in every message. The SenderCompID is your username. Click here to contact us and get the host, port, username and password to connect. Messages not specified below (i.e. Heartbeat, Test Request, etc.) follow the standard FIX format.

Message Short Description

To start a FIX session

Description

You use the Logon message to start a FIX session with the server. The server will reply with a Logon message to indicate that the logon was successful or with a Logout message to indicate that there was a problem with the logon.
          

Format

Tag Name Description
98 EncryptMethod Must always be '0'
108 HeartBtInt The heartbeat interval in seconds. '30' is a good value.
553 Username Your username. Contact Coral Blocks to get one.
554 Password Your password. Contact Coral Blocks to get one.
141 ResetSeqNumFlag Should always be 'Y' to reset the sequences on every new logon.

To end a FIX session

Description

The Logout message can be sent by the client to gracefully disconnect or it can be sent by the server to indicate that a logon attempt was not successful. In that case you should check the Text tag for clues.
          

Format

Tag Name Description
58 Text A description of why the Logon from the client was not accepted (when coming from server)

To subscribe to market data

Description

The MarketDataRequest message can be sent by the client to subscribe to market data. The server supports subscription to all securities or individual subscriptions. The client can also use this message to unsubscribe. If the subscription is successful, the client will receive a MarketDataSnapshotFullRefresh with the book. When unsubscribing, the client will receive a MarketDataSnapshotFullRefresh with an empty book if successful.
          

Format

Tag Name Description
262 MDReqID An identifier number for this request (will be sent back with the MarketDataSnapshotFullRefresh response)
263 SubscriptionRequestType 'A' - subscribe to all
'X' - unsubscribe from all
'S' - subscribe to a single symbol
'U' - unsubscribe from a single symbol
55 Symbol Required when SubscriptionRequestType above is 'S' or 'U'

To subscribe to market data

Description

The MarketDataRequestReject message is sent back by the server when it cannot process the MarketDataRequest sent by the client. It contains the reason why the request was rejected.
          

Format

Tag Name Description
262 MDReqID The identifier number used in the MarketDataRequest
281 MDReqRejReason '0' - Tag Missing
'1' - You are already subscribed to all
'2' - No book for requested symbol
'3' - Invalid SubscriptionRequestType tag value
58 Text A text description with more details about the reject reason

Provides the full view of a market data book, with all open orders

Description

The MarketDataSnapshotFullRefresh message is sent by the server to provide the full market data book for a security. The server sends only one MarketDataSnapshotFullRefresh per symbol, never two symbols in the same message. This message is only sent as a response for a MarketDataRequest message. When processing this message, the client should clear his book before adding the orders.
          

Format

Tag Name Description
262 MDReqID The identifier number that was sent with the MarketDataRequest
55 Symbol Required when SubscriptionRequestType from the MarketDataRequest was 'S' or 'U'
268 NoMDEntries The number of entries for the repeating group containing the orders
=> 279 MDUpdateAction '0' - Order added (always)
=> 54 Side '1' - Bid
'2' - Ask
=> 5001 FeedID The id number of the feed that originated this order
(currently each exchange is coming from only one feed, so we have four different feeds, one for each exchange)
=> 5002 ExchangeID "BASE" - Coinbase
"OKCN" - Okcon
"SETR" - Coinsetter
"LAKE" - LakeBTC
=> 5003 Timestamp The epoch timestamp in milliseconds
=> 278 MDEntryID The order id number
=> 271 MDEntrySize The size of the order
=> 270 MDEntryPx The price of the order
=> 270 MDEntryPx The price of the order
=> 5004 Ownership 'Y' - The order is mine
'N' - The order is not mine or it can't be determined at this point

Provides incremental updates for subscribed market data books

Description

The MarketDataIncrementalRefresh message is sent by the server to provide incremental updates for subscribed securities. Updates for more than one symbol can come on the same message. It is also used to indicate a live trade and to signal that a book for a security should be cleared.
          

Format

Tag Name Description
268 NoMDEntries The number of entries for the repeating group containing the updates
=> 279 MDUpdateAction '0' - Order added
'1' - Order modified
'2' - Order removed
'O' - Order owned
'T' - Live Trade (will not contain the Side and the MDEntryID)
'C' - Book cleared (will only contain the FeedID, ExchangeID (optionally) and Symbol)
=> 54 Side '1' - Bid
'2' - Ask
=> 55 Symbol The symbol of this update
=> 5001 FeedID The id number of the feed that originated this order
(currently each exchange is coming from only one feed, so we have four different feeds, one for each exchange)
=> 5002 ExchangeID "BASE" - Coinbase
"OKCN" - Okcon
"SETR" - Coinsetter
"LAKE" - LakeBTC
=> 5003 Timestamp The epoch timestamp in milliseconds (not sent for MDUpdateAction 'C' and 'O')
=> 278 MDEntryID The order id number
=> 271 MDEntrySize The size of the order (not sent for MDUpdateAction '2', 'C' and 'O')
=> 270 MDEntryPx The price of the order (not sent for MDUpdateAction '2', 'C' and 'O')

TCP

For low-latency you should use our TCP API which is shorter and faster than FIX. It uses a byte-payload protocol where the first byte contains the size of the payload that follows. All binary numbers follow the big-endian network format. If you are using Java, you can use the ByteBuffer methods getShort (2 bytes), getInt (4 bytes) and getLong (8 bytes) to read binary numbers. The “Z” message (batch end) is always sent after previous update messages to denote that a full batch update has been sent by the server. That way the client might choose to take action only after a full batch has been received instead of taking action on individual updates. (Note: For FIX you can assume that each MarketDataIncrementalRefresh message contains a batch)

Message Short Description

To login to the server

Description

The Login message must be the first message sent by the client to the server upon connection. It provides username, password and the heartbeat interval the client wants to configure. The server will reply with an 'L' message back (without any fields) to indicate that the login was successful.
          

Format

Name Size Description
Type 1 (ascii) 'L'
Heartbeat 4 (int) The heartbeat interval in seconds the client wants to configure
Username 12 (ascii) Your username. Contact Coral Blocks to get one.
Password 12 (ascii) Your password. Contact Coral Blocks to get one.

Sent by the server to indicate that an error happened

Description

The server can send an error message to indicate any error condition like for example if the client can't be authenticated. It contains a text message with the details about the error. The text field does not have a fixed length. Its length will be the remaining of the message.
          

Format

Name Size Description
Type 1 (ascii) 'E'
Text remaining (ascii) A text message with the details of the error

Message to subscribe to all symbols

Description

The client sends a SubscribeAll message to receive updates for all books. The server will reply with another 'A' message back if the subscription was successful. The client will receive all open orders from all books immediately after subscribing to all, so it should clear its books before sending this message. (Note: The subscription confirmation ('A' back) is sent by the server only after all orders are resent to the client)
          

Format

Name Size Description
Type 1 (ascii) 'A'

Message to unsubscribe from all symbols

Description

The client sends an UnsubscribeAll message to stop receiving updates for all books. The server will reply with another 'X' message back if the unsubscribe request was successful. The client should clear all its books after receiving the unsubscribe confirmation back from the server.
          

Format

Name Size Description
Type 1 (ascii) 'X'

Message to subscribe to a symbol

Description

The client sends a Subscribe message to subscribe for updates for a single symbol. The server will reply with another 'S' message back if the subscription was successful. The client will receive all open orders for the requested symbol immediately after sending the subscription, so it should clear its book before sending this message. (Note: The subscription confirmation ('S' back) is sent by the server only after all orders for the symbol are resent to the client)
          

Format

Name Size Description
Type 1 (ascii) 'S'
Symbol remaining (ascii) The symbol to subscribe

Message to unsubscribe from a symbol

Description

The client sends an Unsubscribe message to stop receiving updates for the provided symbol. The server will reply with another 'U' message back if the unsubscribe request was successful. The client should clear the book for the symbol after receiving the unsubscribe confirmation back from the server.

Format

Name Size Description
Type 1 (ascii) 'U'
Symbol remaining (ascii) The symbol to subscribe

Heartbeat to keep the connection alive

Description

The client should send a heartbeat message after a period of inactivity, in other words, after a period of silence when it hasn't sent any messages to the server. The heartbeat period is configured in the Login message. If the server does not receive any message after the heartbeat interval it disconnects the client due to a read timeout. The server also sends heartbeats to the client.

Format

Name Size Description
Type 1 (ascii) 'H'

New order added to the book

Description

The server sends a NewOrder message to indicate that a new order was added to the book.

Format

Name Size Description
Type 1 (ascii) 'N'
FeedID 4 (int) The id number of the feed that originated this order
(currently each exchange is coming from only one feed, so we have four different feeds, one for each exchange)
ExchangeID 4 (ascii) "BASE" - Coinbase
"OKCN" - Okcon
"SETR" - Coinsetter
"LAKE" - LakeBTC
Timestamp 8 (long) The epoch timestamp in milliseconds
OrderID 8 (long) The order id number
Side 1 (ascii) 'B' - Bid
'A' - Ask
Size 8 (long) The order size. Must be divided by 100,000,000 for the decimal size
Price 8 (long) The order price. Must be divided by 100,000,000 for the decimal price
Ownership 1 (ascii) 'Y' - The order is mine
'N' - The order is not mine or it can't be determined at this point
Symbol remaining (ascii) The symbol to where this order belongs

This order should now be marked as mine

Description

The server sends a OwnOrder message to indicate that this order should be marked as mine.

Format

Name Size Description
Type 1 (ascii) 'N'
FeedID 4 (int) The id number of the feed that originated this order
(currently each exchange is coming from only one feed, so we have four different feeds, one for each exchange)
ExchangeID 4 (ascii) "BASE" - Coinbase
"OKCN" - Okcon
"SETR" - Coinsetter
"LAKE" - LakeBTC
OrderID 8 (long) The order id number
Side 1 (ascii) 'B' - Bid
'A' - Ask
Symbol remaining (ascii) The symbol to where this order belongs

An existing order was modified

Description

The server sends a ModifyOrder message to indicate that an order was modified and should be updated in the client book. This message has the same format as the NewOrder message, with a different type ('M' instead of 'N').

Format

Name Size Description
Type 1 (ascii) 'M'
FeedID 4 (int) The id number of the feed that originated this order
(currently each exchange is coming from only one feed, so we have four different feeds, one for each exchange)
ExchangeID 4 (ascii) "BASE" - Coinbase
"OKCN" - Okcon
"SETR" - Coinsetter
"LAKE" - LakeBTC
Timestamp 8 (long) The epoch timestamp in milliseconds
OrderID 8 (long) The order id number
Side 1 (ascii) 'B' - Bid
'A' - Ask
Size 8 (long) The order size. Must be divided by 100,000,000 for the decimal size
Price 8 (long) The order price. Must be divided by 100,000,000 for the decimal price
Symbol remaining (ascii) The symbol to where this order belongs

An existing order was removed from the book

Description

The server sends a RemoveOrder message to indicate that an order was deleted and should be removed from the client book.

Format

Name Size Description
Type 1 (ascii) 'R'
FeedID 4 (int) The id number of the feed that originated this order
(currently each exchange is coming from only one feed, so we have four different feeds, one for each exchange)
ExchangeID 4 (ascii) "BASE" - Coinbase
"OKCN" - Okcon
"SETR" - Coinsetter
"LAKE" - LakeBTC
Timestamp 8 (long) The epoch timestamp in milliseconds
OrderID 8 (long) The order id number
Side 1 (ascii) 'B' - Bid
'A' - Ask
Symbol remaining (ascii) The symbol to where this order belongs

A batch of order changes is completed

Description

The server sends a BatchEnd message to indicate that it has sent a full batch of book changes. The client might want to take action only after a full batch has been received instead of taking action on each individual book update. A client can assume that it will always receive a 'Z' message after one or more book update messages.

Format

Name Size Description
Type 1 (ascii) 'Z'

A trade happened

Description

The server sends a LiveTrade message to indicate that a trade in one of the exchanges has occured.

Format

Name Size Description
Type 1 (ascii) 'T'
FeedID 4 (int) The id number of the feed that originated this trade
(currently each exchange is coming from only one feed, so we have four different feeds, one for each exchange)
ExchangeID 4 (ascii) "BASE" - Coinbase
"OKCN" - Okcon
"SETR" - Coinsetter
"LAKE" - LakeBTC
Timestamp 8 (long) The epoch timestamp in milliseconds
Size 8 (long) The trade size. Must be divided by 100,000,000 for the decimal size
Price 8 (long) The trade price. Must be divided by 100,000,000 for the decimal price
Symbol remaining (ascii) The symbol that was traded

Clear the book for this feed ID

Description

The server sends a ClearBook message to indicate that the client should clear all orders belonging to this feed ID for the given symbol.

Format

Name Size Description
Type 1 (ascii) 'K'
FeedID 4 (int) The id number of the feed that needs to be cleared
Symbol remaining (ascii) The symbol that needs to be cleared

Clear the book for this feed ID and exchange ID

Description

The server sends a ClearBookByExchange message to indicate that the client should clear all orders belonging to this feed ID and exchange ID for the given symbol.

Format

Name Size Description
Type 1 (ascii) 'C'
FeedID 4 (int) The id number of the feed that needs to be cleared
ExchangeID 4 (ascii) The exchange that needs to be cleared
Symbol remaining (ascii) The symbol that needs to be cleared