OrderBook Heatmap visualizes the limit order book, compares resting limit orders and shows a time & sales log with live market data streamed directly from the Binance WS API. This was a short exploratory project. Keep in mind that a lot of work is needed for this to work in all market conditions.
Try it with live data: https://elenchev.github.io/order-book-heatmap/
This repo implements a live limit order book heatmap, resting limit orders graph and a buffered time & sales log. Market data is received through a custom Binance WS client, which feeds data into a simple orderbook structure, responsible for keeping track of all market deltas and returning snapshots to the D3 visualizations.
The main goal of this project was to familiarize myself with the Binance WS APIs and the data streams that they provide. Keep in mind that this was written in a couple of days, it's nowhere near close to handling all possible market states.
Binance WS Client (100% coverage) + some of the Binance REST API requests (5% coverage) but only what was necessary - mostly symbol info & snapshot requests. There are better clients out there, but I wanted to get familiar with the API. I recommend using a different client, but if you're interested in this implementation, check out examples/datafeed-example.js
The class lets users subscribe to 1 or more data streams and reuses streams if multiple clients subscribe to the same one. It's pretty easy to use. The following command will log all BTC/USDT trades to the console:
feed.subscribe('BTCUSDT', {
onTrade: (data) => console.log(data)
});
Limit order book implementation, which depends on BinanceDataFeed.js
. Internal structures keep a live representation of the limit order book. The class also keeps track of all trades and calculates some simple statistics. Check out examples/orderbook-example.js
to see how to use it.
BinanceOrderBook.js provides a getSnapshot
method, which is what the visualization modules use in order to display all heatmaps & charts.
Unfortunately Binance uses strings for all prices, volumes & quantities, instead of just returning the number of ticks (int) representing the price. Simply using parseFloat introduces a lot of inaccuracies. Tick.js
handles all this by allowing you to work with ticks instead of strings. It lets you parse, round, add, subtract, increment, decrement, multiply and divide. It also handles aggregation, if you want to use the same instance to work with ticks as well as steps (multiples of N ticks).
This class makes calls lib/BinanceOrderBook.js
on regular intervals specified by the user, and uses the snapshot provided by it to render different visualizations. Some notable features: