pub struct MarketDataSubscribe {
pub subscribe_type: u8,
pub data_type: u8,
pub instruments: Vec<InstrumentKey>,
pub depth: Option<u32>,
pub time_frame: Option<String>,
}Expand description
A subscribe or unsubscribe command for the market data channel (client to server).
Build it with the constructors: MarketDataSubscribe::quotes, MarketDataSubscribe::order_book,
MarketDataSubscribe::last_trades, MarketDataSubscribe::last_candle and the unsubscribe_* forms.
subscribe_type and data_type are numbers on the wire, as in the broker docs. The broker allows
100 instruments per connection and 10 client messages per second.
§Examples
use brokapi_bcs_protocol::models::instrument::InstrumentKey;
use brokapi_bcs_protocol::ws::models::MarketDataSubscribe;
let sub = MarketDataSubscribe::order_book(vec![InstrumentKey::new("SBER", "TQBR")], 20);
assert_eq!(
serde_json::to_value(&sub)?,
serde_json::json!({
"subscribeType": 0,
"dataType": 0,
"instruments": [{ "ticker": "SBER", "classCode": "TQBR" }],
"depth": 20
})
);Fields§
§subscribe_type: u80 subscribe, 1 unsubscribe.
data_type: u8What to subscribe to: 0 order book, 1 last candle, 2 anonymous trades, 3 quotes.
instruments: Vec<InstrumentKey>The instruments the command is about.
depth: Option<u32>Order book depth, 1 to 20 by the broker docs (default 20). Sent only for the order book. Not checked here.
time_frame: Option<String>Candle time frame: M1 M5 M15 M30 H1 H4 D W MN. Sent only for the last candle. Not checked here.
Implementations§
Source§impl MarketDataSubscribe
impl MarketDataSubscribe
Sourcepub fn into_unsubscribe(self) -> Self
pub fn into_unsubscribe(self) -> Self
Turns a subscribe command into the matching unsubscribe: the same data type, instruments, depth
and time frame, with subscribe_type set to 1.
§Examples
use brokapi_bcs_protocol::models::instrument::InstrumentKey;
use brokapi_bcs_protocol::ws::models::MarketDataSubscribe;
let sub = MarketDataSubscribe::order_book(vec![InstrumentKey::new("SBER", "TQBR")], 10);
let unsub = sub.clone().into_unsubscribe();
assert_eq!((sub.subscribe_type, unsub.subscribe_type), (0, 1));
assert_eq!(unsub.depth, Some(10));Sourcepub fn quotes(instruments: Vec<InstrumentKey>) -> Self
pub fn quotes(instruments: Vec<InstrumentKey>) -> Self
Subscribes to quotes (dataType 3).
§Examples
use brokapi_bcs_protocol::models::instrument::InstrumentKey;
use brokapi_bcs_protocol::ws::models::MarketDataSubscribe;
let sub = MarketDataSubscribe::quotes(vec![InstrumentKey::new("SBER", "TQBR")]);
assert_eq!((sub.subscribe_type, sub.data_type), (0, 3));Sourcepub fn unsubscribe_quotes(instruments: Vec<InstrumentKey>) -> Self
pub fn unsubscribe_quotes(instruments: Vec<InstrumentKey>) -> Self
Unsubscribes from quotes (dataType 3, subscribeType 1).
§Examples
use brokapi_bcs_protocol::models::instrument::InstrumentKey;
use brokapi_bcs_protocol::ws::models::MarketDataSubscribe;
let cmd = MarketDataSubscribe::unsubscribe_quotes(vec![InstrumentKey::new("SBER", "TQBR")]);
assert_eq!((cmd.subscribe_type, cmd.data_type), (1, 3));Sourcepub fn order_book(instruments: Vec<InstrumentKey>, depth: u32) -> Self
pub fn order_book(instruments: Vec<InstrumentKey>, depth: u32) -> Self
Subscribes to the order book (dataType 0) with depth levels per side.
The broker docs allow 1 to 20 and default to 20. The depth is not checked here. The broker
computes the volumes in the answers over the levels within depth.
§Examples
use brokapi_bcs_protocol::models::instrument::InstrumentKey;
use brokapi_bcs_protocol::ws::models::MarketDataSubscribe;
let sub = MarketDataSubscribe::order_book(vec![InstrumentKey::new("SBER", "TQBR")], 5);
assert_eq!((sub.data_type, sub.depth), (0, Some(5)));Sourcepub fn unsubscribe_order_book(
instruments: Vec<InstrumentKey>,
depth: u32,
) -> Self
pub fn unsubscribe_order_book( instruments: Vec<InstrumentKey>, depth: u32, ) -> Self
Unsubscribes from the order book (dataType 0, subscribeType 1). Pass the same depth as
at subscribe if you compare it with the restore list of a session.
§Examples
use brokapi_bcs_protocol::models::instrument::InstrumentKey;
use brokapi_bcs_protocol::ws::models::MarketDataSubscribe;
let cmd = MarketDataSubscribe::unsubscribe_order_book(vec![InstrumentKey::new("SBER", "TQBR")], 5);
assert_eq!((cmd.subscribe_type, cmd.data_type), (1, 0));Sourcepub fn last_trades(instruments: Vec<InstrumentKey>) -> Self
pub fn last_trades(instruments: Vec<InstrumentKey>) -> Self
Subscribes to the anonymous trades tape (dataType 2).
§Examples
use brokapi_bcs_protocol::models::instrument::InstrumentKey;
use brokapi_bcs_protocol::ws::models::MarketDataSubscribe;
let sub = MarketDataSubscribe::last_trades(vec![InstrumentKey::new("SBER", "TQBR")]);
assert_eq!(sub.data_type, 2);Sourcepub fn unsubscribe_last_trades(instruments: Vec<InstrumentKey>) -> Self
pub fn unsubscribe_last_trades(instruments: Vec<InstrumentKey>) -> Self
Unsubscribes from the anonymous trades tape (dataType 2, subscribeType 1).
§Examples
use brokapi_bcs_protocol::models::instrument::InstrumentKey;
use brokapi_bcs_protocol::ws::models::MarketDataSubscribe;
let cmd = MarketDataSubscribe::unsubscribe_last_trades(vec![InstrumentKey::new("SBER", "TQBR")]);
assert_eq!((cmd.subscribe_type, cmd.data_type), (1, 2));Sourcepub fn last_candle(instruments: Vec<InstrumentKey>, time_frame: &str) -> Self
pub fn last_candle(instruments: Vec<InstrumentKey>, time_frame: &str) -> Self
Subscribes to the last candle (dataType 1) for a time frame.
time_frame is one of M1 M5 M15 M30 H1 H4 D W MN (broker docs). It is not checked here.
§Examples
use brokapi_bcs_protocol::models::instrument::InstrumentKey;
use brokapi_bcs_protocol::ws::models::MarketDataSubscribe;
let sub = MarketDataSubscribe::last_candle(vec![InstrumentKey::new("SBER", "TQBR")], "M5");
assert_eq!((sub.data_type, sub.time_frame.as_deref()), (1, Some("M5")));Sourcepub fn unsubscribe_last_candle(
instruments: Vec<InstrumentKey>,
time_frame: &str,
) -> Self
pub fn unsubscribe_last_candle( instruments: Vec<InstrumentKey>, time_frame: &str, ) -> Self
Unsubscribes from the last candle (dataType 1, subscribeType 1) for a time frame.
§Examples
use brokapi_bcs_protocol::models::instrument::InstrumentKey;
use brokapi_bcs_protocol::ws::models::MarketDataSubscribe;
let cmd = MarketDataSubscribe::unsubscribe_last_candle(vec![InstrumentKey::new("SBER", "TQBR")], "M5");
assert_eq!(cmd.subscribe_type, 1);Trait Implementations§
Source§impl Clone for MarketDataSubscribe
impl Clone for MarketDataSubscribe
Source§fn clone(&self) -> MarketDataSubscribe
fn clone(&self) -> MarketDataSubscribe
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for MarketDataSubscribe
impl Debug for MarketDataSubscribe
Source§impl PartialEq for MarketDataSubscribe
impl PartialEq for MarketDataSubscribe
Source§fn eq(&self, other: &MarketDataSubscribe) -> bool
fn eq(&self, other: &MarketDataSubscribe) -> bool
self and other values to be equal, and is used by ==.