Recognize observed price boundaries on empty production books
This commit is contained in:
@@ -58,7 +58,20 @@ fn classify(before: &Value, after: &Value, buy: &Value, sell: &Value) -> &'stati
|
||||
return "inconclusive";
|
||||
};
|
||||
match (bid, ask) {
|
||||
(None, None) => "inconclusive",
|
||||
(None, None) => {
|
||||
let empty = [before, after].iter().all(|book| {
|
||||
["best_bid", "best_ask"]
|
||||
.iter()
|
||||
.all(|key| book.get(*key) == Some(&Value::Null))
|
||||
});
|
||||
if !empty {
|
||||
"inconclusive"
|
||||
} else if (buy, sell) == (0, 1_000_000) {
|
||||
"empty_book_defaults"
|
||||
} else {
|
||||
"different_prices"
|
||||
}
|
||||
}
|
||||
(Some(b), Some(a)) if b >= a => "inconclusive",
|
||||
_ if (buy, sell) == (bid.unwrap_or(0), ask.unwrap_or(1_000_000)) => "resting_side",
|
||||
(Some(b), Some(a)) if (buy, sell) == (a, b) => "opposing_side",
|
||||
@@ -70,6 +83,31 @@ fn classify(before: &Value, after: &Value, buy: &Value, sell: &Value) -> &'stati
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn observed_empty_book_defaults_require_two_explicitly_empty_sides() {
|
||||
let observation: Value =
|
||||
serde_json::from_str(include_str!("../fixtures/live-empty-prices.json")).unwrap();
|
||||
let raw = &observation["before"]["body"];
|
||||
let market = json!({"conditionId":raw["market"]});
|
||||
let token = raw["asset_id"].as_str().unwrap();
|
||||
let before = books::poly_book(&market, token, raw).unwrap();
|
||||
let after = books::poly_book(&market, token, &observation["after"]["body"]).unwrap();
|
||||
let price = |key: &str| json!({"price_micros":books::price(&observation[key]["body"]["price"]).unwrap()});
|
||||
assert_eq!(
|
||||
classify(&before, &after, &price("buy"), &price("sell")),
|
||||
"empty_book_defaults"
|
||||
);
|
||||
assert_eq!(
|
||||
classify(&before, &after, &price("sell"), &price("buy")),
|
||||
"different_prices"
|
||||
);
|
||||
let incomplete = json!({"hash":before["hash"]});
|
||||
assert_eq!(
|
||||
classify(&incomplete, &incomplete, &price("buy"), &price("sell")),
|
||||
"inconclusive"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn public_side_prices_replay_against_bracketing_books() {
|
||||
let raw: Value =
|
||||
|
||||
@@ -63,9 +63,12 @@ fn polymarket_report(
|
||||
}
|
||||
let complete = outcomes.iter().all(|s| s.get("book_error").is_none());
|
||||
let passed = compare
|
||||
&& outcomes
|
||||
.iter()
|
||||
.all(|s| s["price_check"]["status"] == "resting_side");
|
||||
&& outcomes.iter().all(|s| {
|
||||
matches!(
|
||||
s["price_check"]["status"].as_str(),
|
||||
Some("resting_side" | "empty_book_defaults")
|
||||
)
|
||||
});
|
||||
result["orderbooks_complete"] = json!(complete);
|
||||
if compare {
|
||||
result["price_check_passed"] = json!(passed);
|
||||
|
||||
Reference in New Issue
Block a user