use crate::messages::{encode_protobuf_message, OutgoingMessages};
use prost::Message;
pub(crate) trait RequestEncoder {
type Proto: prost::Message + Default + PartialEq + std::fmt::Debug;
const MSG_ID: OutgoingMessages;
fn to_proto(&self) -> Self::Proto;
fn encode_proto(&self) -> Vec<u8> {
self.to_proto().encode_to_vec()
}
fn encode_request(&self) -> Vec<u8> {
encode_protobuf_message(Self::MSG_ID as i32, &self.encode_proto())
}
}
pub(crate) trait ResponseProtoEncoder {
type Proto: prost::Message;
fn to_proto(&self) -> Self::Proto;
fn encode_proto(&self) -> Vec<u8> {
self.to_proto().encode_to_vec()
}
}
macro_rules! single_req_id_request_builder {
($builder:ident, $proto_type:ident, $msg_id:expr) => {
#[derive(Clone, Copy, Debug)]
pub struct $builder {
pub request_id: i32,
}
impl Default for $builder {
fn default() -> Self {
Self {
request_id: $crate::common::test_utils::helpers::constants::TEST_TICKER_ID,
}
}
}
impl $builder {
pub fn request_id(mut self, v: i32) -> Self {
self.request_id = v;
self
}
}
impl $crate::testdata::builders::RequestEncoder for $builder {
type Proto = $crate::proto::$proto_type;
const MSG_ID: $crate::messages::OutgoingMessages = $msg_id;
fn to_proto(&self) -> Self::Proto {
$crate::proto::$proto_type {
req_id: Some(self.request_id),
}
}
}
};
}
macro_rules! request_id_response_builder {
($builder:ident, $proto_type:ident) => {
#[derive(Clone, Debug)]
pub struct $builder {
pub request_id: i32,
}
impl Default for $builder {
fn default() -> Self {
Self {
request_id: $crate::common::test_utils::helpers::constants::TEST_TICKER_ID,
}
}
}
impl $crate::testdata::builders::ResponseProtoEncoder for $builder {
type Proto = $crate::proto::$proto_type;
fn to_proto(&self) -> Self::Proto {
$crate::proto::$proto_type {
req_id: Some(self.request_id),
}
}
}
};
}
macro_rules! empty_request_builder {
($builder:ident, $proto_type:ident, $msg_id:expr) => {
#[derive(Clone, Copy, Debug, Default)]
pub struct $builder;
impl $crate::testdata::builders::RequestEncoder for $builder {
type Proto = $crate::proto::$proto_type;
const MSG_ID: $crate::messages::OutgoingMessages = $msg_id;
fn to_proto(&self) -> Self::Proto {
$crate::proto::$proto_type {}
}
}
};
}
#[cfg_attr(not(all(feature = "sync", feature = "async")), allow(dead_code))] pub(crate) mod accounts;
pub(crate) mod config;
#[cfg_attr(not(all(feature = "sync", feature = "async")), allow(dead_code))] pub(crate) mod contracts;
pub(crate) mod display_groups;
#[cfg_attr(not(all(feature = "sync", feature = "async")), allow(dead_code))] pub(crate) mod market_data;
#[cfg_attr(not(all(feature = "sync", feature = "async")), allow(dead_code))] pub(crate) mod news;
#[cfg_attr(not(all(feature = "sync", feature = "async")), allow(dead_code))] pub(crate) mod orders;
pub(crate) mod positions;
pub(crate) mod scanner;
pub(crate) mod wsh;