Skip to content

FlikoB/order-book-api

Repository files navigation

Order Book API

This project includes an Artisan command that periodically retrieves orders from a selected exchange (Binance) and stores the best bid/ask prices into the database.

The goal is to visualize the spread and monitor market movement in near real-time.

Requirements

  • PHP >= 8.2
  • MySQL
  • Composer
  • npm

Installation

1. Clone the repository

git clone git@github.com:FlikoB/order-book-api.git

2. Install composer dependencies

cd order-book-api
composer install

3. Set up .env file

cp .env.example .env
php artisan key:generate

Open the .env file and fill in the variables:

  • URL of the APP
  • database connection

4. Create a database structure

php artisan migrate

5. Install npm dependencies and build front-end assets

npm install
npm run build

Usage

Run the command

php artisan app:fetch-order-book

Arguments and options:

  • symbol – currency pair (default BTCUSDT)
  • --interval – interval between requests in seconds (default 10)
  • --minimum – minimum volume in USD required for an offer to be considered valid (default 500)

Example:

Run for BTC/USDT every 10 seconds with a minimum of 500 USD:

php artisan app:fetch-order-book BTCUSDT --interval=10 --minimum=500

Data storage

Each valid entry is stored in the order_entries table with the following columns:

  • base_currency – e.g. BTC
  • quote_currency – e.g. USDT
  • type – buy or sell
  • price – order price
  • volume – order quantity
  • total – price × quantity
  • created_at - timestamp of the entry

Throttling and retry

  • The command respects API limits.
  • If the API returns 429 Too Many Requests, it waits and retries.
  • The request interval is configurable via --interval.

Visualization

The project also includes a simple frontend:

  • / – visualization using Chart.js
  • /api/latest-entry – current bid/ask/spread

About

Order Book API

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages