Skip to content

Brokers & Datafeeds

AQE separates market data from execution. A datafeed supplies history and prices; an execution broker manages orders and account state. UnifiedBroker combines them so the strategy can use the same structure for historical tests and live operation.

PurposeImplementations
Simulated executionPaperBroker
MetaTrader 5 executionMt5Broker
Market dataYahooFinanceDataFeed, Mt5DataFeed

Use PaperBroker for simulated execution and fee assumptions. Use the MT5 guide for the Expert Advisor and bridge configuration.

let execution = PaperBroker::new(AccountType::Paper, 100_000.0, 1);
let data = YahooFinanceDataFeed::new();
let broker = UnifiedBroker::new_backtest(execution, data);

The 0.2.0 API submits a BrokerOrderRequest, rather than passing the entire insight to the broker. It carries the entry, protection and identity data needed for execution.

let request = aq_engine::core::broker::BrokerOrderRequest::from(&insight);
let order = broker.submit_order(request).await?;

This excerpt assumes an existing broker, insight and OrderManagementProvider import. Strategy pipes should normally request mutations through the strategy context and preserve their pending results; see Insight Pipes.

Custom adapters must return Send futures for broker mutations. Pending-entry replacement uses replace_order; protective changes use update_take_profit or update_stop_loss. Do not reuse the removed, ambiguous update_order interface.

For a pending Executed insight with no fill, update_limit(ctx, price) amends its entry limit and update_stop_limit(ctx, price) amends its entry stop trigger. The latter is not a stop-loss update. The execution adapter handles these through amend_entry_prices(order_id, limit_price, stop_price) and advertises AmendLimitPrice or AmendStopPrice for supported operations. This price amendment keeps the order quantity; replace_order is a separate operation. See Insight Lifecycle for the state and acknowledgement rules.

Connect your own market-data service, exchange API or historical dataset by implementing DataFeed and DataProvider. These traits cover connection management, asset metadata, historical bars, current prices and subscriptions. You can pair the result with PaperBroker to test the data independently of live execution.

Follow Create a custom datafeed for required methods, bar and quote formats, capability flags and a validation checklist.

Connect an execution venue by implementing Broker and OrderManagementProvider. Your adapter translates AQE order requests into the venue’s API, returns account and position state, and reports order lifecycle events. UnifiedBroker can combine it with an existing datafeed or your own implementation.

Follow Create a custom broker for the execution contract, bounded event queues, protection management and recovery requirements.

These are Rust integrations compiled into your strategy. Implementing the traits does not automatically add a provider to the AQS connection picker.

SourceQuote behaviour
MT5 liveSampled native bid/ask, independent of candle timeframe
Yahoo live or paperPolled minute-candle close represented as a synthetic bid=ask quote
Backtest replaySynthetic quotes from already-consumed historical bars

Synthetic quotes do not provide a real spread or an executable price. Backtests do not fetch current market quotes. Quote subscriptions do not introduce a strategy on_quote callback or tick-driven backtests.

For a custom data consumer, check DataFeedFeature::QuoteStream and the native/synthetic capability flags. Use a unique subscription ID and release only your own subscription. Keep callbacks short and non-blocking.

The current engine distinguishes three limits:

FieldMeaning
Account.max_total_ordersMaximum pending-order count
Asset.max_order_sizeMaximum quantity for one entry order
Asset.max_total_sizeAggregate quantity limit for a symbol

Sizing considers active and reserved quantities before splitting an order. MT5 reports capacity through the updated Expert Advisor. Paper execution does not inherit every live account limit from its datafeed.

Reservations are strategy-local. Other strategies or manual orders can consume account capacity; a broker may still refuse an order after local validation. Inspect the refusal before retrying.

AQS displays delivered account observations, equity, events and insights. A command acknowledgement is not a fill, and an absent or stale observation is not proof of cancellation. Check the broker’s records and the insight history when an outcome is uncertain.

See Live Runtime for recovery and Datafeeds in AQS for desktop configuration.