Capture and verify production Polymarket and Kalshi order books
This commit is contained in:
@@ -116,6 +116,50 @@ fn kalshi_report(
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn captured_production_books_keep_empty_sides_and_exact_prices() {
|
||||
let capture: Value =
|
||||
serde_json::from_str(include_str!("../fixtures/live-polymarket-books.json")).unwrap();
|
||||
let responses = capture["responses"].as_array().unwrap();
|
||||
assert_eq!(responses.len(), 2);
|
||||
let condition = json!({"conditionId":"0xf17ad24eb4ad57926495b114149c765b9b95bc286eadc91cbbfa901ceb10d0b8"});
|
||||
for (i, response) in responses.iter().enumerate() {
|
||||
let asset = response["url"]
|
||||
.as_str()
|
||||
.unwrap()
|
||||
.split_once("token_id=")
|
||||
.unwrap()
|
||||
.1;
|
||||
let raw = &response["body"];
|
||||
let book = books::poly_book(&condition, asset, raw).unwrap();
|
||||
let audit = crate::book_audit::inspect(raw, asset).unwrap();
|
||||
assert_eq!(audit["hash_matches"], true);
|
||||
let (active, empty, side, price) = if i == 0 {
|
||||
("best_ask", "best_bid", "asks", 1_000)
|
||||
} else {
|
||||
("best_bid", "best_ask", "bids", 999_000)
|
||||
};
|
||||
assert!(book[empty].is_null());
|
||||
assert_eq!(
|
||||
book[active],
|
||||
json!({"price_micros":price,"size":"391881.71"})
|
||||
);
|
||||
assert_eq!(audit[side]["levels"], 82);
|
||||
assert_eq!(audit[side]["order"], "best_last");
|
||||
}
|
||||
|
||||
let capture: Value =
|
||||
serde_json::from_str(include_str!("../fixtures/live-kalshi-book.json")).unwrap();
|
||||
let book = books::kalshi_book(
|
||||
"KXPLATINUMH-26DEC0303-T1377.49",
|
||||
&capture["responses"][0]["body"],
|
||||
)
|
||||
.unwrap();
|
||||
for side in ["yes", "no"] {
|
||||
assert_eq!(book[side], json!({"best_bid":null,"best_ask":null}));
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn failed_first_polymarket_book_preserves_the_second_observation() {
|
||||
let market: Value =
|
||||
|
||||
Reference in New Issue
Block a user