Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Slippage Prediction Engine

Market-microstructure pipeline for estimating cryptocurrency trade execution cost across exchanges. It was developed as the prediction layer behind Nara Wallet's venue comparison flow.

The repository collects live order-book snapshots, derives liquidity and volatility features, simulates market-order execution, compares regression models, and exports inference artifacts to ONNX.

Note

This is a research and product prototype. Training targets come from a deterministic simulator operating on live market snapshots, not from exchange-verified post-trade fills. The output is useful for experimentation and venue comparison, but it is not financial advice or a production trading guarantee.

Pipeline

flowchart LR
    EX[Binance / Kraken / Coinbase / OKX] --> CCXT[CCXT market snapshots]
    CCXT --> FE[Microstructure features]
    FE --> SIM[Order-book execution simulator]
    SIM --> DATA[Training dataset]
    DATA --> MODELS[LightGBM / XGBoost / Random Forest]
    MODELS --> ONNX[ONNX model and scaler]
    ONNX --> API[Venue comparison API]
Loading

1. Market data and execution simulation

scripts/trade_cost_dataset.py collects order books and recent trades for several cryptocurrency pairs. It derives features including:

  • bid-ask spread and mid-price;
  • depth at fixed levels and price bands;
  • order-book imbalance and price-impact slope;
  • recent trade volatility, volume, and frequency;
  • order size relative to available depth.

The simulator walks the relevant side of an order book and records weighted fill price, fill percentage, base price impact, partial-fill penalties, and bounded volatility and venue adjustments.

2. Model training and evaluation

scripts/model_training.py adds interaction and log features, then evaluates LightGBM, XGBoost, and Random Forest regressors with a held-out test split. The pipeline records MAE, RMSE, R-squared, MAPE, feature importance, and model artifacts.

Model performance comparison

LightGBM feature importance

3. Portable inference

scripts/onnx_model_training.py exports the model, RobustScaler, feature order, metadata, and a validation case for ONNX Runtime. src/onnx_deployment_predictor.py uses those artifacts to compare execution venues through a small Flask API.

Run locally

Python 3.10 or newer is recommended.

git clone https://github.com/ArgaAAL/slippage-prediction-engine.git
cd slippage-prediction-engine

python -m venv .venv

Activate the environment, then install dependencies:

pip install -r requirements.txt

Generate a dataset from live public exchange data:

python scripts/trade_cost_dataset.py

Train the standard model artifacts:

python scripts/model_training.py

To train and export ONNX artifacts instead:

python scripts/onnx_model_training.py

After the ONNX model and scaler exist under models/, start the inference API:

python src/onnx_deployment_predictor.py

The service exposes health, model inspection, prediction, venue comparison, and model-switching endpoints on port 5000.

Repository map

assets/                         Evaluation and feature-importance plots
scripts/trade_cost_dataset.py   Snapshot collection and execution simulation
scripts/model_training.py       Scikit-learn model comparison and artifacts
scripts/onnx_model_training.py  ONNX export pipeline
src/deployment_predictor.py     Joblib-based predictor and Flask API
src/onnx_deployment_predictor.py
                                ONNX Runtime predictor and Flask API
tests/                          Exchange and API checks

Design boundary

The model estimates the output of the repository's execution simulator. A production validation program would additionally compare predictions against timestamped order submissions, partial fills, venue fees, latency, rejected orders, and realized post-trade execution. Keeping that boundary explicit is part of the project, not a disclaimer added after it.

About

Market-microstructure pipeline for predicting cryptocurrency trade execution cost from slippage, liquidity, volatility, spread, and order-book depth.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages