Crypto Order Book: Part IV, Gemini.

In the past three parts of this series of articles, we discussed the order books of three crypto-exchanges (i.e. Bitfinex, Bitstamp, and Kraken) and highlighted some problems and issues and pitfalls that we have discovered. Hopefully those highlights have saved you some time in figuring out how to get the order book data correct (if you don’t want to invent your own data pipeline, you could always use us: cryptochassis.com). Today we’ll move to the next exchange (Gemini) and reveal an issue which by itself is small but might have profound implications. So this article’s going to short (and sweet:)).

For regular data providers and traders, the most interesting and important part of an order book is the top of the book, i.e. best bid and best ask. On Gemini, we would listen on change events of the top of book by simply doing this in a terminal (e.g. if we are sell-side traders and only interested in bids):

wscat -c 'wss://api.gemini.com/v1/marketdata/bchusd?bids=true&top_of_book=true'

Waiting patiently for a while (sometimes this can be as short as less than one minute), you will notice that our client is disconnected with code 1006.

Websocket disconnected with code 1006
Websocket disconnected with code 1006

From https://developer.mozilla.org/en-US/docs/Web/API/CloseEvent, 1006 = Abnormal Closure = Used to indicate that a connection was closed abnormally (that is, with no close frame being sent) when a status code is expected. The above observation is highly reproducible. Among all the exchanges that we have investigated, Gemini is the only one having such problems. Our hypothesized theory about it is that when a trading pair (such as Bitcoin Cash against USD) isn’t active enough the connection gets dropped which shouldn’t happen. If the server side would like to save computing resources and network bandwidth, what it should do is that: send a ping frame to the client, and if (and only if) the client doesn’t reply with a pong frame in a timely manner the server could send a close frame to the client and drop the connection. This is what the websocket standard has mandated (not just recommended). Frequent abnormal closure of websocket connections cause serious problems on data providers and traders. Data providers will have frequent data gaps and traders will miss golden opportunities.

With all those said, we have discovered a solution to work around the disconnection problem: by adding the “heartbeat” parameter to the connection url, we are able to obtain a long-lasting connection. Cheers!

wscat -c 'wss://api.gemini.com/v1/marketdata/bchusd?bids=true&top_of_book=true&heartbeat=true'

If you are a trader or fund manager or financial researcher and need to have access to high-fidelity historical tick data on crypto quotes and trades, and want to avoid all these headaches that we’ve mentioned in the past several articles, feel free to download our data set at cryptochassis.com.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store