use crate::config::common::encoders;
use crate::config::{ApiConfig, ConfigWarning, LockAndExit, MessageSetting, OrdersConfig};
use crate::proto;
#[must_use = "UpdateConfigBuilder does nothing until you call .submit()"]
pub struct UpdateConfigBuilder<'a, C> {
pub(in crate::config::builder) client: &'a C,
lock_and_exit: Option<LockAndExit>,
messages: Vec<MessageSetting>,
api: Option<ApiConfig>,
orders: Option<OrdersConfig>,
accepted_warnings: Vec<ConfigWarning>,
reset_api_order_sequence: bool,
}
impl<'a, C> UpdateConfigBuilder<'a, C> {
pub(in crate::config) fn new(client: &'a C) -> Self {
Self {
client,
lock_and_exit: None,
messages: Vec::new(),
api: None,
orders: None,
accepted_warnings: Vec::new(),
reset_api_order_sequence: false,
}
}
pub fn api(mut self, api: ApiConfig) -> Self {
self.api = Some(api);
self
}
pub fn orders(mut self, orders: OrdersConfig) -> Self {
self.orders = Some(orders);
self
}
pub fn lock_and_exit(mut self, lock_and_exit: LockAndExit) -> Self {
self.lock_and_exit = Some(lock_and_exit);
self
}
pub fn message(mut self, message: MessageSetting) -> Self {
self.messages.push(message);
self
}
pub fn messages(mut self, messages: impl IntoIterator<Item = MessageSetting>) -> Self {
self.messages.extend(messages);
self
}
pub fn accept_warning(mut self, warning: ConfigWarning) -> Self {
self.accepted_warnings.push(warning);
self
}
pub fn accept_warnings(mut self, warnings: impl IntoIterator<Item = ConfigWarning>) -> Self {
self.accepted_warnings.extend(warnings);
self
}
pub fn reset_api_order_sequence(mut self) -> Self {
self.reset_api_order_sequence = true;
self
}
pub(in crate::config) fn to_proto(&self, request_id: i32) -> proto::UpdateConfigRequest {
proto::UpdateConfigRequest {
req_id: Some(request_id),
lock_and_exit: self.lock_and_exit.as_ref().map(encoders::to_proto_lock_and_exit),
messages: self.messages.iter().map(encoders::to_proto_message).collect(),
api: self.api.as_ref().map(encoders::to_proto_api),
orders: self.orders.as_ref().map(encoders::to_proto_orders),
accepted_warnings: self.accepted_warnings.iter().map(encoders::to_proto_warning).collect(),
reset_api_order_sequence: self.reset_api_order_sequence.then_some(true),
}
}
}