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.
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]
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.
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.
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.
Python 3.10 or newer is recommended.
git clone https://github.com/ArgaAAL/slippage-prediction-engine.git
cd slippage-prediction-engine
python -m venv .venvActivate the environment, then install dependencies:
pip install -r requirements.txtGenerate a dataset from live public exchange data:
python scripts/trade_cost_dataset.pyTrain the standard model artifacts:
python scripts/model_training.pyTo train and export ONNX artifacts instead:
python scripts/onnx_model_training.pyAfter the ONNX model and scaler exist under models/, start the inference API:
python src/onnx_deployment_predictor.pyThe service exposes health, model inspection, prediction, venue comparison,
and model-switching endpoints on port 5000.
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
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.

