Skip to main content

Broker

Trait Broker 

Source
pub trait Broker: Send + Sync {
Show 24 methods // Required methods fn name(&self) -> &'static str; fn connect<'async_trait>( params: BrokerParams, ) -> Pin<Box<dyn Future<Output = Result<Self, BrokerError>> + Send + 'async_trait>> where Self: Sized + 'async_trait; fn disconnect<'life0, 'async_trait>( &'life0 mut self, ) -> Pin<Box<dyn Future<Output = Result<(), BrokerError>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait; fn is_connected<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = bool> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait; fn session<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<Session, BrokerError>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait; fn get_balance<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<Balance, BrokerError>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait; fn get_account_type<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<AccountType, BrokerError>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait; fn switch_account<'life0, 'async_trait>( &'life0 mut self, kind: AccountType, ) -> Pin<Box<dyn Future<Output = Result<(), BrokerError>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait; fn list_assets<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<Vec<Asset>, BrokerError>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait; fn asset_status<'life0, 'life1, 'async_trait>( &'life0 self, symbol: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<MarketStatus, BrokerError>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait; fn get_candles<'life0, 'async_trait>( &'life0 self, req: CandleRequest, ) -> Pin<Box<dyn Future<Output = Result<Vec<Candle>, BrokerError>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait; fn subscribe_candles<'life0, 'async_trait>( &'life0 self, req: CandleSubscribe, ) -> Pin<Box<dyn Future<Output = Result<CandleStream, BrokerError>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait; fn get_position_history<'life0, 'life1, 'async_trait>( &'life0 self, symbol: Option<&'life1 str>, limit: usize, offset: usize, ) -> Pin<Box<dyn Future<Output = Result<PositionHistory, BrokerError>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait; fn get_payout<'life0, 'life1, 'async_trait>( &'life0 self, symbol: &'life1 str, expiration_seconds: u64, ) -> Pin<Box<dyn Future<Output = Result<Payout, BrokerError>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait; fn get_technical_indicators<'life0, 'life1, 'async_trait>( &'life0 self, symbol: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<TechnicalIndicators, BrokerError>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait; fn get_asset_profile<'life0, 'life1, 'async_trait>( &'life0 self, symbol: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<AssetProfile, BrokerError>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait; fn subscribe_live_deals<'life0, 'life1, 'async_trait>( &'life0 self, symbol: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<(), BrokerError>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait; fn subscribe_commission_changes<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<(), BrokerError>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait; fn buy_binary<'life0, 'async_trait>( &'life0 self, req: BuyBinaryRequest, ) -> Pin<Box<dyn Future<Output = Result<OrderId, BrokerError>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait; fn buy_blitz<'life0, 'async_trait>( &'life0 self, req: BuyBlitzRequest, ) -> Pin<Box<dyn Future<Output = Result<OrderId, BrokerError>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait; fn buy_digital_spot<'life0, 'async_trait>( &'life0 self, req: BuyDigitalRequest, ) -> Pin<Box<dyn Future<Output = Result<OrderId, BrokerError>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait; fn sell_option<'life0, 'life1, 'async_trait>( &'life0 self, order_id: &'life1 OrderId, ) -> Pin<Box<dyn Future<Output = Result<(), BrokerError>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait; fn get_operation_result<'life0, 'life1, 'async_trait>( &'life0 self, order_id: &'life1 OrderId, ) -> Pin<Box<dyn Future<Output = Result<OperationResult, BrokerError>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait; fn events<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<EventStream, BrokerError>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait;
}
Expand description

Contrato que todo adaptador de bróker cumple.

Diseño type-erased a propósito: sin associated types para que Box<dyn Broker> y MultiBroker compilen (ver docs/01_introduccion.es.md).

Required Methods§

Source

fn name(&self) -> &'static str

Nombre estable del adaptador, p. ej. iq_option.

Source

fn connect<'async_trait>( params: BrokerParams, ) -> Pin<Box<dyn Future<Output = Result<Self, BrokerError>> + Send + 'async_trait>>
where Self: Sized + 'async_trait,

Constructor de la sesión: autentica y deja el bróker operativo.

Source

fn disconnect<'life0, 'async_trait>( &'life0 mut self, ) -> Pin<Box<dyn Future<Output = Result<(), BrokerError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Source

fn is_connected<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = bool> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Source

fn session<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<Session, BrokerError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Metadatos de la sesión activa (copia: la sesión se actualiza en caliente).

Source

fn get_balance<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<Balance, BrokerError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Source

fn get_account_type<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<AccountType, BrokerError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Source

fn switch_account<'life0, 'async_trait>( &'life0 mut self, kind: AccountType, ) -> Pin<Box<dyn Future<Output = Result<(), BrokerError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Source

fn list_assets<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<Vec<Asset>, BrokerError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Source

fn asset_status<'life0, 'life1, 'async_trait>( &'life0 self, symbol: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<MarketStatus, BrokerError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Source

fn get_candles<'life0, 'async_trait>( &'life0 self, req: CandleRequest, ) -> Pin<Box<dyn Future<Output = Result<Vec<Candle>, BrokerError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Source

fn subscribe_candles<'life0, 'async_trait>( &'life0 self, req: CandleSubscribe, ) -> Pin<Box<dyn Future<Output = Result<CandleStream, BrokerError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Source

fn get_position_history<'life0, 'life1, 'async_trait>( &'life0 self, symbol: Option<&'life1 str>, limit: usize, offset: usize, ) -> Pin<Box<dyn Future<Output = Result<PositionHistory, BrokerError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Historial de posiciones cerradas (cartera): para analítica de cuenta. limit ≤ 100 por página, offset para paginar.

Source

fn get_payout<'life0, 'life1, 'async_trait>( &'life0 self, symbol: &'life1 str, expiration_seconds: u64, ) -> Pin<Box<dyn Future<Output = Result<Payout, BrokerError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Payout publicado en el catálogo para el activo.

expiration_seconds se devuelve en el resultado pero no altera la consulta: no se pide una cotización por expiración ni por strike. Los cambios en vivo llegan por Event::PayoutChanged.

Source

fn get_technical_indicators<'life0, 'life1, 'async_trait>( &'life0 self, symbol: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<TechnicalIndicators, BrokerError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Indicadores técnicos que el bróker envía para un activo (trading-signals). No calcula nada: transporta lo que el bróker entregue; si no soporta el activo devuelve BrokerError::Rejected con el mensaje del bróker.

Source

fn get_asset_profile<'life0, 'life1, 'async_trait>( &'life0 self, symbol: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<AssetProfile, BrokerError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Perfil fundamental del activo (nombre del bróker, ticker y variaciones dtd/m1/y1/ytd) vía el endpoint GraphQL del bróker.

Source

fn subscribe_live_deals<'life0, 'life1, 'async_trait>( &'life0 self, symbol: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<(), BrokerError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Suscribe el stream de operaciones de terceros (live-deal) para un activo. Los deals llegan por Event::LiveDeal.

Source

fn subscribe_commission_changes<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<(), BrokerError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Suscribe los cambios de comisión por tipo de instrumento. Llegan por Event::CommissionChanged.

Source

fn buy_binary<'life0, 'async_trait>( &'life0 self, req: BuyBinaryRequest, ) -> Pin<Box<dyn Future<Output = Result<OrderId, BrokerError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Compra clásica (turbo o binary según la duración).

BLITZ tiene su propia petición: Broker::buy_blitz.

Source

fn buy_blitz<'life0, 'async_trait>( &'life0 self, req: BuyBlitzRequest, ) -> Pin<Box<dyn Future<Output = Result<OrderId, BrokerError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Compra BLITZ: duración en segundos y payout explícito (protocolo v2).

Source

fn buy_digital_spot<'life0, 'async_trait>( &'life0 self, req: BuyDigitalRequest, ) -> Pin<Box<dyn Future<Output = Result<OrderId, BrokerError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Compra digital spot: el bróker elige el strike a precio actual.

Source

fn sell_option<'life0, 'life1, 'async_trait>( &'life0 self, order_id: &'life1 OrderId, ) -> Pin<Box<dyn Future<Output = Result<(), BrokerError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Venta anticipada (buyback) de una orden abierta. El bróker la admite dentro de la ventana buyback_deadtime del activo; si la orden ya no es vendible responde con su mensaje de rechazo.

Source

fn get_operation_result<'life0, 'life1, 'async_trait>( &'life0 self, order_id: &'life1 OrderId, ) -> Pin<Box<dyn Future<Output = Result<OperationResult, BrokerError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Resultado leído de la caché local (alimentada por events()).

No consulta al bróker: devuelve OperationResult::Pending mientras el cierre no haya llegado por eventos.

Source

fn events<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = Result<EventStream, BrokerError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Stream de eventos (cierres, balances, payouts en vivo, velas suscritas).

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§