Skip to content

Engine

The execution engine applies intents to a broker, producing orders and fills. Brokers cover simulation and live trading; the order primitives describe what is sent and what comes back.

Engine

signalflow.Engine

Engine(capital: dict[str, float] | float, target: str = 'USDT', quote: str = 'USDT')

Folds fills into balances + positions and values the book in target.

Source code in src/signalflow/engine/engine.py
def __init__(self, capital: dict[str, float] | float, target: str = "USDT", quote: str = "USDT"):
    if isinstance(capital, (int, float)):
        capital = {quote: float(capital)}
    self.initial_capital: dict[str, float] = dict(capital)
    self.target = target
    self.quote = quote
    self.reset()

equity

equity(prices: dict[str, float]) -> float

Value the book in target, carrying forward the last-known price for any held asset missing from prices (gappy/staggered multi-asset data).

Source code in src/signalflow/engine/engine.py
def equity(self, prices: dict[str, float]) -> float:
    """Value the book in ``target``, carrying forward the last-known price for
    any held asset missing from ``prices`` (gappy/staggered multi-asset data)."""
    self.marks.update(prices)
    total = 0.0
    for asset, amount in self.balances.items():
        if abs(amount) < 1e-15:
            continue
        total += amount * self._rate(asset)
    return total

Brokers

signalflow.SimBroker dataclass

SimBroker(fee_rate: float = 0.001, slippage: float = 0.0005, quote: str = 'USDT')

Bases: Broker

Simulated fills with flat fee + slippage; next-available close pricing.

signalflow.ExchangeBroker dataclass

ExchangeBroker(quote: str = 'USDT')

Bases: Broker

Base for live venue brokers. Subclass and implement execute.

signalflow.BinanceBroker dataclass

BinanceBroker(quote: str = 'USDT', api_key: str = '', api_secret: str = '', base_url: str = 'https://testnet.binance.vision', recv_window: int = 5000, timeout: float = 20.0)

Bases: ExchangeBroker

Live Binance spot venue: signed REST market orders (testnet by default).

Set base_url to https://api.binance.com for production. Requires api_key/api_secret; only reachable through Flow.live(armed=True).

Order primitives

signalflow.Intent dataclass

Intent(pair: str, kind: IntentKind, side: Side, qty: float | None = None, notional: float | None = None, limit_price: float | None = None, reason: str = '')

A strategy proposal for a pair (not yet an order).

signalflow.Order dataclass

Order(pair: str, side: Side, qty: float, type: OrderType = OrderType.MARKET, limit_price: float | None = None, ts: object = None, reason: str = '')

A concrete order handed to a broker.

signalflow.Fill dataclass

Fill(pair: str, ts: object, side: Side, qty: float, price: float, fee: float = 0.0, fee_asset: str = 'USDT')

An executed order - the single source of truth the Engine folds.