Skip to main content

Market types

Symbol

Represents a financial symbol with exchange information.
pub struct Symbol {
    pub symbol: String,
    pub exchange: String,
    pub asset_class: AssetClass,
}
symbol
String
Ticker symbol (e.g., “AAPL”, “BTC-USD”)
exchange
String
Exchange identifier (e.g., “NASDAQ”, “BINANCE”)
asset_class
AssetClass
Type of financial instrument
Methods:
impl Symbol {
    pub fn new(symbol: &str, exchange: &str, asset_class: AssetClass) -> Self
    pub fn equity(symbol: &str) -> Self
    pub fn crypto(symbol: &str) -> Self
}
Example:
let aapl = Symbol::equity("AAPL");
let btc = Symbol::crypto("BTC-USD");
let custom = Symbol::new("EURUSD", "FOREX", AssetClass::Forex);

AssetClass

Asset classes supported by the platform.
pub enum AssetClass {
    Equity,
    Crypto,
    Forex,
    Commodity,
    Bond,
}
Methods:
impl AssetClass {
    pub fn is_24_7(&self) -> bool
    pub fn supports_fractional_quantities(&self) -> bool
    pub fn default_exchange(&self) -> &'static str
}
Example:
assert!(AssetClass::Crypto.is_24_7());
assert!(AssetClass::Crypto.supports_fractional_quantities());
assert_eq!(AssetClass::Crypto.default_exchange(), "BINANCE");

Bar

OHLCV bar data with volume and timestamp.
pub struct Bar {
    pub symbol: Symbol,
    pub timestamp: DateTime<Utc>,
    pub open: Decimal,
    pub high: Decimal,
    pub low: Decimal,
    pub close: Decimal,
    pub volume: Decimal,
    pub resolution: Resolution,
}
symbol
Symbol
Symbol for this bar
timestamp
DateTime<Utc>
Bar timestamp (UTC)
open
Decimal
Opening price
high
Decimal
Highest price during period
low
Decimal
Lowest price during period
close
Decimal
Closing price
volume
Decimal
Trading volume
resolution
Resolution
Time resolution (minute, hour, day, etc.)
Methods:
impl Bar {
    pub fn new(
        symbol: Symbol,
        timestamp: DateTime<Utc>,
        open: Decimal,
        high: Decimal,
        low: Decimal,
        close: Decimal,
        volume: Decimal,
        resolution: Resolution,
    ) -> Self
    
    pub fn typical_price(&self) -> Decimal
    pub fn true_range(&self, prev_close: Option<Decimal>) -> Decimal
}

Resolution

Time resolution for market data.
pub enum Resolution {
    Tick,
    Second,
    Minute,
    FiveMinute,
    FifteenMinute,
    Hour,
    FourHour,
    Day,
    Week,
    Month,
}
Methods:
impl Resolution {
    pub fn to_seconds(&self) -> Option<u64>
}

Order types

Order

Order request from strategy.
pub struct Order {
    pub id: OrderId,
    pub symbol: Symbol,
    pub side: Side,
    pub quantity: Decimal,
    pub order_type: OrderType,
    pub time_in_force: TimeInForce,
    pub submitted_at: DateTime<Utc>,
    pub status: OrderStatus,
    pub filled_quantity: Decimal,
    pub remaining_quantity: Decimal,
    pub average_fill_price: Option<Decimal>,
    pub strategy_id: String,
    pub metadata: serde_json::Value,
}
id
OrderId
Unique order identifier (UUID)
symbol
Symbol
Symbol to trade
side
Side
Buy or Sell
quantity
Decimal
Order quantity
order_type
OrderType
Market, Limit, Stop, or StopLimit
time_in_force
TimeInForce
Day, GTC, IOC, or FOK
status
OrderStatus
Current order status
Methods:
impl Order {
    pub fn new(
        symbol: Symbol,
        side: Side,
        quantity: Decimal,
        order_type: OrderType,
        strategy_id: String,
    ) -> Self
    
    pub fn market_order(symbol: Symbol, side: Side, quantity: Decimal, strategy_id: String) -> Self
    pub fn limit_order(symbol: Symbol, side: Side, quantity: Decimal, price: Decimal, strategy_id: String) -> Self
    pub fn stop_order(symbol: Symbol, side: Side, quantity: Decimal, stop_price: Decimal, strategy_id: String) -> Self
    
    pub fn is_buy(&self) -> bool
    pub fn is_sell(&self) -> bool
    pub fn is_filled(&self) -> bool
    pub fn is_active(&self) -> bool
    pub fn fill(&mut self, quantity: Decimal, price: Decimal)
    pub fn cancel(&mut self)
}
Example:
let order = Order::market_order(
    Symbol::equity("AAPL"),
    Side::Buy,
    Decimal::from(100),
    "my_strategy".to_string()
);

Side

Direction of an order.
pub enum Side {
    Buy,
    Sell,
}
Methods:
impl Side {
    pub fn opposite(&self) -> Side
    pub fn sign(&self) -> i32
}

OrderType

Order types supported by the engine.
pub enum OrderType {
    Market,
    Limit { price: Decimal },
    Stop { stop_price: Decimal },
    StopLimit { stop_price: Decimal, limit_price: Decimal },
}

Fill

Order execution record.
pub struct Fill {
    pub id: Uuid,
    pub order_id: OrderId,
    pub symbol: Symbol,
    pub side: Side,
    pub quantity: Decimal,
    pub price: Decimal,
    pub commission: Decimal,
    pub executed_at: DateTime<Utc>,
    pub strategy_id: String,
}
price
Decimal
Execution price
commission
Decimal
Commission charged for this fill
executed_at
DateTime<Utc>
Fill timestamp
Methods:
impl Fill {
    pub fn gross_amount(&self) -> Decimal
    pub fn net_amount(&self) -> Decimal
}

Portfolio types

Portfolio

Portfolio state and management.
pub struct Portfolio {
    pub account_id: String,
    pub initial_capital: Decimal,
    pub cash: Decimal,
    pub positions: HashMap<Symbol, Position>,
    pub total_equity: Decimal,
    pub total_pnl: Decimal,
    pub total_realized_pnl: Decimal,
    pub total_unrealized_pnl: Decimal,
    pub total_commissions: Decimal,
    pub last_updated: DateTime<Utc>,
    pub daily_returns: Vec<DailyReturn>,
}
account_id
String
Portfolio identifier
initial_capital
Decimal
Starting capital
cash
Decimal
Current cash balance
positions
HashMap<Symbol, Position>
Current positions by symbol
total_equity
Decimal
Total portfolio value (cash + positions)
total_pnl
Decimal
Total profit and loss (realized + unrealized)
Methods:
impl Portfolio {
    pub fn new(account_id: String, initial_capital: Decimal) -> Self
    pub fn apply_fill(&mut self, fill: &Fill)
    pub fn update_market_prices(&mut self, prices: &HashMap<Symbol, Decimal>)
    pub fn get_position(&self, symbol: &Symbol) -> Option<&Position>
    pub fn get_available_cash(&self) -> Decimal
    pub fn get_total_return(&self) -> Decimal
    pub fn get_sharpe_ratio(&self, risk_free_rate: Decimal) -> Option<Decimal>
    pub fn get_max_drawdown(&self) -> Decimal
    pub fn add_daily_return(&mut self, date: DateTime<Utc>, daily_return: Decimal)
}
Example:
let mut portfolio = Portfolio::new("my_account".to_string(), Decimal::from(100000));

// Apply a fill
let fill = Fill::new(
    order_id,
    Symbol::equity("AAPL"),
    Side::Buy,
    Decimal::from(10),
    Decimal::from(150),
    Decimal::from(1),
    "strategy_1".to_string()
);
portfolio.apply_fill(&fill);

// Check position
if let Some(position) = portfolio.get_position(&Symbol::equity("AAPL")) {
    println!("Position: {} shares at avg price {}", position.quantity, position.average_price);
}

Position

Portfolio position for a specific symbol.
pub struct Position {
    pub symbol: Symbol,
    pub quantity: Decimal,
    pub average_price: Decimal,
    pub market_value: Decimal,
    pub unrealized_pnl: Decimal,
    pub realized_pnl: Decimal,
    pub last_updated: DateTime<Utc>,
}
quantity
Decimal
Position size (positive for long, negative for short)
average_price
Decimal
Average entry price
market_value
Decimal
Current market value of position
unrealized_pnl
Decimal
Unrealized profit/loss
realized_pnl
Decimal
Realized profit/loss from closed portions
Methods:
impl Position {
    pub fn new(symbol: Symbol) -> Self
    pub fn is_long(&self) -> bool
    pub fn is_short(&self) -> bool
    pub fn is_flat(&self) -> bool
    pub fn apply_fill(&mut self, fill: &Fill)
    pub fn update_market_price(&mut self, market_price: Decimal)
    pub fn total_pnl(&self) -> Decimal
}

Build docs developers (and LLMs) love