Skip to content

CCXT framework for the limit orderbook. Calculates the rate of change, the spread & amount of pulled bids/asks

License

Notifications You must be signed in to change notification settings

0xd3lbow/Orderbook-Speed

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Simple Model for High Frequency Orderbook Data

This is a lightweight tool that measures the speed and velocity of the limit orderbook, by using a Websocket to fetch orderbook updates it can track the fluctuation of quotes and return the total changes per second.

  • Plot the rate of change for buy and sell orders.
  • Added outputs for the Bid-Ask Spread + pulled/removed bids and asks.
  • Can be applied to any exchange's websocket connection, simply adjust ws config for the given exchange.
orderbookspeed

Velocity in Relation to Orderbook Speed

Velocity is a metric for the rate of change in speed, in this script I use velocity to represent the change in speed per unit of time, in order to measure the acceleration and deceleration of aggregated quotes.

Terminal-Output

In the physical world, velocity is expressed in terms of distance traveled per unit of time and the unit of velocity is meters per second (m/s) .

  • However, when velocity is measured in terms of changes in speed per unit of time, it can be described as changes per second squared (c/s²) . (c/s²) means we're measuring the change in the number of quote updates per second, the rate is squared to indicate the acceleration or deceleration of those changes over time.

  • The squared unit (s²) indicates the rate of change is measured per unit of time squared.

Pulled Bids & Asks for Altcoin Orderbooks

  • To run this script on altcoins, you'll have to update the size property under the for-loop to calculate the pulled orders from the new ticker.
  • Note: If you refer to the Coinbase documentation on Websocket channels, a message containing a size property of "0" indicates a previously active order was removed from that price level.
Pulled-BidAsk

Size Property Variance

  • In the case of "BTC-USD" the size property for a pulled order is "0.00000000" .
# BTC-USD
if message['type'] == 'l2update':
            for change in message['changes']:
                side, price, size = change
                if side == 'buy' and size == '0.00000000':
                    pulledBids += 1
                elif side == 'sell' and size == '0.00000000':
                    pulledAsks += 1
  • For other tokens the l2update can return a different integer such as "0.00" . Here's "LDO-USD" for example.
# LDO-USD
if side == 'buy' and size == '0.00':
    pulledBids += 1
elif side == 'sell' and size == '0.00':
    pulledAsks += 1
  • To find the correct format from the websocket, use a print statement under the on_message function.
def on_message(ws, message):
    global changeCount, pulledBids, pulledAsks

    message = json.loads(message)
    print('WebSocket Message:', message)