Archived
feat: ready to submit, a run to watch, the README, the review's fixes
Sprint 08 (roadmap/08. ready to submit.md), the last milestone. - scripts/watch.sh runs the collector with a live view of its log, stops cleanly on Ctrl-C, then checks the output (reconcile) and shows one symbol's book as text (show, a new binary). - The README for the solution, with the final runs: Polymarket through an outage it recovered from on its own, Kalshi's demo with two slow connections recycled. - From a review of the whole codebase: Kalshi takes RSA keys too (RSA-PSS-SHA256); a slow Kalshi connection takes the hourly recycle's next turn, which it nearly never got before; a market tracked again no longer fails reconcile; Book::add checks for overflow; usage and --help name the key variables; the first scan says how far it got. - Tests for every gap the reviews found, an offline run of the whole orchestrator among them; ShellCheck in CI.
This commit is contained in:
35 files changed
+2791
-207
No files matched your search
@@ -0,0 +1,94 @@
|
||||
//! The `reconcile` binary's exit status: what `scripts/watch.sh` relies on.
|
||||
|
||||
use std::process::Command;
|
||||
|
||||
use chrono::DateTime;
|
||||
use engineering_challenge::Side;
|
||||
use engineering_challenge::util::AlignedSbeWriter;
|
||||
use engineering_challenge::util::dtos::challenge_orderbook::{
|
||||
PriceLevelUpdateDomain, SnapshotBidsEntryDomain, SnapshotDomain,
|
||||
};
|
||||
|
||||
/// An output of a symbol's Snapshot and a Delta, after an orphan Delta of
|
||||
/// another symbol if `orphan`; then, if `mismatched`, a Snapshot of the
|
||||
/// symbol that the Delta doesn't lead to.
|
||||
fn output(orphan: bool, mismatched: bool) -> std::path::PathBuf {
|
||||
let at = DateTime::from_timestamp(1_794_390_000, 0).unwrap();
|
||||
let delta = |symbol: &str| PriceLevelUpdateDomain {
|
||||
backtest_timestamp: at,
|
||||
exchange_timestamp: at,
|
||||
price_level: 500_000,
|
||||
quantity: 2_000_000,
|
||||
side: Side::Buy,
|
||||
symbol: symbol.to_string(),
|
||||
};
|
||||
let path = std::env::temp_dir().join(format!(
|
||||
"reconcile-exit-{}-{orphan}-{mismatched}.sbe",
|
||||
std::process::id()
|
||||
));
|
||||
let mut writer = AlignedSbeWriter::create(path.to_str().unwrap(), 64 << 20).unwrap();
|
||||
if orphan {
|
||||
writer.write_msg(&delta("2")).unwrap();
|
||||
}
|
||||
writer
|
||||
.write_msg(&SnapshotDomain {
|
||||
received_at: at,
|
||||
exchange_timestamp: at,
|
||||
bids: vec![SnapshotBidsEntryDomain {
|
||||
price_level: 500_000,
|
||||
quantity: 1_000_000,
|
||||
}],
|
||||
asks: Vec::new(),
|
||||
symbol: "1".to_string(),
|
||||
})
|
||||
.unwrap();
|
||||
writer.write_msg(&delta("1")).unwrap();
|
||||
if mismatched {
|
||||
writer
|
||||
.write_msg(&SnapshotDomain {
|
||||
received_at: at,
|
||||
exchange_timestamp: at,
|
||||
bids: vec![SnapshotBidsEntryDomain {
|
||||
price_level: 500_000,
|
||||
quantity: 3_000_000,
|
||||
}],
|
||||
asks: Vec::new(),
|
||||
symbol: "1".to_string(),
|
||||
})
|
||||
.unwrap();
|
||||
}
|
||||
writer.flush().unwrap();
|
||||
path
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn reconcile_fails_on_an_orphan_delta_or_an_unexplained_mismatch_and_passes_otherwise() {
|
||||
let status = |orphan: bool, mismatched: bool| {
|
||||
let path = output(orphan, mismatched);
|
||||
let output = Command::new(env!("CARGO_BIN_EXE_reconcile"))
|
||||
.arg(&path)
|
||||
.output()
|
||||
.unwrap();
|
||||
std::fs::remove_file(&path).unwrap();
|
||||
(
|
||||
output.status.success(),
|
||||
String::from_utf8(output.stdout).unwrap(),
|
||||
)
|
||||
};
|
||||
let (passed, text) = status(false, false);
|
||||
assert!(passed, "{text}");
|
||||
assert_eq!(
|
||||
text,
|
||||
"1 snapshots, 1 deltas, 0 orphan deltas, 0 mismatches\n"
|
||||
);
|
||||
let (passed, text) = status(true, false);
|
||||
assert!(!passed, "{text}");
|
||||
assert!(text.contains("1 orphan deltas"), "{text}");
|
||||
// A Snapshot no log line explains (no log given): it fails too.
|
||||
let (passed, text) = status(false, true);
|
||||
assert!(!passed, "{text}");
|
||||
assert!(
|
||||
text.contains("1 mismatches") && text.contains("unexplained: 1 at "),
|
||||
"{text}"
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user