Overview
Parsecular includes a strategy framework for building automated trading strategies. It provides aBaseStrategy class with common functionality like position tracking, order management, and event handling.
Core Components
Strategy Trait
Strategy States
Strategy Events
Configuration
StrategyConfig
MarketMakingConfig
For market-making strategies:BaseStrategy
TheBaseStrategy provides common trading functionality:
Key Methods
| Method | Description |
|---|---|
new() | Create a new strategy instance |
subscribe() | Subscribe to strategy events |
refresh_state() | Refresh positions and orders |
cancel_all_orders() | Cancel all open orders |
get_position() | Get position for an outcome |
get_net_position() | Get net exposure |
place_order() | Place a new order |
run_loop() | Run the main strategy loop |
pause() / resume() | Control strategy state |
get_account_state() | Get balance and positions |
Basic Example
Market Making Example
Event Subscription
Controlling Strategy
Account State
Utility Methods
Calculate Order Size
Calculate Spread Prices
Best Practices
Always refresh state
Always refresh state
The
run_loop automatically refreshes state each tick. If running custom logic, call refresh_state() periodically.Handle errors gracefully
Handle errors gracefully
Errors in the tick handler are logged and emitted as events but don’t stop the strategy.
Use position limits
Use position limits
Always check position limits before placing orders to avoid excessive exposure.
Cancel orders on stop
Cancel orders on stop
Consider canceling all orders when stopping the strategy to avoid orphaned orders.