Skip to main content

matchcore/
command.rs

1//! Command specifications for the matchcore library
2//!
3//! The `Command` type is the top-level command for all kinds of commands and orders,
4//! and is the only input accepted by the order book.
5
6mod amend;
7mod cancel;
8mod error;
9mod submit;
10mod validation;
11
12pub use amend::*;
13pub use cancel::*;
14pub use error::*;
15pub use submit::*;
16
17use crate::{SequenceNumber, Timestamp};
18
19/// Represents a top-level command for all kinds of commands and orders
20#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
21#[derive(Debug, Clone, PartialEq, Eq)]
22pub struct Command {
23    /// The common metadata for all command kinds
24    pub meta: CommandMeta,
25    /// The kind of command
26    pub kind: CommandKind,
27}
28
29/// Represents the common metadata for all command kinds
30#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
31#[derive(Debug, Clone, Copy, PartialEq, Eq)]
32pub struct CommandMeta {
33    /// The sequence number of the command
34    pub sequence_number: SequenceNumber,
35    /// The timestamp of the command
36    pub timestamp: Timestamp,
37}
38
39/// Represents the kind of command
40#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
41#[derive(Debug, Clone, PartialEq, Eq)]
42pub enum CommandKind {
43    /// A command to submit a new order
44    Submit(SubmitCmd),
45    /// A command to amend an existing order
46    Amend(AmendCmd),
47    /// A command to cancel an existing order
48    Cancel(CancelCmd),
49}