Skip to main content

Broker

Trait Broker 

Source
pub trait Broker: Send + Sync {
Show 21 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 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 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; // Provided methods fn quote_payout<'life0, 'life1, 'async_trait>( &'life0 self, symbol: &'life1 str, option_type: OptionType, expiration_seconds: u64, amount: f64, ) -> Pin<Box<dyn Future<Output = Result<PayoutQuote, BrokerError>> + Send + 'async_trait>> where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait { ... } fn iqoption_extras(&self) -> Option<&dyn IqOptionExtras> { ... } fn subscribe_ticks<'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 { ... }
}
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 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 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).

Provided Methods§

Source

fn quote_payout<'life0, 'life1, 'async_trait>( &'life0 self, symbol: &'life1 str, option_type: OptionType, expiration_seconds: u64, amount: f64, ) -> Pin<Box<dyn Future<Output = Result<PayoutQuote, BrokerError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Cotización por expiración y tipo de opción.

La referencia actual es CALL: Deriv traduce OptionType::Binary a CALL y la cotización digital de IQ usa call.bid del spot. El tipo no transporta dirección, así que no se debe asumir que PUT paga lo mismo.

El default no inventa un payout: devuelve available: false con profit_percent: None. Un adaptador que pueda cotizar debe sobrescribirlo.

Source

fn iqoption_extras(&self) -> Option<&dyn IqOptionExtras>

Acceso a las capacidades exclusivas de IQ Option, si el adaptador las ofrece. Los adaptadores que no las implementan devuelven None.

Source

fn subscribe_ticks<'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 nativo de ticks de un activo.

Los ticks llegan por Event::PriceTick. Un adaptador sin stream nativo hereda el rechazo explícito; no se simula con polling.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§