Skip to content

Brokers & Datafeeds

AQE currently exposes these concrete runtime integrations:

  • execution brokers: PaperBroker, Mt5Broker
  • datafeeds: YahooFinanceDataFeed, Mt5DataFeed

They are composed through UnifiedBroker, which gives the strategy runtime one consistent broker-facing surface.

aq-engine/src/core/broker/mod.rs
pub trait Broker {
async fn connect(&self) -> Result<bool, BrokerError>;
async fn disconnect(&self) -> Result<bool, BrokerError>;
fn is_connected(&self) -> bool;
fn get_name(&self) -> String;
fn get_account_type(&self) -> Result<AccountType, BrokerError>;
}
pub trait OrderManagementProvider: Broker {
async fn submit_order(&self, insight: Insight) -> Result<Order, BrokerError>;
async fn cancel_order(&self, order_id: &str) -> Result<bool, BrokerError>;
async fn close_position(&self, order_id: &str, qty: f64, price: Option<f64>) -> Result<bool, BrokerError>;
async fn get_account(&self) -> Result<Account, BrokerError>;
fn drain_trade_events(&self) -> Vec<(Order, TradeUpdateEvent)>;
}
aq-engine/src/core/broker/mod.rs
pub trait DataFeed {
async fn connect(&self) -> Result<bool, BrokerError>;
async fn disconnect(&self) -> Result<bool, BrokerError>;
fn is_connected(&self) -> bool;
}
pub trait DataProvider: DataFeed {
async fn get_ticker_info(&self, symbol: &str) -> Result<Asset, BrokerError>;
async fn get_history(
&self,
symbol: &str,
start: DateTime<Utc>,
end: DateTime<Utc>,
time_frame: TimeFrame,
) -> Result<DataFrame, BrokerError>;
async fn get_latest_quote(&self, symbol: &str) -> Result<Quote, BrokerError>;
async fn get_latest_bar(&self, symbol: &str) -> Result<Bar, BrokerError>;
}

PaperBroker is AQE’s execution simulator for:

  • backtesting
  • paper trading
  • validating insight lifecycle behaviour

It handles:

  • order submission
  • fills
  • cancels
  • close requests
  • bracket legs
  • trailing stop execution
  • trade event emission
  • account and equity state

It is also responsible for preventing invalid paper account states, such as orders that would exceed available buying power.

YahooFinanceDataFeed provides:

  • ticker metadata
  • historical bars
  • latest quotes
  • latest bars
  • live bar stream subscription

That is the default market-data path used for historical research and paper-oriented runtime workflows.

Mt5Broker and Mt5DataFeed are live-only integrations that connect AQE to a running MetaTrader 5 terminal through the local AQE MT5 bridge.

They are designed for:

  • live account snapshots
  • latest quote and bar updates
  • order submission and cancellation
  • position close requests
  • trade event delivery back into AQE

The MT5 bridge requires the AQE bridge service to run locally and the MT5 Expert Advisor to be attached to a terminal chart with matching session and token settings.

The MT5 integration has two sides:

  • AQE side: Mt5Broker and Mt5DataFeed talk to the local MT5 bridge using the configured bridge token and bind address.
  • MT5 terminal side: the AQE Expert Advisor runs inside MetaTrader 5 and polls the local AQE bridge for market-data and broker RPC requests.

Use this setup flow:

  1. Install or update the AQE MT5 Expert Advisor from the AQE repository.
  2. Start MetaTrader 5 and sign in to the account you want AQE to use.
  3. Attach the AQE Expert Advisor to a chart for a symbol your broker exposes.
  4. Set the same AQE_MT5_BRIDGE_TOKEN in the AQE runtime environment and in the Expert Advisor.
  5. Keep the bridge bind address aligned between AQE and the Expert Advisor. The default local address is 127.0.0.1:18080.
  6. Start the AQE runtime and confirm the Expert Advisor is polling the bridge.

For the Expert Advisor files, installation notes, and bridge README, see the AQE MT5 integration directory on GitHub: algoquantstudio/aq-engine integrations/mt5.

When using MT5 for live execution, verify fills, stops, account state, and open positions in the MT5 terminal. AQE receives broker updates from the bridge, but the MT5 account remains the source of truth for live execution.

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

For live operation, the same pattern applies, but the runtime uses the live path instead of new_backtest(...).

When live sync is enabled, AQE publishes broker/runtime state into session-scoped tables used by AQS:

  • insights
  • strategy_accounts
  • strategy_equity_points
  • strategy_live_metrics
  • strategy_events

That means broker/datafeed behaviour directly shapes what the operator sees in the desktop UI.

  • aq-engine/src/core/broker/mod.rs
  • aq-engine/src/core/broker/paper_broker.rs
  • aq-engine/src/core/broker/data_feeds/yahoo.rs