ML Model for Crypto Liquidity Forecasting

Imagine placing a large order on Binance through an algorithmic system when the spread suddenly widens tenfold—slippage eats 2% of the trade. The reason: the model didn't predict a liquidity drop during off-hours. In one of our projects, such a situation cost a trader tens of thousands of dollars in

Blockchain Development Services

Frequently Asked Questions

Latest works

  • image_web-applications_feedme_466_0.webp
    Development of a web application for FEEDME
    1310
  • image_ecommerce_furnoro_435_0.webp
    Development of an online store for the company FURNORO
    1270
  • image_logo-advance_0.webp
    B2B Advance company logo design
    719
  • image_crm_enviok_479_0.webp
    Development of a web application for Enviok
    1012
  • image_logo-aider_0.webp
    AIDER company logo development
    955
  • image_crm_chasseurs_493_0.webp
    CRM development for Chasseurs
    1062

Imagine placing a large order on Binance through an algorithmic system when the spread suddenly widens tenfold—slippage eats 2% of the trade. The reason: the model didn't predict a liquidity drop during off-hours. In one of our projects, such a situation cost a trader tens of thousands of dollars in a single month. We are a team of blockchain developers with 5+ years of experience, building predictive models that warn of these situations 4 hours in advance. Our certified engineers ensure solution quality. Our LightGBM-based models analyze liquidity time series, accounting for spread, market depth, and market microstructure. The forecast enables strategy adaptation: adjusting order sizes, widening spreads, delaying execution. Liquidity forecasting is especially critical for DeFi protocols, where low pool liquidity can cause sharp slippage and LP fund losses. Request a consultation—we will evaluate your data and propose a model architecture tailored to your stack.

Why is liquidity unpredictable?

Crypto market liquidity depends on many factors, many of which are nonlinear. The table below shows the key ones.

Factor Impact on liquidity Example
Time patterns Peak at 14:00–22:00 UTC, minimum on weekends (drop 20–30%) Sharp spread widening on Sunday evening
Market regime High volatility → market makers widen spreads or withdraw After a sharp BTC rise, liquidity drops
News events Macro releases, hacks, regulatory announcements Position liquidations of $300M in 10 minutes
Liquidations Cascade of liquidations reduces order book depth ETH falls 15% in an hour

What liquidity metrics are used?

Four main metrics are used for quantitative assessment. Compare them in the table.

More about liquidity metrics
Metric Formula/Interpretation When to use
Bid-Ask Spread (Ask - Bid) / Mid × 100%. Narrow spread → high liquidity Daily assessment
Market Depth Total volume in the book at N% from mid-price. Deep book can absorb a large order without slippage Capacity assessment
Amihud Illiquidity Ratio ` return
Kyle's Lambda Regression of price change on order flow. High λ means large price impact Execution models

Kyle (1985) showed that Kyle's Lambda is a coefficient measuring the impact of order flow on price. Its estimation requires cleaning microstructure noise.

How we build the model?

The process includes five stages:

  1. Analytics—collecting data for the last 12 months: order book snapshots, trade data, funding rates.
  2. Design—engineering 30+ features: time cyclic encodings, lags of spread and depth, moving averages, volatility, Amihud ratio.
  3. Implementation—training a LightGBM model with hyperparameter tuning via Optuna. The baseline predicts spread 4 hours ahead with 85% accuracy—30% better than ARIMA and 15% better than LSTM on the same horizon.
  4. Testing—walk-forward validation with a 6-month window.
  5. Deployment—integration with the trading engine via REST API or WebSocket.
import lightgbm as lgb import pandas as pd import numpy as np def create_liquidity_features(df, spread_col='spread', depth_col='depth_1pct'): features = pd.DataFrame(index=df.index) # Temporal features features['hour'] = df.index.hour features['day_of_week'] = df.index.dayofweek features['is_weekend'] = (features['day_of_week'] >= 5).astype(int) features['hour_sin'] = np.sin(2 * np.pi * features['hour'] / 24) features['hour_cos'] = np.cos(2 * np.pi * features['hour'] / 24) # Lagged liquidity for lag in [1, 4, 12, 24, 48]: features[f'spread_lag_{lag}'] = df[spread_col].shift(lag) if depth_col in df.columns: features[f'depth_lag_{lag}'] = df[depth_col].shift(lag) # Rolling statistics for window in [12, 24, 72]: features[f'spread_ma_{window}'] = df[spread_col].rolling(window).mean() features[f'spread_std_{window}'] = df[spread_col].rolling(window).std() # Volatility (proxy for liquidity) returns = df['close'].pct_change() if 'close' in df.columns else pd.Series(index=df.index) for window in [12, 24]: features[f'vol_{window}h'] = returns.rolling(window).std() # Volume if 'volume' in df.columns: features['vol_ratio'] = df['volume'] / df['volume'].rolling(24).mean() # Amihud ratio if 'close' in df.columns and 'volume' in df.columns: features['amihud'] = amihud_ratio(returns, df['volume']) return features.dropna() def train_liquidity_model(liquidity_df, target_col='spread', horizon=4): """ Predict spread/liquidity horizon periods ahead """ X = create_liquidity_features(liquidity_df) y = liquidity_df[target_col].shift(-horizon) # Walk-forward split split_idx = int(len(X) * 0.8) X_train, X_test = X.iloc[:split_idx], X.iloc[split_idx:] y_train, y_test = y.iloc[:split_idx], y.iloc[split_idx:] # Remove NaN from target valid_mask = y_train.notna() model = lgb.LGBMRegressor( n_estimators=500, learning_rate=0.05, num_leaves=31, early_stopping_rounds=50 ) model.fit( X_train[valid_mask], y_train[valid_mask], eval_set=[(X_test, y_test.fillna(method='ffill'))], callbacks=[lgb.early_stopping(50), lgb.log_evaluation(100)] ) return model 

Training runs on GPU (NVIDIA A100) and takes about 2 hours for 12 months of data. We also add features from related markets: funding rate and open interest—they correlate with liquidity outflows. The model is recalibrated weekly to account for regime changes.

How does liquidity forecasting help execution?

Before executing a large order, we estimate its market impact using the Almgren-Chriss model. If predicted market impact exceeds 10 bps, we recommend TWAP/VWAP. Example assessment code:

def estimate_market_impact(order_size_usd, current_depth, current_spread, lambda_estimate): """ Simplified Almgren-Chriss model for market impact """ temporary_impact = lambda_estimate * np.sqrt(order_size_usd) permanent_impact = 0.5 * temporary_impact spread_cost = current_spread / 2 * order_size_usd total_cost = (temporary_impact + permanent_impact + spread_cost) total_cost_bps = total_cost / order_size_usd * 10000 return { 'total_impact_usd': total_cost, 'total_impact_bps': total_cost_bps, 'temporary': temporary_impact, 'permanent': permanent_impact, 'spread_cost': spread_cost, 'optimal_execution': total_cost_bps > 10 } 

On average, using liquidity forecasting reduces slippage by 35% for orders larger than 10 BTC, saving up to 2% of trade volume in high-turnover projects. Our experience shows integration with a trading engine takes at most a week—we provide a ready REST API with /predict and /impact endpoints.

Scope of work

  • Development of data collection and processing pipeline (order book, trade data)
  • Building and training the prediction model (LightGBM with temporal features)
  • Validation on historical data (walk-forward)
  • Integration with trading engine via REST API or WebSocket
  • Documentation and team training
  • One month of post-launch support

Estimated timelines

Timelines depend on data complexity and integration: from 2 to 4 weeks. Pricing is determined individually after audit. Order development—start with a data audit.