AI Trading Model: Order Book Analysis with DeepLOB for Price Prediction

Real Task: Predicting Price Movement from the Order Book

AI Development Areas

Frequently Asked Questions

Latest works

  • image_web-applications_feedme_466_0.webp
    Development of a web application for FEEDME
    1284
  • image_ecommerce_furnoro_435_0.webp
    Development of an online store for the company FURNORO
    1240
  • image_logo-advance_0.webp
    B2B Advance company logo design
    696
  • image_crm_enviok_479_0.webp
    Development of a web application for Enviok
    982
  • image_logo-aider_0.webp
    AIDER company logo development
    917
  • image_crm_chasseurs_493_0.webp
    CRM development for Chasseurs
    1031

Real Task: Predicting Price Movement from the Order Book

A trader looks at the Depth of Market (DOM) and sees an imbalance: 2000 lots at Best Bid, 1500 at Best Ask. The order book is the full snapshot of limit orders with prices and volumes. In real time, it provides a signal milliseconds before trade execution. Extracting a reliable trading signal from noise is key. We tackle the problem: a trader needs to predict short-term price movement based on L2 data. We demonstrate using a project for Binance: transforming the order flow into predictions with a 1-10 second horizon. We combine linear models and convolutional neural networks for maximum accuracy at minimal latency.

Why Order Book Analysis Works for Short-Term Forecasting

Market microstructure is encoded in the distribution of liquidity. The order book reflects participants' expectations – the imbalance between volumes at the best levels precedes price movement. Order Book Imbalance (OBI) is the simplest yet powerful predictor. For 1–10 second horizons, OBI achieves AUC 0.58 with 0.1 ms latency. That suffices for arbitrage strategies. For trend trading, a more complex model capturing book dynamics is needed.

Order Book Data Structure

L2 Order Book snapshot:

Price | Bid Volume | Ask Volume ---------|-----------|---------- 100.05 | 0 | 5000 100.04 | 0 | 3000 100.03 | 0 | 1500 ← Best Ask 100.02 | 2000 | 0 ← Best Bid 100.01 | 3500 | 0 100.00 | 8000 | 0 99.99 | 2500 | 0 

L3 order book contains individual orders with IDs – needed for microstructure analysis, available on some exchanges (Binance, CME via API).

Feature Engineering from Order Book

Basic metrics: bid-ask spread, mid price, imbalance, weighted mid price. Order Book Imbalance (OBI):

def order_book_imbalance(book, levels=5): bids = [vol for price, vol in book['bids'][:levels]] asks = [vol for price, vol in book['asks'][:levels]] return (sum(bids) - sum(asks)) / (sum(bids) + sum(asks)) 

OBI > 0 → buyer pressure → expected upward move. This is one of the strongest short-term predictors (1-10 second horizon).

Iceberg detection: hidden orders – series of small orders at the same price. Signs: quick replenishment of a level after execution, constant volume at a level.

Market depth curves:

def depth_imbalance_at_level(book, price_distance): bid_vol = sum([vol for p, vol in book['bids'] if (mid - p) <= price_distance]) ask_vol = sum([vol for p, vol in book['asks'] if (p - mid) <= price_distance]) return (bid_vol - ask_vol) / (bid_vol + ask_vol) 

Features: imbalance at 0.1%, 0.3%, 0.5%, 1.0% from mid. We also add the rate of change of imbalance and the slope of the depth curve.

Choosing Between OBI and DeepLOB

Model comparison:

Model Latency (p99) AUC (0.1 sec horizon) Application
OBI 0.1 ms 0.58 High-frequency arbitrage
LightGBM 0.5 ms 0.64 Medium-frequency strategies
DeepLOB 2 ms 0.69 Trend trading

OBI is a linear predictor with 0.1 ms inference latency – critical for HFT. LightGBM requires 0.5 ms, DeepLOB 2 ms. But DeepLOB gives a 5% AUC boost over gradient boosting, justified for large capital strategies. We choose the approach per task: for arbitrage, OBI suffices; for trend trading, DeepLOB.

How DeepLOB Processes L2 Data

The convolutional neural network takes time slices of the order book as a 2D image (price × level × volume). It trains on millions of examples. In production we use ONNX Runtime for inference – p99 latency under 5 ms on a T4 GPU.

Iceberg Orders and Their Detection

Iceberg orders mask true volume. We use statistics of order reappearance at the same level: if the volume recovers more than 3 times in 1 second, it's likely an iceberg. This feature improves prediction accuracy by 2-3%.

How We Build a Production Solution

Our team has over 7 years in algorithmic trading. We use: PyTorch, ONNX Runtime for inference, Kafka for data streams.

Process

  1. Data collection: obtain historical L2 data via Binance WebSocket or CME FIX.
  2. Feature engineering: compute OBI, depth curves, imbalance at multiple horizons.
  3. Model design: try DeepLOB, LightGBM on handcrafted features, hybrid approaches.
  4. Training: on a GPU cluster with distributed training.
  5. Backtesting: on historical data accounting for fees and slippage.
  6. Deployment: containerization, ONNX Runtime on inference server, integration with OMS.

What’s Included

  • Model card with metrics and limitations.
  • API for signal retrieval (gRPC or REST).
  • Training of client team on interpreting outputs.
  • Support for 3 months post-deployment.
  • Source code and pipeline configuration.

We guarantee transparency – you get an interpretable pipeline, not a black box. All results are confirmed by backtests on a hold-out set. Cost savings from ready-made feature extractors and base models reach 30% of budget.

Common Mistakes in Building Order Book Models

  • Ignoring microstructure: using only mid price without depth.
  • Incorrect forecast horizon: for HFT milliseconds matter, for trends seconds.
  • Lack of iceberg detection: hidden orders skew imbalance.

Development Timelines

Stage Duration
Feature engineering + baseline 2-3 weeks
DeepLOB with real data 8-12 weeks
Production integration 4-6 weeks
Total 14-21 weeks

Pricing is individual – depends on data volume, model complexity, and infrastructure. Contact us for a preliminary assessment of your task – we will select the optimal architecture for your strategy. Get a consultation for your project right now.