Skip to main content

Crate quantforge

Crate quantforge 

Source
Expand description

§QuantForge

QuantForge is a CLI-first trading systems framework in Rust for deterministic research, SQLite-backed market data, and controlled strategy execution.

Version 0.2.0 keeps the repository as a single Cargo package, following the 0.1.0 contributor experience, while adding the first live-trading and monitoring path for Binance Spot.

There is no UI. The CLI is the product.

§What changed in 0.2.0

  • single-crate repository layout with internal Rust modules
  • data command group for historical and incremental candle ingestion into SQLite
  • trade run command for a polling strategy bot that reads closed bars from SQLite, evaluates a strategy, and can place or close spot market orders
  • trade close command for operator-driven position exits
  • monitor command group for balances, open orders, recent trades, manual cancel, and manual close
  • bot run state and order or trade journal persisted in SQLite

QuantForge is engineering software. It is not investment advice, does not recommend trades, and does not promise profitability.

§Why keep a single crate?

This repository stays as a single Cargo package in 0.2.0 so versioning, publishing, installation, and contributor onboarding remain simple.

Internal boundaries still exist as Rust modules:

  • model - normalized market types and validation
  • ports - exchange and storage traits plus request types
  • exchange - Binance Spot REST client
  • storage - SQLite candle store and bot journal
  • sdk - strategy trait, indicators, built-in strategies
  • backtest - deterministic bar-by-bar engine
  • data_sync - historical and incremental ingestion loop
  • live - polling live-trade engine

§Scope and guardrails

  • exchange in 0.2.0: Binance Spot
  • storage in 0.2.0: SQLite
  • strategy execution model: closed-bar, event-driven
  • built-in strategy in 0.2.0: SMA crossover example
  • default execution mode: dry-run
  • live order placement requires explicit --mode live and Binance credentials from environment variables

§Credentials

QuantForge keeps secrets out of the repository. For live and monitor commands, use:

export QF_BINANCE_API_KEY="..."
export QF_BINANCE_API_SECRET="..."
export QF_BINANCE_BASE_URL="https://testnet.binance.vision/"

Use Binance Spot testnet first.

§Quickstart

Sync candles into SQLite:

cargo run -- \
  --db data/market.sqlite \
  data sync \
  --symbol BTCUSDT \
  --interval 1m

Validate the stored series:

cargo run -- \
  --db data/market.sqlite \
  data validate \
  --symbol BTCUSDT \
  --interval 1m

Backtest the SMA crossover example:

cargo run -- \
  --db data/market.sqlite \
  backtest \
  --symbol BTCUSDT \
  --interval 1m \
  --fast 20 \
  --slow 50 \
  --cash 10000 \
  --fee-bps 10

Run the strategy against live-updating database candles without sending real orders:

cargo run -- \
  --db data/market.sqlite \
  trade run \
  --symbol BTCUSDT \
  --interval 1m \
  --fast 20 \
  --slow 50 \
  --quote-order-qty 100 \
  --mode dry-run \
  --poll-secs 5

Run against Binance Spot testnet with live order placement:

export QF_BINANCE_BASE_URL="https://testnet.binance.vision/"

cargo run -- \
  --db data/market.sqlite \
  trade run \
  --symbol BTCUSDT \
  --interval 1m \
  --fast 20 \
  --slow 50 \
  --quote-order-qty 100 \
  --mode live \
  --bootstrap-enter \
  --poll-secs 5

Inspect balances, open orders, and recent trades:

cargo run -- \
  --db data/market.sqlite \
  monitor status \
  --symbol BTCUSDT

Cancel an order manually:

cargo run -- \
  --db data/market.sqlite \
  monitor cancel-order \
  --symbol BTCUSDT \
  --order-id 123456789 \
  --yes

Close the bot-managed position manually:

cargo run -- \
  --db data/market.sqlite \
  trade close \
  --symbol BTCUSDT \
  --yes

§Determinism contract

  • timestamps are stored as UTC epoch milliseconds
  • prices and volumes use decimal arithmetic, not floating-point math
  • strategies evaluate only closed bars
  • backtests execute intent on the next bar open
  • live trading polls closed bars and records run state into SQLite

§Local development

Run the full quality gate before opening a PR:

cargo generate-lockfile
cargo fmt --all -- --check
cargo clippy --all-targets --all-features -- -D warnings
cargo test --all-features
./scripts/release-check.sh

§Roadmap

  • additional exchanges such as Bybit
  • restart reconciliation between local bot state and exchange state
  • richer indicators and more built-in strategies
  • alternative storage backends such as Postgres
  • research-oriented parameter sweeps and snapshot reports

§License

Licensed under MIT.

Re-exports§

pub use backtest::BacktestConfig;
pub use backtest::BacktestEngine;
pub use backtest::BacktestResult;
pub use data_sync::DataSyncConfig;
pub use data_sync::DataSyncEngine;
pub use data_sync::DataSyncSummary;
pub use engine::EngineError;
pub use exchange::BinanceCredentials;
pub use exchange::BinanceSpotClient;
pub use live::LiveTradeConfig;
pub use live::LiveTradeEngine;
pub use live::LiveTradeSummary;
pub use model::AccountTrade;
pub use model::AssetBalance;
pub use model::BotRunState;
pub use model::Candle;
pub use model::ClosedTrade;
pub use model::ExchangeId;
pub use model::ExchangeOrder;
pub use model::ExecutionMode;
pub use model::Fill;
pub use model::Interval;
pub use model::MarketId;
pub use model::ModelError;
pub use model::OrderStatus;
pub use model::PositionState;
pub use model::RunStatus;
pub use model::Side;
pub use model::Symbol;
pub use model::SymbolRules;
pub use model::TargetPosition;
pub use model::TimestampMs;
pub use model::ValidationIssue;
pub use model::ValidationReport;
pub use model::ms_to_rfc3339;
pub use model::now_utc_ms;
pub use model::parse_rfc3339_to_ms;
pub use model::round_down_to_step;
pub use model::validate_candles;
pub use ports::CancelOrderRequest;
pub use ports::CandleQuery;
pub use ports::CandleStore;
pub use ports::ExchangeError;
pub use ports::KlineRequest;
pub use ports::MarketDataSource;
pub use ports::MarketOrderRequest;
pub use ports::OrderQueryRequest;
pub use ports::RunJournalStore;
pub use ports::StorageError;
pub use ports::TradingVenue;
pub use sdk::BuiltInStrategyConfig;
pub use sdk::Indicator;
pub use sdk::Sma;
pub use sdk::Strategy;
pub use sdk::StrategyContext;
pub use sdk::StrategyError;
pub use sdk::strategies::SmaCrossStrategy;
pub use storage::SqliteStore;

Modules§

backtest
data_sync
engine
exchange
live
model
ports
sdk
storage