This project offers a solution for generating orderflow data from Binance and Bybit. Built with Node.js/TypeScript and leveraging the NestJS framework, it comprises three applications:
- Real-time data collection from Binance Perps.
- Real-time data collection from Bybit Perps.
- Historical data processing for Binance.
The system processes live trade data in real-time, aggregating it into 1-minute Footprint candles and then building higher timeframe Footprint candles. This data is crucial for revealing the underlying trade information associated with each candle.
-
Clone the repository:
git clone https://github.com/focus1691/orderflow cd orderflow
-
Install dependencies:
yarn install
-
Set up a PostgreSQL TimescaleDB instance (Required):
docker run -d --name timescaledb -p 5433:5432 -e POSTGRES_PASSWORD=password timescale/timescaledb-ha:pg14-latest
-
Configure environment variables:
DB_HOST
DB_PORT
DB_USERNAME
DB_PASSWORD
DB_NAME
SYMBOLS
(CSV. Defaults to all exchange symbols)
-
Build the Docker images:
docker-compose build binance docker-compose build bybit
-
Run the services:
docker-compose up -d binance docker-compose up -d bybit
Binance and Bybit services run continuously, aggregating live trade data to construct Footprint candles through the following steps:
- Connect to exchange WebSockets to receive live trade data.
- Aggregate raw trades into 1-minute candles.
- Construct higher timeframe candles from the 1-minute candles.
- Store the processed data in TimescaleDB.
For historical data processing:
-
Set the following environment variables:
SYMBOLS
: Specify the trading pair(s) for which you want to process historical data (comma-separated if multiple)BACKFILL_START_AT
: Start timestamp for backfill data processingBACKFILL_END_AT
: End timestamp for backfill data processing
-
Run the Binance Backfill service:
yarn start:binance-backfill
The service automatically downloads and processes the required CSV files from Binance Market Data for the specified symbols and date range, creating footprint candles from the historical data.
- NestJS
binance
andbybit-api
libraries by @tiagosiebler.- PostgreSQL with TimescaleDB extension.
- Ensure the TimescaleDB instance is running before starting the services.
- The Binance Backfill service is not designed for continuous operation and will terminate upon completion.
- For advanced analysis of the generated orderflow data, consider using the chart-patterns library, which provides indicators for:
- Stacked Imbalances: Identify stacks of buying/selling imbalances on the price level.
- High Volume Nodes: Pinpoint areas where significant trade volume occurred.