local_order_book.py provides a demo application showing how to maintain a
local spot BTC_USDT order book using Gate.io WebSocket spot.order_book_update channel and HTTP
API.
To run this demo, you need to install the following packages manually:
pip install --user gate-ws sortedcontainers aiohttp asciimatics Then run it directly python local_order_book.py
Python3.6+ is required.
This application maintains the local order book through LocalOrderBook class which provides a
callback method ws_callback for WebSocket connection to call on order book update received. The
animation is shown through OrderBookFrame using asciimatics. You can use LocalOrderBook
instance in your own application, without OrderBookFrame, screen initialization
and play_order_book task.
Some notes:
- When the demo application starts, you might see the order book did not change for several seconds. It is a normal case, as the HTTP result is trying to keep up with WebSocket updates' pace.
- You can only run this application in a terminal. Order book maintained this way provides at most 100 levels. The application will detect the terminal height to display with proper levels. The longer your terminal, the higher levels will be shown.
- Resizing your terminal is not supported when running.
Here is a pre-recorded clip.