use super::super::RunnerResult;
use crate::types::*;
use serde::{Deserialize, Serialize};
use std::fmt;
#[derive(
Debug,
Clone,
Copy,
Serialize,
Deserialize,
PartialEq,
Eq,
Hash,
strum::Display,
strum::EnumString,
rkyv::Archive,
rkyv::Serialize,
rkyv::Deserialize,
)]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
#[strum(serialize_all = "SCREAMING_SNAKE_CASE")]
pub enum Side {
Yes,
No,
}
#[allow(non_upper_case_globals)]
impl Side {
pub const Back: Self = Self::Yes;
pub const Lay: Self = Self::No;
pub const Buy: Self = Self::Yes;
pub const Sell: Self = Self::No;
}
pub type BinarySide = Side;
pub type BinaryTimeInForce = TimeInForce;
#[derive(
Debug,
Clone,
Copy,
Serialize,
Deserialize,
PartialEq,
Eq,
Hash,
strum::Display,
strum::EnumString,
rkyv::Archive,
rkyv::Serialize,
rkyv::Deserialize,
)]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
#[strum(serialize_all = "SCREAMING_SNAKE_CASE")]
pub enum Persistence {
Lapse,
Persist,
MarketOnClose,
}
#[derive(
Debug,
Clone,
Copy,
Serialize,
Deserialize,
PartialEq,
Eq,
Hash,
rkyv::Archive,
rkyv::Serialize,
rkyv::Deserialize,
)]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
pub enum TimeInForce {
Gtc,
FillOrKill { min_fill: Option<Quantity> },
}
#[derive(
Debug,
Clone,
Copy,
Serialize,
Deserialize,
PartialEq,
Eq,
Hash,
strum::Display,
strum::EnumString,
rkyv::Archive,
rkyv::Serialize,
rkyv::Deserialize,
)]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
#[strum(serialize_all = "SCREAMING_SNAKE_CASE")]
pub enum MarketState {
Open,
InPlay,
Suspended,
Closed,
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
pub struct Command {
#[serde(default)]
pub correlation_id: Option<CorrelationId>,
pub market_id: MarketId,
pub kind: CommandKind,
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Hash)]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
pub enum CommandKind {
CreateMarket {
name: String,
market_model: MarketModel,
market_kind: MarketKind,
runner_ids: Vec<RunnerId>,
runner_labels: Vec<String>,
},
PlaceOrder {
runner_id: RunnerId,
account_id: AccountId,
client_order_id: Option<ClientOrderId>,
side: Side,
odds: OddsX10000,
stake: Money,
persistence: Persistence,
time_in_force: TimeInForce,
},
PlaceBinaryOrder {
account_id: AccountId,
client_order_id: Option<ClientOrderId>,
side: Side,
price_ticks: u16,
qty_shares: u64,
time_in_force: TimeInForce,
},
CancelOrder {
account_id: AccountId,
order_id: OrderId,
},
ReplaceOrder {
account_id: AccountId,
order_id: OrderId,
new_odds: Option<OddsX10000>,
new_stake: Option<Money>,
},
ReplaceBinaryOrder {
account_id: AccountId,
order_id: OrderId,
new_price_ticks: Option<u16>,
new_qty_shares: Option<u64>,
},
CashoutRunner {
account_id: AccountId,
runner_id: RunnerId,
percent_bps: u16,
max_slippage_bps: u16,
depth_levels: u16,
},
SetMarketState { state: MarketState },
CloseMarket { batch_max_events: u16 },
ContinueCloseMarket,
RemoveRunner {
runner_id: RunnerId,
reduction_factor_bps: Option<u32>,
},
VoidTradesFromTime {
from_matched_at_inclusive: DateTime,
reason: String,
},
VoidTradeIds {
trade_ids: Vec<TradeId>,
reason: String,
},
VoidMarket { reason: String },
SettleMarket {
runner_results: Vec<(RunnerId, RunnerResult)>,
dead_heat_divisor: Option<u32>,
},
HaltMarket { reason: u32 },
ResumeMarket,
RemoveMarket,
}
impl Command {
pub fn market_id(&self) -> MarketId {
self.market_id
}
}
impl fmt::Display for Command {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "{}", self.kind)
}
}
impl fmt::Display for CommandKind {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
let s = match self {
CommandKind::CreateMarket { .. } => "CREATE_MARKET",
CommandKind::PlaceOrder { .. } => "PLACE_ORDER",
CommandKind::PlaceBinaryOrder { .. } => "PLACE_BINARY_ORDER",
CommandKind::CancelOrder { .. } => "CANCEL_ORDER",
CommandKind::ReplaceOrder { .. } => "REPLACE_ORDER",
CommandKind::ReplaceBinaryOrder { .. } => "REPLACE_BINARY_ORDER",
CommandKind::SetMarketState { .. } => "SET_MARKET_STATE",
CommandKind::CloseMarket { .. } => "CLOSE_MARKET",
CommandKind::ContinueCloseMarket => "CONTINUE_CLOSE_MARKET",
CommandKind::RemoveRunner { .. } => "REMOVE_RUNNER",
CommandKind::VoidTradesFromTime { .. } => "VOID_TRADES_FROM_TIME",
CommandKind::VoidTradeIds { .. } => "VOID_TRADE_IDS",
CommandKind::VoidMarket { .. } => "VOID_MARKET",
CommandKind::SettleMarket { .. } => "SETTLE_MARKET",
CommandKind::HaltMarket { .. } => "HALT_MARKET",
CommandKind::ResumeMarket => "RESUME_MARKET",
CommandKind::CashoutRunner { .. } => "CASHOUT_RUNNER",
CommandKind::RemoveMarket => "REMOVE_MARKET",
};
write!(f, "{s}")
}
}