Rust tests (98 tests) cover the core engine, risk pipeline, order management, position tracking, exchange backends, feed system, persistence layer, contingent orders, and order amendment. Tests are located in #[cfg(test)] mod tests blocks within each source file.
Python Tests
Python tests (395 tests) cover the full SDK: engine creation, pipeline composition, exchange configuration, feed management, multi-exchange routing, risk behavior, backtesting, execution algorithms, advanced orders, and Prometheus metrics.
Writing Strategy Tests
Use the Engine directly for unit testing your strategy logic:
from horizon import Engine, RiskConfig, OrderRequest, Side, OrderSide, Quote, Filldef test_my_strategy_logic(): config = RiskConfig(max_position_per_market=1000) engine = Engine(risk_config=config) # Submit an order order_id = engine.submit_order(OrderRequest( market_id="test", side=Side.Yes, order_side=OrderSide.Buy, size=10.0, price=0.55, )) # Tick to fill fills = engine.tick("test", 0.55) assert fills == 1 # Check position positions = engine.positions() assert len(positions) == 1 assert positions[0].size == 10.0
Testing with fills
Since Position has no Python constructor, build positions by processing fills:
def test_position_limit(): config = RiskConfig(max_position_per_market=10.0) engine = Engine(risk_config=config) # Fill up to the limit engine.process_fill(Fill( fill_id="f1", order_id="o1", market_id="test", side=Side.Yes, order_side=OrderSide.Buy, price=0.50, size=10.0, )) # This should be rejected by the position limit import pytest with pytest.raises(Exception): engine.submit_order(OrderRequest( market_id="test", side=Side.Yes, order_side=OrderSide.Buy, size=5.0, price=0.55, ))
Testing pipeline functions
Test pipeline functions in isolation with a mock context: