Skip to main content

MarketDataSubscribe

Struct MarketDataSubscribe 

Source
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: u8

0 subscribe, 1 unsubscribe.

§data_type: u8

What 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

Source

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));
Source

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));
Source

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));
Source

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)));
Source

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));
Source

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);
Source

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));
Source

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")));
Source

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

Source§

fn clone(&self) -> MarketDataSubscribe

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for MarketDataSubscribe

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl PartialEq for MarketDataSubscribe

Source§

fn eq(&self, other: &MarketDataSubscribe) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for MarketDataSubscribe

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for MarketDataSubscribe

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> PolicyExt for T
where T: ?Sized,

§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] only if self and other return Action::Follow. Read more
§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] if either self or other returns Action::Follow. Read more
§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more