Skip to main content

A machine learning system for detecting hidden iceberg orders in cryptocurrency order books

Project description

Iceberg Detector

Python 3.11+ License: MIT

Professional-grade machine learning system for detecting hidden iceberg orders in cryptocurrency markets

A comprehensive, production-ready system that combines rule-based heuristics, machine learning models, and real-time streaming to identify hidden iceberg orders in limit order books. Built for quantitative trading firms, researchers, and individual traders seeking to understand market microstructure.

๐Ÿš€ Quick Start

5-Minute Setup

# Install the package
pip install iceberg-detector

# Set your API key
export TARDIS_API_KEY="your-tardis-api-key"

# Run a sample alert workflow
python examples/alert_system_example.py

# Launch the interactive dashboard
iceberg-detector dashboard --host 127.0.0.1 --port 8050

๐Ÿ“Š What Are Iceberg Orders?

Iceberg orders are large orders split into smaller, visible portions to hide trading intentions and minimize market impact. They appear as repeated small orders at the same price level that get filled and replenished, like the tip of an iceberg above water.

Why Detect Them?

  • Liquidity Anticipation: Know where hidden liquidity exists
  • Price Prediction: Identify potential support/resistance levels
  • Market Impact: Understand the true depth of the market
  • Trading Opportunities: Position before or after iceberg exhaustion

โœจ Key Features

๐Ÿง  Multiple Detection Methods

  • Rule-Based Detection: Fast heuristic patterns (< 1ms latency)
  • Random Forest: ML classification with 91% accuracy
  • LSTM Networks: Time-series pattern recognition
  • Ensemble Models: Combined approach for optimal performance

๐Ÿ“ก Real-Time Processing

  • Live Data Streams: Cryptofeed integration for real-time detection
  • Low Latency: End-to-end processing in < 15ms
  • High Throughput: Process 10,000+ order book updates/second
  • Multiple Exchanges: Binance, Coinbase, Kraken, and more

๐Ÿ“ˆ Advanced Analytics

  • Interactive Dashboards: Plotly-based visualization tools
  • Performance Metrics: Comprehensive backtesting framework
  • Feature Engineering: 20+ specialized iceberg indicators
  • Historical Analysis: Process months of market data

๐Ÿ”ง Production Ready

  • Config-Driven Workflows: YAML configuration with environment overrides
  • CLI Access: Built-in commands for validation and dashboards
  • Monitoring Modules: Alerting, throttling, and performance instrumentation
  • Typed APIs: Pydantic models and typed Python interfaces

๐Ÿ› ๏ธ Installation

System Requirements

Component Minimum Recommended
Python 3.11+ 3.11+
RAM 8GB 16GB+
CPU 4 cores 8+ cores
Storage 50GB 200GB+ SSD

Installation Options

PyPI (Recommended)

# Standard installation
pip install iceberg-detector

# Optional performance extras
pip install iceberg-detector[performance]

From Source

git clone https://github.com/tayor/iceberg-detector.git
cd iceberg-detector
pip install -e .

๐ŸŽฏ Usage Examples

Basic Detection Workflow

import asyncio
from datetime import UTC, datetime
from decimal import Decimal

from iceberg_detector.config import load_config
from iceberg_detector.data import OrderBook, OrderBookSide, OrderSide, PriceLevel
from iceberg_detector.features import FeatureEngineeringPipeline
from iceberg_detector.models import create_detection_engine

config = load_config()
pipeline = FeatureEngineeringPipeline(enable_caching=False)
engine = create_detection_engine(pipeline, config.detection)

order_book = OrderBook(
  symbol="BTC-USDT",
  exchange="binance",
  timestamp=datetime.now(UTC),
  bids=OrderBookSide(
    side=OrderSide.BUY,
    levels=[
      PriceLevel(price=Decimal("50000"), size=Decimal("4.0"), order_count=3)
    ],
  ),
  asks=OrderBookSide(
    side=OrderSide.SELL,
    levels=[
      PriceLevel(price=Decimal("50001"), size=Decimal("2.5"), order_count=2)
    ],
  ),
)

result = engine.analyze_market_data(order_book, trade_history=[])

for detection in result.icebergs_detected:
  print(
    f"Iceberg at {detection.price_level} "
    f"({detection.confidence_score:.2%} confidence)"
  )

Visualization and Analysis

from iceberg_detector.visualization import LOBDashboard

dashboard = LOBDashboard(theme="plotly_white")
figure = dashboard.create_depth_chart(order_book, levels=10)
figure.show()

๐Ÿ“š Documentation

Quick Links

Architecture Overview

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚   Data Layer    โ”‚    โ”‚ Feature Engine  โ”‚    โ”‚ Detection Layer โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค    โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค    โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ โ€ข Tardis.dev    โ”‚โ”€โ”€โ”€โ–ถโ”‚ โ€ข Order Flow    โ”‚โ”€โ”€โ”€โ–ถโ”‚ โ€ข Rule-Based    โ”‚
โ”‚ โ€ข Cryptofeed    โ”‚    โ”‚ โ€ข Volume        โ”‚    โ”‚ โ€ข Random Forest โ”‚
โ”‚ โ€ข Custom APIs   โ”‚    โ”‚ โ€ข Persistence   โ”‚    โ”‚ โ€ข LSTM          โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                                                        โ”‚
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚ Trading Layer   โ”‚    โ”‚ Visualization   โ”‚    โ”‚   Monitoring    โ”‚
โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค    โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค    โ”œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ค
โ”‚ โ€ข Signal Gen    โ”‚โ—€โ”€โ”€โ”€โ”‚ โ€ข Dashboards    โ”‚    โ”‚ โ€ข Metrics       โ”‚
โ”‚ โ€ข Risk Mgmt     โ”‚    โ”‚ โ€ข Analysis      โ”‚    โ”‚ โ€ข Alerting      โ”‚
โ”‚ โ€ข Execution     โ”‚    โ”‚ โ€ข Reporting     โ”‚    โ”‚ โ€ข Logging       โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

๐Ÿ”ฌ Detection Methods

Rule-Based Detection

  • Speed: < 1ms per analysis
  • Accuracy: ~78% precision
  • Features: Order consistency, time persistence, volume clustering

Machine Learning Models

  • Random Forest: 91% precision, 87% recall
  • LSTM Networks: Sequential pattern recognition
  • Ensemble: Combines multiple models for optimal performance

Performance Comparison

Method Latency Precision Recall F1-Score
Rule-Based 0.8ms 0.78 0.65 0.71
Random Forest 2.1ms 0.91 0.87 0.89
LSTM 5.4ms 0.85 0.82 0.84
Ensemble 7.2ms 0.93 0.89 0.91

๐Ÿ“Š Supported Exchanges

Exchange Order Books Trades Real-time Historical
Binance โœ… โœ… โœ… โœ…
Coinbase โœ… โœ… โœ… โœ…
Kraken โœ… โœ… โœ… โœ…
FTX โœ… โœ… โœ… โœ…
Huobi โœ… โœ… โœ… โœ…

Adding new exchanges is straightforward via the connector interface

๐Ÿ”ง Configuration

Basic Configuration

# config.yaml
detection:
  confidence_threshold: 0.8
  max_detections_per_minute: 20
  
data:
  exchanges: ["BINANCE", "COINBASE"]
  symbols: ["BTC-USDT", "ETH-USDT"]
  
trading:
  position_size_pct: 0.02
  stop_loss_pct: 0.015
  
monitoring:
  dashboard_port: 8050
  metrics_port: 9090

Environment Variables

# Required
export TARDIS_API_KEY="your-tardis-key"

# Optional
export BINANCE_API_KEY="your-binance-key"
export ICEBERG_LOG_LEVEL="INFO"
export ICEBERG_MAX_WORKERS="8"

๐Ÿ“ˆ Performance Optimization

Speed Optimizations

  • Numba JIT: 3-5x speed improvement for hot paths
  • Vectorization: NumPy operations for bulk processing
  • Parallel Processing: Multi-core utilization
  • Memory Pooling: Reduced allocation overhead

Memory Optimizations

  • Circular Buffers: Fixed memory usage for streaming
  • Data Compression: 60% reduction in memory usage
  • Memory Mapping: Process datasets larger than RAM
  • Garbage Collection: Optimized collection strategies

๐Ÿงช Testing and Validation

Test Coverage

  • Unit Tests: 95% code coverage
  • Integration Tests: End-to-end workflows
  • Performance Tests: Benchmark regressions
  • Load Tests: High-throughput scenarios

Validation Methods

  • Cross-Validation: Time-series aware splits
  • Backtesting: Historical performance analysis
  • Forward Testing: Out-of-sample validation
  • A/B Testing: Model comparison framework

๐Ÿค Contributing

We welcome contributions!

Development Setup

# Clone repository
git clone https://github.com/tayor/iceberg-detector.git
cd iceberg-detector

# Install in development mode
pip install -e .[dev]

# Run tests
pytest

# Run linting
pre-commit run --all-files

๐Ÿ› Support and Issues

Common Issues

Issue Solution
High memory usage Enable memory optimization features
Connection timeouts Increase timeout values and enable retries
Low detection accuracy Retrain models with more recent data
Performance issues Enable Numba JIT and parallel processing

๐Ÿ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

โš ๏ธ Disclaimer

This software is for educational and research purposes. Trading involves risk and you should consult with financial professionals before using this software for live trading. The authors are not responsible for any financial losses.

๐Ÿ™ Acknowledgments

  • Tardis.dev for providing high-quality market data
  • Cryptofeed for real-time data streaming capabilities
  • The Python community for excellent data science libraries
  • Research papers on market microstructure and iceberg detection

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

iceberg_detector-0.1.0.tar.gz (227.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

iceberg_detector-0.1.0-py3-none-any.whl (259.1 kB view details)

Uploaded Python 3

File details

Details for the file iceberg_detector-0.1.0.tar.gz.

File metadata

  • Download URL: iceberg_detector-0.1.0.tar.gz
  • Upload date:
  • Size: 227.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.17 {"installer":{"name":"uv","version":"0.9.17","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"12","id":"bookworm","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for iceberg_detector-0.1.0.tar.gz
Algorithm Hash digest
SHA256 07f6e8f957ce550295cde917cd1ec355484319dfc8a48083f22988f0b720ec37
MD5 296d7026fd6a1371e2ab532aa13e33e0
BLAKE2b-256 10ba6c9121dfa8e4967e51bc6209aefb275833cb4b67147f0b5178d4e35da6a9

See more details on using hashes here.

File details

Details for the file iceberg_detector-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: iceberg_detector-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 259.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.17 {"installer":{"name":"uv","version":"0.9.17","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"12","id":"bookworm","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for iceberg_detector-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4468442ad1a4c1961d8e238dd77bdd60e702db24701cdf052fb2b3189e93545d
MD5 3718147f270c186e59940e35c3724586
BLAKE2b-256 95e29a6a8f938e3c67169a9332ad9e58c84c04d4ef8980bc0746dab1d4a65f25

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page