How dykij/dmarket_bot works
Purpose and entry points
DMarket Quantitative Engine is an autonomous Python trading system for DMarket marketplace items. It scans order-book-derived demand signals, evaluates candidates, executes purchases/resales (or dry runs), and manages positions. Primary runtime entry point is src/__main__.py, which initializes and runs the application via src/core/application.py; operational startup is also supported by scripts/start.sh and Docker definitions.
Application lifecycle and orchestration
The core application owns configuration, startup/shutdown, recovery, signals, and notifications. It composes long-running scanner and trading services rather than exposing an HTTP application interface.
• src/core/application.py
• src/core/app_initialization.py
• src/core/app_lifecycle.py
Control flow is: load environment/configuration → initialize persistence, API, risk, telemetry, and notifications → run scheduled/autonomous scan cycles → recover or shut down safely on lifecycle events.
Market-access boundary
DMarket REST v2 interaction is isolated behind a signed client with account, market, offer, target, fee, retry/backoff, and rate-limit concerns. Rust/PyO3 provides Ed25519 signing support, creating a language boundary between Python orchestration and cryptographic performance code.
• src/api/dmarket_api_client/core.py
• src/api/dmarket_api_client/rate_limiter.py
• src/rust_core/src/lib.rs
External dependencies are DMarket API credentials/services and, optionally, Telegram. API responses become normalized market/candidate inputs for trading stages.
Target-sniping trading pipeline
target_sniping is the architecture’s execution-critical pipeline. Its cycle orchestrator schedules scanner output through filtering, microstructure analysis, demand/price ranking, validation, guarded execution, and resale management.
• src/core/target_sniping/cycle_orchestrator.py
• src/core/target_sniping/scanner.py
• src/core/target_sniping/execution.py
Primary data flow: listings and aggregated bid/ask data → candidate items → OBI/demand and price calculations → ranked, validated targets → purchase order or sandbox result → inventory position → resale/exit action.
Signal, valuation, and strategy layer
Microstructure modules calculate OBI-related signals and volatility; the algorithm pack supplies statistical models. The demand strategy applies adaptive thresholds, and pricing/fair-value logic establishes expected economics before a target is eligible.
• src/core/target_sniping/microstructure_pipeline.py
• src/core/target_sniping/demand_strategy.py
• src/core/target_sniping/pricing.py
This is intentionally separated from API transport and execution, allowing signal generation and strategy tuning without directly placing orders. Additional strategies exist under src/strategies/, but the target-sniping demand pipeline is the stated primary path.
Risk, positions, and persistence
Risk controls form a gate around both entry and holding: price validation, liquidity/pump checks, concentration/portfolio rules, dynamic controls, and circuit breaking. Position guards and resale modules determine stops, profit targets, holding limits, and exit execution. SQLite in WAL mode persists price history, inventory, targets, state, and analytics.
• src/risk/risk_manager.py
• src/core/target_sniping/position_guard.py
• src/db/price_history/core.py
The persistence boundary should preserve trade/position state across restarts; recovery logic is in the core lifecycle rather than the database package.
Operations, observability, and control
Telegram is the operator command and notification surface, while Prometheus metrics and health endpoints support machine monitoring. Docker Compose provides deployment composition; Python 3.13+ is the main runtime, with Rust built through Cargo/Maturin.
• src/telegram/control_bot/bot.py
• src/monitoring/prometheus_metrics.py
• src/utils/health_server.py
Dry-run and live-shadow components provide non-production execution boundaries before real DMarket order placement.
• src/core/live_shadow.py
• src/core/target_sniping/sandbox.py
Main entry points: execution.py Guarded execution · application.py Application · core.py DMarket client · app_initialization.py Initialization
Components 20
Runtime & Control
- Application · Owns startup, recovery, scheduling, and safe shutdown.
src/core/application.py - Initialization
src/core/app_initialization.py - Lifecycle & recovery
src/core/app_lifecycle.py - Sandbox
src/core/target_sniping/sandbox.py - Live shadow
src/core/live_shadow.py
Target-Sniping Pipeline
- Target cycle
src/core/target_sniping/cycle_orchestrator.py - Market scanner
src/core/target_sniping/scanner.py - Microstructure signals
src/core/target_sniping/microstructure_pipeline.py - Demand strategy
src/core/target_sniping/demand_strategy.py - Pricing & fair value
src/core/target_sniping/pricing.py - Guarded execution
src/core/target_sniping/execution.py
Market & Operations
- DMarket client · Handles market, offers, targets, fees, retries, and rate limits.
src/api/dmarket_api_client/core.py - Rate limiter
src/api/dmarket_api_client/rate_limiter.py - Rust signing core
src/rust_core/src/lib.rs - Telegram control
src/telegram/control_bot/bot.py - Prometheus metrics
src/monitoring/prometheus_metrics.py - Health server
src/utils/health_server.py
Risk & State
- Position guard
src/core/target_sniping/position_guard.py - Risk manager
src/risk/risk_manager.py - SQLite state · Persists prices, inventory, targets, and analytics across restarts.
src/db/price_history/core.py
Connections 24
- Application → Initialization: initializes
- Application → Lifecycle & recovery: manages
- Initialization → DMarket client: configures
- Initialization → Risk manager: configures
- Application → Target cycle: runs cycles
- Lifecycle & recovery → SQLite state: recovers state
- Target cycle → Market scanner: scans
- Market scanner → DMarket client: fetches listings and books
- Market scanner → Microstructure signals: candidate market data
- Microstructure signals → Demand strategy: demand signals
- Demand strategy → Pricing & fair value: eligible candidates
- Pricing & fair value → Risk manager: valued targets
- Risk manager → Guarded execution: approved targets
- Guarded execution → Sandbox: dry-run orders
- Guarded execution → Live shadow: shadow orders
- Guarded execution → DMarket client: live orders
- Guarded execution → Position guard: opens and manages positions
- Position guard → Guarded execution: exit actions
- Guarded execution → SQLite state: persists positions
- DMarket client → Rate limiter: throttles requests
- DMarket client → Rust signing core: signs requests
- Application → Telegram control: operator notifications
- Application → Prometheus metrics: emits metrics
- Application → Health server: serves health