Archived
Add Side to PriceLevelUpdate.
This commit is contained in:
1 parent
cd02a89303
commit
97360aefac
9 files changed
+82
-1
No files matched your search
@@ -8,6 +8,7 @@ build = "src/util/build.rs"
|
|||||||
anyhow = "1"
|
anyhow = "1"
|
||||||
chrono = "0.4"
|
chrono = "0.4"
|
||||||
crossbeam = "0.8.4"
|
crossbeam = "0.8.4"
|
||||||
|
serde = { version = "1", features = ["derive"] }
|
||||||
tempfile = "3"
|
tempfile = "3"
|
||||||
|
|
||||||
[build-dependencies]
|
[build-dependencies]
|
||||||
|
|||||||
@@ -18,3 +18,4 @@ If you're curious to see the YAML schema, take a look at [challenge_orderbook.ya
|
|||||||
We also use a custom timestamp field, so that the Rust struct can use
|
We also use a custom timestamp field, so that the Rust struct can use
|
||||||
`chrono::DateTime` in the generated struct, and in SBE schema, it is a uint64
|
`chrono::DateTime` in the generated struct, and in SBE schema, it is a uint64
|
||||||
representing the timestamp as the number of microseconds since unix epoch.
|
representing the timestamp as the number of microseconds since unix epoch.
|
||||||
|
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
id: 1
|
id: 1
|
||||||
version: 1
|
version: 2
|
||||||
description: Voluntas engineering challenge orderbook update schema.
|
description: Voluntas engineering challenge orderbook update schema.
|
||||||
|
|
||||||
messages:
|
messages:
|
||||||
@@ -49,4 +49,8 @@ messages:
|
|||||||
id: 5
|
id: 5
|
||||||
type: int64
|
type: int64
|
||||||
description: The absolute available quantity, in fixed point; 1_000_000 = 1 share/contract
|
description: The absolute available quantity, in fixed point; 1_000_000 = 1 share/contract
|
||||||
|
side:
|
||||||
|
id: 6
|
||||||
|
type: SideEncoding
|
||||||
|
description: The side being updated; Buy = bid, Sell = ask
|
||||||
symbol: { id: 3, type: string }
|
symbol: { id: 3, type: string }
|
||||||
@@ -47,6 +47,11 @@
|
|||||||
<type name="bytes32" primitiveType="uint8" length="32"/>
|
<type name="bytes32" primitiveType="uint8" length="32"/>
|
||||||
<type name="address" primitiveType="uint8" length="20"/>
|
<type name="address" primitiveType="uint8" length="20"/>
|
||||||
|
|
||||||
|
<!-- The shared Side domain enum owns and validates the Buy/Sell values. -->
|
||||||
|
<composite name="SideEncoding" description="Orderbook side: 0 = Buy (bid), 1 = Sell (ask)">
|
||||||
|
<type name="value" primitiveType="uint8"/>
|
||||||
|
</composite>
|
||||||
|
|
||||||
<!-- FIX-standard boolean: one byte on the wire. -->
|
<!-- FIX-standard boolean: one byte on the wire. -->
|
||||||
<enum name="BooleanType" encodingType="uint8">
|
<enum name="BooleanType" encodingType="uint8">
|
||||||
<validValue name="False">0</validValue>
|
<validValue name="False">0</validValue>
|
||||||
|
|||||||
@@ -1 +1,4 @@
|
|||||||
pub mod util;
|
pub mod util;
|
||||||
|
|
||||||
|
mod side;
|
||||||
|
pub use side::{InvalidSide, Side};
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
use chrono::DateTime;
|
use chrono::DateTime;
|
||||||
|
use engineering_challenge::Side;
|
||||||
use engineering_challenge::util::dtos::challenge_orderbook::{
|
use engineering_challenge::util::dtos::challenge_orderbook::{
|
||||||
AnyMessage, PriceLevelUpdateDomain, SnapshotAsksEntryDomain, SnapshotBidsEntryDomain,
|
AnyMessage, PriceLevelUpdateDomain, SnapshotAsksEntryDomain, SnapshotBidsEntryDomain,
|
||||||
SnapshotDomain,
|
SnapshotDomain,
|
||||||
@@ -35,6 +36,7 @@ fn main() -> anyhow::Result<()> {
|
|||||||
exchange_timestamp: timestamp,
|
exchange_timestamp: timestamp,
|
||||||
price_level: 400_000,
|
price_level: 400_000,
|
||||||
quantity: 1_250_000,
|
quantity: 1_250_000,
|
||||||
|
side: Side::Buy,
|
||||||
symbol: symbol.clone(),
|
symbol: symbol.clone(),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
+43
@@ -0,0 +1,43 @@
|
|||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
|
/// The side of an order or price level, shared by DTOs and application code.
|
||||||
|
/// Buy means bid; Sell means ask. The discriminants are SBE wire values and
|
||||||
|
/// must not be renumbered.
|
||||||
|
#[repr(u8)]
|
||||||
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
|
||||||
|
pub enum Side {
|
||||||
|
Buy = 0,
|
||||||
|
Sell = 1,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl std::fmt::Display for Side {
|
||||||
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
|
f.write_str(match self {
|
||||||
|
Self::Buy => "Buy",
|
||||||
|
Self::Sell => "Sell",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl TryFrom<u8> for Side {
|
||||||
|
type Error = InvalidSide;
|
||||||
|
|
||||||
|
fn try_from(value: u8) -> Result<Self, Self::Error> {
|
||||||
|
match value {
|
||||||
|
0 => Ok(Self::Buy),
|
||||||
|
1 => Ok(Self::Sell),
|
||||||
|
_ => Err(InvalidSide(value)),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||||
|
pub struct InvalidSide(pub u8);
|
||||||
|
|
||||||
|
impl std::fmt::Display for InvalidSide {
|
||||||
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
|
write!(f, "invalid side {}; expected 0 (Buy) or 1 (Sell)", self.0)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl std::error::Error for InvalidSide {}
|
||||||
@@ -26,6 +26,10 @@ fn main() -> Result<()> {
|
|||||||
.with_domain_type(
|
.with_domain_type(
|
||||||
ConversionSelector::named_type("UTCTimestampMicrosEncoding"),
|
ConversionSelector::named_type("UTCTimestampMicrosEncoding"),
|
||||||
"chrono::DateTime<chrono::Utc>",
|
"chrono::DateTime<chrono::Utc>",
|
||||||
|
)
|
||||||
|
.with_domain_type(
|
||||||
|
ConversionSelector::named_type("SideEncoding"),
|
||||||
|
"crate::Side",
|
||||||
);
|
);
|
||||||
generate_str_to_out_dir(&xml, config)?;
|
generate_str_to_out_dir(&xml, config)?;
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|||||||
@@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
use chrono::{DateTime, Utc};
|
use chrono::{DateTime, Utc};
|
||||||
|
|
||||||
|
use crate::{InvalidSide, Side};
|
||||||
|
|
||||||
macro_rules! schemas {
|
macro_rules! schemas {
|
||||||
($($schema:ident),* $(,)?) => {$(
|
($($schema:ident),* $(,)?) => {$(
|
||||||
pub mod $schema {
|
pub mod $schema {
|
||||||
@@ -76,6 +78,22 @@ macro_rules! sbe_encode {
|
|||||||
|
|
||||||
schemas!(challenge_orderbook);
|
schemas!(challenge_orderbook);
|
||||||
|
|
||||||
|
impl challenge_orderbook::TryFromSbe<challenge_orderbook::SideEncoding> for Side {
|
||||||
|
type Error = InvalidSide;
|
||||||
|
|
||||||
|
fn try_from_sbe(wire: challenge_orderbook::SideEncoding) -> Result<Self, Self::Error> {
|
||||||
|
Self::try_from(wire.value())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl challenge_orderbook::TryToSbe<challenge_orderbook::SideEncoding> for Side {
|
||||||
|
type Error = std::convert::Infallible;
|
||||||
|
|
||||||
|
fn try_to_sbe(&self) -> Result<challenge_orderbook::SideEncoding, Self::Error> {
|
||||||
|
Ok(challenge_orderbook::SideEncoding::new(*self as u8))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
sbe_encode!(
|
sbe_encode!(
|
||||||
challenge_orderbook::SnapshotDomain,
|
challenge_orderbook::SnapshotDomain,
|
||||||
challenge_orderbook::PriceLevelUpdateDomain,
|
challenge_orderbook::PriceLevelUpdateDomain,
|
||||||
|
|||||||
Reference in new issue
Block a user