Cryptocurrency Order Book Analysis Tool
Reason this release was yanked:
markdown errors
Project description
crobat
Crypocurrency Order Book Analysis Tool
Explore the docs »
View Demo
·
Report Bug
·
Request Feature
Table of Contents
About The Project
This project is an extension of my thesis, A Study of CUSUM Statistics on Bitcoin Transactions , where I was tasked with implementing CUSUM statistic processes to identify price actions periods in bitcoin markets. After developing a tool for market orders, the natural extension was to find relationships from activities in the limit order book. I started developing this tool to record instances of the limit order book in order to record Limit Order insertions (LO), cancellations (CO), and Market Orders (MO).
As the project grew I wanted to make a tool that could be used by academics looking to apply and develop market microstructure models in live markets. As a result, the styles in which the limit orderbook and orderbook events are recorded are being developed in accordance to the conventions presented in recent market microstructure papers correspond to the following papers:
-
Cont R., Stoikov S. and Talreja R. - A stochastic model for order book dynamics
-
Cont R., Kukanov A. and Stoikov S. - The price impact of order book events
Getting Started
To get a local copy up and running follow these simple steps.
Prerequisites
You can use requirements.txt
to see what is necessary but they are also listed below:
from standard python library: asyncio, time, datetime, sys, bisect
requisite modules: copra, pandas, numpy
pip install crobat
Installation
- Clone the repo
git clone https://github.com/github_username/repo_name.git
- Install NPM packages
npm install
Usage
Since this is an orderbook recorder my use until now has been to record the orderbook. I should write acessors to get the latest event or orderbook snapshot in realtime.
-
For now we only have the full orderbook, with no regard for ticksize, and we call that
recorder_full.py
(I'm still working on fixed tick). -
We change the
settings
variable in theinput_args.py
file that has arguments for:| Parameter | Function Arg | Type | Description | |---------------------------|-------------------|------| -----| | Recording Duration | duration | int | recording time in seconds | | Position Range | position_range| int | ordinal distance from the best bid(ask) | | Currency Pair | currency_pair | str | List of currency pairs supported by Coinbase|
-
When you are ready, you can start the build. When it finishes you should get a message
Connection Closed
fromCoPrA
. And the files for the limit orderbook for each side should be created with a timestamp:|Filename|side|description| |----|----|----| |L2_orderbook_events_askYYYY-MM-DDTHH:MM:SS.ffffff| ask| Order book events on the ask side| |L2_orderbook_events_bidYYYY-MM-DDTHH:MM:SS.ffffff| bid| Order book events on the bid side | |L2_orderbook_askYYYY-MM-DDTHH:MM:SS.ffffff| ask |Images of orderbook on the ask side | |L2_orderbook_bidYYYY-MM-DDTHH:MM:SS.ffffff| bid |Images of orderbook on the bid side |
Understanding The Raw Order Book Data
The coinbase exchange operates using the double auction model, the Coinbase Pro API, and by extension the CoPrA API makes it realitively easy to get still images of an instance of the orderbook as snapshots
and it sends updates in real time of the volume at a particular price level as l2_update
messages. If you would like to know more, the cited papers do a great job introducing the double auction model for the purposes of defining the types of orders, and how they record events and make sense of them.
Orderbook Snapshots
Below there is a graph of the snapshot where bids (green) show open limit orders to buy the 1 unit of the cryptocurrency below $7085.930, and asks (red) show open limit orders to buy 1 unit above $7085.930. The x-axis shows the price points, and the y-axis is the aggregate size at the price level.
Early and current works relied on exchanges and private data providers (e.g., NASDAQ - BookViewer, LOBSTER) to provide reconstructions of orderbooks. Earlier works were limited to taking snapshots and inferring the possible sequence of orderbook events between states. Coinbase and by extension crobat update the levels on the instance of a update message from the exchange so there is no guess as to what happened between states of the order book. The current format of the orderbook snapshot is not aggregated. The format of the orderbook snapshot is shown below
Timestamp | 0 | 1 | 2 | ... | position range -1 |
---|---|---|---|---|---|
YYYY-MM-DDTHH:MM:SS.ffffff | total BTC at position 0 | total BTC at position 1 | total BTC at position 2 | ... | total BTC at position range -1 |
This has some limitations as you cannot get market depth in the quote currency. These snapshots in the future will include the price at each position for studies involving market depth. The Event Recorder does retain price point information.
Event Recordings
Event recording are a timeseries of MO, LO, CO's as afforded from the l2_update
messages which are used to update the price, volume pair size at each price level. The format of the Event recorder is as follows:
Timestamp | order type | price level | event size | position | mid price | bid-ask spread |
---|---|---|---|---|---|---|
YYYY-MM-DDTHH:MM:SS.ffffff | MO, LO, CO | price level in quote currency | event size in base currency | position | (best-ask + best-bid)/2 | best-ask - best-bid range |
Roadmap
####Features that need to be developed in order of priority:
- fixed tick orderbook snapshots and event recording
- market depth recording in both base and quote currencies.
- Acessor functions
- modernizing/optimizing iteration and classes
See the open issues for a list of proposed features (and known issues).
Contributing
Any contributions you make are greatly appreciated. I am not much of a computer scientist so suggestions and feedback will improve this project for everyone and make me a more capable developer for future projects.
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature
) - Commit your Changes (
git commit -m 'Add some AmazingFeature'
) - Push to the Branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
License
Distributed under the GNU GPLv3 License. See LICENSE
for more information.
Contact
Ivan E. Perez - @IvanEPerez - perez.ivan.e@gmail.com
Project Link: https://github.com/orderbooktools/crobat
Acknowledgements
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.