Route orders and market data by stable outcome asset IDs
This commit is contained in:
@@ -229,6 +229,14 @@ fn sports_catalog_and_trade_curve_survive_retries() {
|
||||
catalog = e.execute(serde_json::from_str(line).unwrap()).unwrap();
|
||||
}
|
||||
assert_eq!(catalog["markets"].as_array().unwrap().len(), 6);
|
||||
for market in catalog["markets"].as_array().unwrap() {
|
||||
let direct = e
|
||||
.execute(json!({"op":"assets","market":market["market"]}))
|
||||
.unwrap();
|
||||
assert_eq!(market["outcomes"], direct["outcomes"]);
|
||||
assert_eq!(market["outcomes"][0]["label"], market["yes_label"]);
|
||||
assert_eq!(market["outcomes"][1]["label"], market["no_label"]);
|
||||
}
|
||||
setup(&mut e);
|
||||
e.execute(order("ask", "alice", "sell", 50, 2)).unwrap();
|
||||
e.execute(order("bid", "bob", "buy", 50, 2)).unwrap();
|
||||
@@ -725,3 +733,61 @@ fn gtd_expiry_survives_rejection_and_recovery() {
|
||||
let mut e = Exchange::open(path).unwrap();
|
||||
assert_eq!(state(&mut e)["accounts"][1]["cash"], 1880);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn asset_discovery_and_routing_share_one_orderbook_across_restart() {
|
||||
let dir = tempdir().unwrap();
|
||||
let path = dir.path().join("assets.db");
|
||||
let mut e = Exchange::open(&path).unwrap();
|
||||
setup(&mut e);
|
||||
let market = "杯赛:NO:决赛";
|
||||
e.execute(json!({"op":"list","id":"new","market":market,"rules":"official"}))
|
||||
.unwrap();
|
||||
let discovery = json!({"op":"assets","market":market});
|
||||
let assets = e.execute(discovery.clone()).unwrap()["outcomes"].clone();
|
||||
let yes = assets[0]["asset_id"].clone();
|
||||
let no = assets[1]["asset_id"].clone();
|
||||
assert_ne!(yes, no);
|
||||
e.execute(json!({"op":"split","id":"pairs","account":"alice","market":market,"qty":3}))
|
||||
.unwrap();
|
||||
e.execute(json!({"op":"open","id":"open","market":market}))
|
||||
.unwrap();
|
||||
let ask = json!({"op":"order","id":"offer","asset_id":yes,"account":"alice","side":"sell","price":47,"qty":3});
|
||||
let receipt = e.execute(ask.clone()).unwrap();
|
||||
drop(e);
|
||||
let mut e = Exchange::open(path).unwrap();
|
||||
assert_eq!(e.execute(discovery).unwrap()["outcomes"], assets);
|
||||
assert_eq!(e.execute(ask).unwrap(), receipt);
|
||||
let book = e.execute(json!({"op":"book","asset_id":yes})).unwrap();
|
||||
assert_eq!(
|
||||
book,
|
||||
e.execute(json!({"op":"book","market":market,"outcome":"YES"}))
|
||||
.unwrap()
|
||||
);
|
||||
assert_eq!(book["asks"][0]["size"], 3);
|
||||
let opposite = e.execute(json!({"op":"quote","asset_id":no})).unwrap();
|
||||
assert_eq!(opposite["best_bid_micros"], 530000);
|
||||
let mut buy = order("take", "bob", "buy", 47, 2);
|
||||
buy["market"] = json!(market);
|
||||
let mut conflicting = buy.clone();
|
||||
conflicting["asset_id"] = no.clone();
|
||||
assert!(e.execute(conflicting).is_err());
|
||||
assert_eq!(e.execute(buy).unwrap()["filled"], 2);
|
||||
let history = e
|
||||
.execute(json!({"op":"history","asset_id":yes,"from_ms":0,"to_ms":i64::MAX,"limit":10}))
|
||||
.unwrap();
|
||||
assert_eq!(history["points"][0]["quantity"], 2);
|
||||
assert_eq!(history["asset_id"], yes);
|
||||
let live = e
|
||||
.execute(json!({"op":"open_orders","asset_id":yes,"account":"alice"}))
|
||||
.unwrap();
|
||||
assert_eq!(live["orders"][0]["open_size"], 1);
|
||||
assert_eq!(live["orders"][0]["asset_id"], yes);
|
||||
let held = e
|
||||
.execute(json!({"op":"positions","market":market,"account":"bob"}))
|
||||
.unwrap();
|
||||
assert_eq!(held["positions"][0]["asset_id"], yes);
|
||||
for asset in ["eb:YES:unlisted", "eb:DRAW:e", "venue:123"] {
|
||||
assert!(e.execute(json!({"op":"book","asset_id":asset})).is_err());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user