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.
- PHP >= 8.2
- MySQL
- Composer
- npm
git clone git@github.com:FlikoB/order-book-api.git
cd order-book-api
composer install
cp .env.example .env
php artisan key:generate
Open the .env file and fill in the variables:
- URL of the APP
- database connection
php artisan migrate
npm install
npm run build
php artisan app:fetch-order-book
symbol– currency pair (defaultBTCUSDT)--interval– interval between requests in seconds (default10)--minimum– minimum volume in USD required for an offer to be considered valid (default500)
Run for BTC/USDT every 10 seconds with a minimum of 500 USD:
php artisan app:fetch-order-book BTCUSDT --interval=10 --minimum=500
Each valid entry is stored in the order_entries table with the following columns:
base_currency– e.g. BTCquote_currency– e.g. USDTtype– buy or sellprice– order pricevolume– order quantitytotal– price × quantitycreated_at- timestamp of the entry
- The command respects API limits.
- If the API returns 429 Too Many Requests, it waits and retries.
- The request interval is configurable via
--interval.
The project also includes a simple frontend:
- / – visualization using Chart.js
- /api/latest-entry – current bid/ask/spread