diff --git a/Cargo.lock b/Cargo.lock index 31691b1..76181d2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -9,7 +9,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3019c0b8d883a8a17df3129e417ef463c087807d245e8881a31d583dee1c0519" dependencies = [ "cfg-if", - "getrandom", + "getrandom 0.4.3", "once_cell", "version_check", "zerocopy", @@ -21,18 +21,51 @@ version = "1.0.104" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "330a5ed07fa54e4702c9d6c4174f74427fc0ef6e214bbd677ae50a5099946470" +[[package]] +name = "atomic-waker" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" + +[[package]] +name = "base64" +version = "0.22.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b3254f16251a8381aa12e40e3c4d2f0199f8c6508fbecb9d91f575e0fbb8c6" + +[[package]] +name = "base64" +version = "0.23.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac07cdecf99051d9a5238b80f35af32cdeba5b336e55d957b318b50137e18da5" + [[package]] name = "bitflags" version = "2.13.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3ded4057c258ba199e2d26386d3af3780957ecaee6c4ef4041c6b4b8b97c0b06" +[[package]] +name = "block-buffer" +version = "0.10.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71" +dependencies = [ + "generic-array", +] + [[package]] name = "bumpalo" version = "3.20.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "72f5acc6cb2ba439de613abc23857ec3d78374d8ed5ac84e9d11336e87da8649" +[[package]] +name = "bytes" +version = "1.12.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "776dfebd015e2d8732c684a2c71003674ccb49457b539b9e82151ba38e96dd7c" + [[package]] name = "cc" version = "1.12.0" @@ -49,6 +82,23 @@ version = "1.0.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "4e7648175b45a9a48536d676f68d918270699102aa8dab5496df06904c914600" +[[package]] +name = "cfg_aliases" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f079e83a288787bcd14a6aea84cee5c87a67c5a3e660c30f557a3d24761b3527" + +[[package]] +name = "chacha20" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "65c35e4b699c7e15ccbe7ee35c005e4fc0a278d22238a2857e6ce2dadeda1b06" +dependencies = [ + "cfg-if", + "cpufeatures 0.3.1", + "rand_core", +] + [[package]] name = "cli" version = "0.1.0" @@ -58,6 +108,55 @@ dependencies = [ "serde_json", ] +[[package]] +name = "cpufeatures" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "59ed5838eebb26a2bb2e58f6d5b5316989ae9d08bab10e0e6d103e656d1b0280" +dependencies = [ + "libc", +] + +[[package]] +name = "cpufeatures" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ca28b0ae3115b884660db4118d803791fd6756b6e88f39c0f3f7859060d7566" +dependencies = [ + "libc", +] + +[[package]] +name = "crypto-common" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78c8292055d1c1df0cce5d180393dc8cce0abec0a7102adb6c7b1eef6016d60a" +dependencies = [ + "generic-array", + "typenum", +] + +[[package]] +name = "digest" +version = "0.10.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" +dependencies = [ + "block-buffer", + "crypto-common", +] + +[[package]] +name = "displaydoc" +version = "0.2.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c6232dd377dcc64799954cbd3a9bb882e9cdc1308ccd87b1c098f1fb2eaf82a8" +dependencies = [ + "proc-macro2", + "quote", + "syn 3.0.10", +] + [[package]] name = "errno" version = "0.3.15" @@ -65,7 +164,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e35d6e78f4cebb90e51d543db8fe41528851d6deeef6ef21ebd4bfdc1e784776" dependencies = [ "libc", - "windows-sys", + "windows-sys 0.61.2", ] [[package]] @@ -104,6 +203,87 @@ version = "0.1.16" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3e44f110d1777dc6559a51e7d45083945ded4f1bf3305494350f693b6d20b9c8" +[[package]] +name = "form_urlencoded" +version = "1.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "afa489199eaffb1211795df1c6236ce1ad0d41a6fa45250add73e3b02420f06e" +dependencies = [ + "percent-encoding", +] + +[[package]] +name = "futures-channel" +version = "0.3.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1f9e3d69d39e4862ffed03ed071a76f9a13ba1d9109d355b0f0aa6b15e393c4" +dependencies = [ + "futures-core", + "futures-sink", +] + +[[package]] +name = "futures-core" +version = "0.3.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "92d699e522242e69e3003b94ecc1f960f3a5e015aa7c5d7486e65ad01dd94f5e" + +[[package]] +name = "futures-io" +version = "0.3.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53c0fa8157de1303bfffdaa1cc2a673bfffb60102f76b0ef4441659124373fed" + +[[package]] +name = "futures-sink" +version = "0.3.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1944426bf7d03f1d14f708785e4b33efd750b36d48a157b836b3efc15ede8e1d" + +[[package]] +name = "futures-task" +version = "0.3.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd417de3d1d015fc3bfd2b1ea46dfc7bab72ef86f1cc7cc9c78e728b34a6d1fd" + +[[package]] +name = "futures-util" +version = "0.3.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0d50a92467f8ba5dd6e3ee5d4bd04d73ab2e4e1c44474a0674821dfce14b79bc" +dependencies = [ + "futures-core", + "futures-io", + "futures-sink", + "futures-task", + "memchr", + "pin-project-lite", + "slab", +] + +[[package]] +name = "generic-array" +version = "0.14.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" +dependencies = [ + "typenum", + "version_check", +] + +[[package]] +name = "getrandom" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff2abc00be7fca6ebc474524697ae276ad847ad0a6b3faa4bcb027e9a4614ad0" +dependencies = [ + "cfg-if", + "js-sys", + "libc", + "wasi", + "wasm-bindgen", +] + [[package]] name = "getrandom" version = "0.4.3" @@ -114,6 +294,7 @@ dependencies = [ "js-sys", "libc", "r-efi", + "rand_core", "wasm-bindgen", ] @@ -135,6 +316,214 @@ dependencies = [ "hashbrown", ] +[[package]] +name = "http" +version = "1.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a07dc2d082802d1782faa5b3c8ac252f3a4fc89f51e76c3f37dc2d1a5b857c05" +dependencies = [ + "bytes", + "itoa", +] + +[[package]] +name = "http-body" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ca2a8f2913ee65f60facd6a5905613afaa448497a0230cc41ce022d93290bc2c" +dependencies = [ + "bytes", + "http", +] + +[[package]] +name = "http-body-util" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "23169fe34a5fbcdd3f3862e78fb9b6fccd5f02a6dc6f732547005d45631ce71c" +dependencies = [ + "bytes", + "futures-core", + "http", + "http-body", + "pin-project-lite", +] + +[[package]] +name = "httparse" +version = "1.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6dbf3de79e51f3d586ab4cb9d5c3e2c14aa28ed23d180cf89b4df0454a69cc87" + +[[package]] +name = "hyper" +version = "1.13.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "229c6ff5584df4c6becbfe00567128bac768c8cd32ebc8a8366bd81ed072e8f3" +dependencies = [ + "atomic-waker", + "bytes", + "futures-core", + "http", + "http-body", + "httparse", + "itoa", + "pin-project-lite", + "smallvec", + "tokio", + "want", +] + +[[package]] +name = "hyper-rustls" +version = "0.27.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dfa8e654703247911e29c23fbeaa261834bd9bb74efba2f9acddc37bfb127f53" +dependencies = [ + "http", + "hyper", + "hyper-util", + "rustls", + "tokio", + "tokio-rustls", + "tower-service", + "webpki-roots", +] + +[[package]] +name = "hyper-util" +version = "0.1.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ddc03d96684f9226b8a787cdb71488417b53ab5ea8fdb1dac946cb9431cc8bff" +dependencies = [ + "base64 0.23.1", + "bytes", + "futures-channel", + "futures-util", + "http", + "http-body", + "httparse", + "hyper", + "ipnet", + "libc", + "percent-encoding", + "pin-project-lite", + "socket2", + "tokio", + "tower-service", + "tracing", +] + +[[package]] +name = "icu_collections" +version = "2.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fe090a42a0d3140fed8c63263ed1fecc02422cb2f4bfe55cd8de2de1b8e105dd" +dependencies = [ + "displaydoc", + "potential_utf", + "utf8_iter", + "yoke", + "zerofrom", + "zerovec", +] + +[[package]] +name = "icu_locale_core" +version = "2.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "25d29b57c17c6528d0dc4c2141cfa2d08200465acb537a3909c8b9b8a4a984c0" +dependencies = [ + "displaydoc", + "litemap", + "tinystr", + "writeable", + "zerovec", +] + +[[package]] +name = "icu_normalizer" +version = "2.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "404a3b8c486f205c87fe7f23ab6894d84a4ad76d6e4671ae1981ba7def87c599" +dependencies = [ + "icu_collections", + "icu_normalizer_data", + "icu_properties", + "icu_provider", + "smallvec", + "zerovec", +] + +[[package]] +name = "icu_normalizer_data" +version = "2.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "20f0088bfb7441f7a37fa0c9e20cb1e9cba1cac6b9ce8cd2a6dc44294f8e8cbc" + +[[package]] +name = "icu_properties" +version = "2.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2ea83d991c56158f7cf898bf86436c1dfe7c07ee82fe88951f2695c9f37a379f" +dependencies = [ + "displaydoc", + "icu_collections", + "icu_locale_core", + "icu_properties_data", + "icu_provider", + "zerotrie", + "zerovec", +] + +[[package]] +name = "icu_properties_data" +version = "2.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b98f29af82d02b163fe50161388350e743bb3107cc8e8c2f7314cb505faddfcf" + +[[package]] +name = "icu_provider" +version = "2.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "413099315636c588ee8f011190b329b971a09a8fae9d157e01dcae8379468514" +dependencies = [ + "displaydoc", + "icu_locale_core", + "writeable", + "yoke", + "zerofrom", + "zerotrie", + "zerovec", +] + +[[package]] +name = "idna" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b0875f23caa03898994f6ddc501886a45c7d3d62d04d2d90788d47be1b1e4de" +dependencies = [ + "idna_adapter", + "smallvec", + "utf8_iter", +] + +[[package]] +name = "idna_adapter" +version = "1.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb68373c0d6620ef8105e855e7745e18b0d00d3bdb07fb532e434244cdb9a714" +dependencies = [ + "icu_normalizer", + "icu_properties", +] + +[[package]] +name = "ipnet" +version = "2.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "007d6e6b91097094791302ccc6cd0588e0700ddac5c6829035bcd71eff4dc433" + [[package]] name = "itoa" version = "1.0.19" @@ -148,6 +537,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7883d941dae510fb2d978fc3fe018c71c9e2892fd38854de3e8b92c2e5ad9cc5" dependencies = [ "cfg-if", + "futures-util", "wasm-bindgen", ] @@ -174,6 +564,24 @@ version = "0.12.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "32a66949e030da00e8c7d4434b251670a91556f4144941d37452769c25d58a53" +[[package]] +name = "litemap" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "47d9d19d1d6efa0109d2f65ff4c85cddd50bd572e5a00127ab10987290bcefae" + +[[package]] +name = "log" +version = "0.4.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5d15f86d12da44cd8d4ec3c73984537eb7f4cadcb9776a575a0a8a05ca11005c" + +[[package]] +name = "lru-slab" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4050469837a6ff301cd14c1f8f24f88549e6d548f24f64e2148eb0f72cebc51f" + [[package]] name = "matching" version = "0.1.0" @@ -184,18 +592,50 @@ version = "2.8.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cf8baf1c55e62ffcace7a9f06f4bd9cd3f0c4beb022d3b367256b91b87513d98" +[[package]] +name = "mio" +version = "1.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "20521a903f02b0a573cd6840e9d0a5a0cc043d361fe924092cd70f8556cc9c4a" +dependencies = [ + "libc", + "wasi", + "windows-sys 0.61.2", +] + [[package]] name = "once_cell" version = "1.21.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9f7c3e4beb33f85d45ae3e3a1792185706c8e16d043238c593331cc7cd313b50" +[[package]] +name = "percent-encoding" +version = "2.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b4f627cb1b25917193a259e49bdad08f671f8d9708acfd5fe0a8c1455d87220" + +[[package]] +name = "pin-project-lite" +version = "0.2.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c938015719552d665fd0553b90d96cd7ff58e83e4c061ca99e6bb78865a72752" + [[package]] name = "pkg-config" version = "0.3.34" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f6b464fbc74e149a392436b17d523f769e057cb6877f6a5c4618bc6f11800548" +[[package]] +name = "potential_utf" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d83eb9bc6d8e5cf568e7a1101d60ee05e81ed50ea106026f3d18deeb046d7661" +dependencies = [ + "zerovec", +] + [[package]] name = "proc-macro2" version = "1.0.107" @@ -205,6 +645,62 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "quinn" +version = "0.11.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4051e23e9185c255a7e33ef59cdbca87a22d359052eecd22fc6b901fb37d9d11" +dependencies = [ + "bytes", + "cfg_aliases", + "pin-project-lite", + "quinn-proto", + "quinn-udp", + "rustc-hash", + "rustls", + "socket2", + "thiserror", + "tokio", + "tracing", + "web-time", +] + +[[package]] +name = "quinn-proto" +version = "0.11.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0e750cca55fe4f0439a15d0bb529da9651e79993e8e72c61a899a36d462befbe" +dependencies = [ + "bytes", + "getrandom 0.4.3", + "lru-slab", + "rand", + "rand_pcg", + "ring", + "rustc-hash", + "rustls", + "rustls-pki-types", + "slab", + "thiserror", + "tinyvec", + "tracing", + "web-time", +] + +[[package]] +name = "quinn-udp" +version = "0.5.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "af66907df18639dcf4db56ca65490cabc4b27a97dbadd96f2926cca73298f016" +dependencies = [ + "cfg_aliases", + "libc", + "once_cell", + "socket2", + "tracing", + "windows-sys 0.61.2", +] + [[package]] name = "quote" version = "1.0.47" @@ -220,6 +716,86 @@ version = "6.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f8dcc9c7d52a811697d2151c701e0d08956f92b0e24136cf4cf27b57a6a0d9bf" +[[package]] +name = "rand" +version = "0.10.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f6fa277c67e6ea590466f04c3fe82cb509f0864fe470643e5570de9514a9b11" +dependencies = [ + "chacha20", + "getrandom 0.4.3", + "rand_core", +] + +[[package]] +name = "rand_core" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "63b8176103e19a2643978565ca18b50549f6101881c443590420e4dc998a3c69" + +[[package]] +name = "rand_pcg" +version = "0.10.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eb95882a1e14462c69aea9984bb261293ccfe6022ef8de0eda18bd5afb0052df" +dependencies = [ + "rand_core", +] + +[[package]] +name = "reqwest" +version = "0.12.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "eddd3ca559203180a307f12d114c268abf583f59b03cb906fd0b3ff8646c1147" +dependencies = [ + "base64 0.22.1", + "bytes", + "futures-channel", + "futures-core", + "futures-util", + "http", + "http-body", + "http-body-util", + "hyper", + "hyper-rustls", + "hyper-util", + "js-sys", + "log", + "percent-encoding", + "pin-project-lite", + "quinn", + "rustls", + "rustls-pki-types", + "serde", + "serde_json", + "serde_urlencoded", + "sync_wrapper", + "tokio", + "tokio-rustls", + "tower", + "tower-http", + "tower-service", + "url", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", + "webpki-roots", +] + +[[package]] +name = "ring" +version = "0.17.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a4689e6c2294d81e88dc6261c768b63bc4fcdb852be6d1352498b114f61383b7" +dependencies = [ + "cc", + "cfg-if", + "getrandom 0.2.17", + "libc", + "untrusted", + "windows-sys 0.52.0", +] + [[package]] name = "rusqlite" version = "0.32.1" @@ -234,6 +810,12 @@ dependencies = [ "smallvec", ] +[[package]] +name = "rustc-hash" +version = "2.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6b1e7f9a428571be2dc5bc0505c13fb6bf936822b894ec87abf8a08a4e51742d" + [[package]] name = "rustix" version = "1.1.6" @@ -244,7 +826,42 @@ dependencies = [ "errno", "libc", "linux-raw-sys", - "windows-sys", + "windows-sys 0.61.2", +] + +[[package]] +name = "rustls" +version = "0.23.46" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "48e13bd8c0e9365c43cfa5c9e8f9ad49d3c8444926c9aac819e0e4dc503c8fdf" +dependencies = [ + "once_cell", + "ring", + "rustls-pki-types", + "rustls-webpki", + "subtle", + "zeroize", +] + +[[package]] +name = "rustls-pki-types" +version = "1.16.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "102f35f7de7b06d8c61f1cff6592f5253e0dea431c74867aad5dfd70f44663fb" +dependencies = [ + "web-time", + "zeroize", +] + +[[package]] +name = "rustls-webpki" +version = "0.103.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3a0760a887c14823fca5a1c970b01d47c328c696c0c64829d1df50e8f853fd5" +dependencies = [ + "ring", + "rustls-pki-types", + "untrusted", ] [[package]] @@ -253,6 +870,12 @@ version = "1.0.23" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cf54715a573b99ac80df0bc206da022bcd442c974952c7b9720069370852e21f" +[[package]] +name = "ryu" +version = "1.0.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9774ba4a74de5f7b1c1451ed6cd5285a32eddb5cccb8cc655a4e50009e06477f" + [[package]] name = "serde" version = "1.0.229" @@ -296,18 +919,69 @@ dependencies = [ "zmij", ] +[[package]] +name = "serde_urlencoded" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d3491c14715ca2294c4d6a88f15e84739788c1d030eed8c110436aafdaa2f3fd" +dependencies = [ + "form_urlencoded", + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "sha1" +version = "0.10.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a978451301f4db1d02937a4ab3ccce137717b81826e79b7d49ffe3244a13c3b8" +dependencies = [ + "cfg-if", + "cpufeatures 0.2.17", + "digest", +] + [[package]] name = "shlex" version = "2.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f8fadd59c855ef2080decdef8ff161eb6661b86933c9d82e5ba29dc602a55aba" +[[package]] +name = "slab" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c790de23124f9ab44544d7ac05d60440adc586479ce501c1d6d7da3cd8c9cf5" + [[package]] name = "smallvec" version = "1.16.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3244542535d5de959d90ec55d1b5ff0fd2bb7b1310223907d5f11932847f7b59" +[[package]] +name = "socket2" +version = "0.6.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3d1e2c7f27f8d4cb10542a02c49005dbd6e93095799d6f3be745fae9f8fedd4" +dependencies = [ + "libc", + "windows-sys 0.61.2", +] + +[[package]] +name = "stable_deref_trait" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ce2be8dc25455e1f91df71bfa12ad37d7af1092ae736f3a6cd0e37bc7810596" + +[[package]] +name = "subtle" +version = "2.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "13c2bddecc57b384dee18652358fb23172facb8a2c51ccc10d74c157bdea3292" + [[package]] name = "syn" version = "2.0.119" @@ -330,6 +1004,26 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "sync_wrapper" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0bf256ce5efdfa370213c1dabab5935a12e49f2c58d15e9eac2870d3b4f27263" +dependencies = [ + "futures-core", +] + +[[package]] +name = "synstructure" +version = "0.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "901704edd0dfe137f1987838ee4f259e4e063c31371bdb423f7ae38ec6f77f02" +dependencies = [ + "proc-macro2", + "quote", + "syn 3.0.10", +] + [[package]] name = "tempfile" version = "3.27.0" @@ -337,30 +1031,225 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "32497e9a4c7b38532efcdebeef879707aa9f794296a4f0244f6f69e9bc8574bd" dependencies = [ "fastrand", - "getrandom", + "getrandom 0.4.3", "once_cell", "rustix", - "windows-sys", + "windows-sys 0.61.2", ] +[[package]] +name = "thiserror" +version = "2.0.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09e52cb86a36cede5cb101bf8908837b3e4c6e5e59fe7fd85c23fb56200d189e" +dependencies = [ + "thiserror-impl", +] + +[[package]] +name = "thiserror-impl" +version = "2.0.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fe5197923287db20a58125f0bc85c062f7f2c892de97b18c356f9efb14b28524" +dependencies = [ + "proc-macro2", + "quote", + "syn 3.0.10", +] + +[[package]] +name = "tinystr" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "abc840c238154d58f9e86b2792261edfde565a17696e1cda1a449de27979801a" +dependencies = [ + "displaydoc", + "zerovec", +] + +[[package]] +name = "tinyvec" +version = "1.13.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fd3ca314f692efd6c868f8408f53fe444634a845f96c028b97d35f6a1f79f0ee" + +[[package]] +name = "tokio" +version = "1.54.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b52fd3255258d26fac7264ab5a76b53c13367136dc011d3d6ad4f8ed070396a3" +dependencies = [ + "bytes", + "libc", + "mio", + "pin-project-lite", + "socket2", + "windows-sys 0.61.2", +] + +[[package]] +name = "tokio-rustls" +version = "0.26.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c9cc2678c2cdd569ef8215e2afd7954ada2ae20b4fdd2c5fe6139a3b02d105db" +dependencies = [ + "rustls", + "tokio", +] + +[[package]] +name = "tower" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ebe5ef63511595f1344e2d5cfa636d973292adc0eec1f0ad45fae9f0851ab1d4" +dependencies = [ + "futures-core", + "futures-util", + "pin-project-lite", + "sync_wrapper", + "tokio", + "tower-layer", + "tower-service", +] + +[[package]] +name = "tower-http" +version = "0.6.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4cfcf7e2740e6fc6d4d688b4ef00650406bb94adf4731e43c096c3a19fe40840" +dependencies = [ + "bitflags", + "bytes", + "futures-util", + "http", + "http-body", + "pin-project-lite", + "tower", + "tower-layer", + "tower-service", + "url", +] + +[[package]] +name = "tower-layer" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "121c2a6cda46980bb0fcd1647ffaf6cd3fc79a013de288782836f6df9c48780e" + +[[package]] +name = "tower-service" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8df9b6e13f2d32c91b9bd719c00d1958837bc7dec474d94952798cc8e69eeec3" + +[[package]] +name = "tracing" +version = "0.1.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "63e71662fa4b2a2c3a26f570f037eb95bb1f85397f3cd8076caed2f026a6d100" +dependencies = [ + "pin-project-lite", + "tracing-core", +] + +[[package]] +name = "tracing-core" +version = "0.1.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db97caf9d906fbde555dd62fa95ddba9eecfd14cb388e4f491a66d74cd5fb79a" +dependencies = [ + "once_cell", +] + +[[package]] +name = "try-lock" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" + +[[package]] +name = "typenum" +version = "1.20.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6f5e870be6c3b371b77fe0ee0bafb859fa4964b4404c27de1d380043c4dda20" + [[package]] name = "unicode-ident" version = "1.0.27" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a2c754d6c33795a1c324727428e5a7dedb5b06195f9890bdbcba760d3e246563" +[[package]] +name = "untrusted" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ecb6da28b8a351d773b68d5825ac39017e680750f980f3a1a85cd8dd28a47c1" + +[[package]] +name = "url" +version = "2.5.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f00cd2407bb42c0ef17be88d4cf020f5cceffd121665bac9b8b9493a369b3b1a" +dependencies = [ + "form_urlencoded", + "idna", + "percent-encoding", + "serde", +] + +[[package]] +name = "utf8_iter" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "af3bd9d3e571c26fcce9d033b87ea5ab061b8d2ffe9b7a5675d810d68f03edf0" +dependencies = [ + "utf_types", +] + +[[package]] +name = "utf_types" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3a3b425286980a367278453f3b6d28cdcb134b574e5a35824a6ff5eebad50bb6" + [[package]] name = "vcpkg" version = "0.2.15" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" +[[package]] +name = "venue-probe" +version = "0.1.0" +dependencies = [ + "anyhow", + "reqwest", + "serde", + "serde_json", + "sha1", +] + [[package]] name = "version_check" version = "0.9.5" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" +[[package]] +name = "want" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec4cdd0dd910afe868b7ef477227d8d538b46b3075031afee8a9f2acb0a2ed0b" +dependencies = [ + "try-lock", +] + +[[package]] +name = "wasi" +version = "0.11.1+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ccf3ec651a847eb01de73ccad15eb7d99f80485de043efb2f370cd654f4ea44b" + [[package]] name = "wasm-bindgen" version = "0.2.129" @@ -374,6 +1263,17 @@ dependencies = [ "wasm-bindgen-shared", ] +[[package]] +name = "wasm-bindgen-futures" +version = "0.4.79" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3cbab34de2d982e9b48e18d216d04c4a6f641066ff19ffb699980f591ee3610e" +dependencies = [ + "js-sys", + "tokio", + "wasm-bindgen", +] + [[package]] name = "wasm-bindgen-macro" version = "0.2.129" @@ -406,12 +1306,50 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "web-sys" +version = "0.3.106" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "88261b9deccee56594c11a3460c462c41f58d148598fe70ad77070126a68aba4" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "web-time" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a6580f308b1fad9207618087a65c04e7a10bc77e02c8e84e9b00dd4b12fa0bb" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "webpki-roots" +version = "1.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7265c9301c16a8711c992c2d8da90ee77ef54b1ed51482d6dfeb00dc756b1297" +dependencies = [ + "rustls-pki-types", +] + [[package]] name = "windows-link" version = "0.2.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5" +[[package]] +name = "windows-sys" +version = "0.52.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" +dependencies = [ + "windows-targets", +] + [[package]] name = "windows-sys" version = "0.61.2" @@ -421,6 +1359,99 @@ dependencies = [ "windows-link", ] +[[package]] +name = "windows-targets" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" +dependencies = [ + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_gnullvm", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" + +[[package]] +name = "windows_i686_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" + +[[package]] +name = "windows_i686_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" + +[[package]] +name = "windows_i686_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.52.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" + +[[package]] +name = "writeable" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3ad82d2a33cdc9674dc7465672f271e096168fcdbe0f799d9e6db8c5892679dc" + +[[package]] +name = "yoke" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "417ef3fcf6c300b7dbd25c85531a746931c02ad536f3cf4786ed1e88223340b3" +dependencies = [ + "stable_deref_trait", + "yoke-derive", + "zerofrom", +] + +[[package]] +name = "yoke-derive" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec8ebde2db3681e8c9980cc27822030e68752690ddfa9473e739aeb4dbde6d71" +dependencies = [ + "proc-macro2", + "quote", + "syn 3.0.10", + "synstructure", +] + [[package]] name = "zerocopy" version = "0.8.66" @@ -441,6 +1472,66 @@ dependencies = [ "syn 2.0.119", ] +[[package]] +name = "zerofrom" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ec05a11813ea801ff6d75110ad09cd0824ddba17dfe17128ea0d5f68e6c5272" +dependencies = [ + "zerofrom-derive", +] + +[[package]] +name = "zerofrom-derive" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f75b4683f6c7f45248d4d64056a24298c6281e0993356d7d1b4a1a962ef10d4a" +dependencies = [ + "proc-macro2", + "quote", + "syn 3.0.10", + "synstructure", +] + +[[package]] +name = "zeroize" +version = "1.9.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85ccff8a4805aba1eaa4cd4afcd49f7557dd2cf5fd79ffc37f8959466effc5aa" + +[[package]] +name = "zerotrie" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ea269c3bd32f0a32c321907a2ae912ba6f4649bb0fc764a15627e99a7095a3f" +dependencies = [ + "displaydoc", + "yoke", + "zerofrom", +] + +[[package]] +name = "zerovec" +version = "0.11.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f58a2799cfe9a1670c7ea8edbd52ef8edb93cb37a7f83bf31ba9e35d9dae6a40" +dependencies = [ + "yoke", + "zerofrom", + "zerovec-derive", +] + +[[package]] +name = "zerovec-derive" +version = "0.11.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3743ddbf47738d929cd1ae2e199d40d0162979dfe31aef8ae646d2bf00bf97a" +dependencies = [ + "proc-macro2", + "quote", + "syn 3.0.10", +] + [[package]] name = "zmij" version = "1.0.23" diff --git a/Cargo.toml b/Cargo.toml index 6ebf8b0..462bd01 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,5 +1,5 @@ [workspace] -members = ["crates/matching", "crates/exchange", "crates/cli"] +members = ["crates/matching", "crates/exchange", "crates/cli", "crates/venue-probe"] resolver = "2" [workspace.package] diff --git a/crates/venue-probe/Cargo.toml b/crates/venue-probe/Cargo.toml new file mode 100644 index 0000000..0fce7bf --- /dev/null +++ b/crates/venue-probe/Cargo.toml @@ -0,0 +1,11 @@ +[package] +name = "venue-probe" +version.workspace = true +edition.workspace = true + +[dependencies] +anyhow.workspace = true +serde_json.workspace = true +reqwest = { version = "0.12", default-features = false, features = ["blocking", "rustls-tls", "json"] } +serde.workspace = true +sha1 = "0.10" diff --git a/crates/venue-probe/README.md b/crates/venue-probe/README.md new file mode 100644 index 0000000..1342f6d --- /dev/null +++ b/crates/venue-probe/README.md @@ -0,0 +1,125 @@ +# venue-probe + +探针匿名读取生产目录及盘口。成功选定合约后每个场所输出一行 JSON,其中最优价格用每美元一百万微单位表示,数量保留场所返回的十进制字符串。Polymarket 依目录顺序返回两个资产的独立报价与快照标识;两次 GET 可能处于不同时间。Kalshi 返回一个 ticker 下 YES、NO 各自的买一和隐含卖一,卖量等于对侧买量。空盘一侧返回 null。目录请求失败时详情写入 stderr。已取得目录时,盘口失败写入该场所的 JSON,任一场所失败会使进程以非零状态退出。 + +```sh +cargo run --locked -p venue-probe +``` + +```mermaid +flowchart LR + main["src/main.rs"] -->|依次调用两个只读探针| impls["src/probes.rs"] + main -->|重放 Gamma 市场| catalog["src/catalog.rs"] + impls -->|识别持仓协议及两套 ID| catalog + main -->|指定资产取样或离线重放| audit["src/book_audit.rs"] + audit -->|精确比较价格| books + impls -.->|回归用例| fixtures["fixtures/gamma-559651.json · kalshi-combo.json"] + impls -->|可选买卖报价对照| check["src/price_check.rs"] + check -->|精确价格与市场标识| books + impls -->|目录标识、盘口校验和最优价| books["src/books.rs"] +``` + +```mermaid +sequenceDiagram + participant P as venue-probe + participant G as Polymarket Gamma + participant C as Polymarket CLOB + participant K as Kalshi + P->>G: 查询开放市场 + G-->>P: 返回版本、negRisk 和两套结果标识 + P->>P: 保留各结果的 token ID 和 position ID,按版本选择盘口 ID + P->>P: CTF 按 negRisk 识别适配器,V2 从位置 ID 解出 31 字节条件并标注 Router + loop 按目录顺序读取两个结果 + P->>C: 按 CTF token ID 或 V2 position ID 查询 + alt 读取成功 + C-->>P: condition、资产 ID、买卖盘 + P->>P: 检查返回标识并提取最优价格与数量 + opt --compare-prices + P->>C: 对同一资产分别查询 BUY 和 SELL + C-->>P: 返回报价或 HTTP 错误 + P->>C: 再次读取该资产盘口 + P->>P: 检查前后哈希、买一与卖一,再判断方向 + end + else 读取失败 + P->>P: 为该资产记录错误,继续读取另一个结果 + end + end + P->>K: 查询开放市场 + K-->>P: 返回 ticker、事件及组合盘每一条腿的方向 + P->>K: 按 ticker 查询订单簿 + alt 盘口读取并解析成功 + K-->>P: YES 和 NO 买盘 + P->>P: 按 1 减去对侧买价计算各自卖一 + else 请求或解析失败 + P->>P: 保留目录合约并记录 book_error + end +``` + +本次工作站用 curl 向官方端点执行匿名 GET。Polymarket Gamma 目录与 CLOB 时钟端点均在取得 HTTP 状态前连接重置;Kalshi 生产目录、备用生产状态端点与 Demo 状态端点均超时。此次没有取得实时盘口,Rust 探针按项目约定暂未编译运行。接口依据见 [Polymarket 市场目录](https://docs.polymarket.com/api-reference/markets/list-markets) 与 [Kalshi 盘口文档](https://docs.kalshi.com/getting_started/orderbook_responses)。 + +复查中,工作站分别向 Gamma `/markets?active=true&closed=false&limit=5` 与 Kalshi 生产 `/markets?status=open&limit=5` 发起匿名 GET,连接超时设为 6 秒。两次均返回 curl 28、HTTP 000,未建立 TCP 连接。目录未返回任何资产,因此本次没有由目录驱动的生产盘口回执。两家场所的可达性仍未验证。 + +官方文档把 V2 position ID 与 CTF token ID 都作为 CLOB 的交易标识,Gamma 原始字段分别为 positionIds 和 clobTokenIds。回归用例覆盖两种版本、错配、空盘和小数数量。Kalshi 示例中,NO 买价 0.5005 与数量 1.25 对应 YES 卖价 0.4995、卖量 1.25。协议与精度依据见 [Polymarket 订单簿接口](https://docs.polymarket.com/market-data/prices-order-books.md) 和 [Kalshi 订单簿结构](https://docs.kalshi.com/getting_started/orderbook_responses.md)。 + +## 核对生产买卖报价 + +`venue-probe --compare-prices` 在常规输出上增加每个结果的 price_check。它把报价响应、HTTP 状态、前后盘口和哈希放在同一条记录中。前后盘口稳定时,BUY 与买一、SELL 与卖一一致就标为 resting_side。缺失买或卖的一侧分别按生产样本的 0 或 1 对照;前后两侧均明确为空且报价为 0 和 1 时标为 empty_book_defaults,缺失深度字段的样本保持待定。 + +[市场 559651 的目录字段摘录](fixtures/gamma-559651.json)来自公开 Gamma JSON 的网页读取,记录自身的更新时间为 2026-12-02 21:08:08 UTC。该 v1 市场同时返回两套 ID,盘口请求使用 clobTokenIds。目录买一为 0.012、卖一为 0.013、最小价格步长为 0.001。测试以这些真实目录值构造模拟的 CLOB 响应;本次工作站直连 Gamma 超时,网页读取该资产的 CLOB book 和 price 也未取得响应。目录观测与模拟样例均不能确认线上 BUY 和 SELL 返回了什么。[Gamma 公开市场目录](https://gamma-api.polymarket.com/markets?limit=1) + +## 核对单个盘口的档位顺序和哈希 + +`venue-probe --inspect-book TOKEN` 只请求一次指定资产的官方 `GET /book`。输出含 URL、HTTP 状态、收到的完整 JSON 对象以及核对结果。保存该行后,`venue-probe --replay-book TOKEN FILE` 可以离线重新核对,也可以直接读取原始盘口 JSON。命令成功表示核对过程正常结束,是否与本地盘口规则一致由 `supports_local_snapshot` 单独报告。 + +```mermaid +sequenceDiagram + participant U as 调用者 + participant P as venue-probe + participant C as Polymarket CLOB + alt 线上取样 + U->>P: inspect-book TOKEN + P->>C: GET /book?token_id=TOKEN + C-->>P: 单个时间戳的盘口与哈希 + else 离线重放 + U->>P: replay-book TOKEN FILE + end + P->>P: 校验资产 ID,检查两侧全部相邻价位 + P->>P: 保留档位与十进制字符串顺序,按 SDK 重算 SHA-1 + P-->>U: 首尾价、档位数、顺序、收到和计算的哈希 +``` + +两侧各有至少两个严格有序的不同价位、最优价均在末尾且哈希一致时,`supports_local_snapshot` 才为 true。空盘与单档记为 `insufficient_levels`。重复价格或非单调价格记为 `non_monotonic_or_repeated`。固定版 SDK 的哈希测试向量恰好买侧最优在末尾、卖侧最优在开头;重放它能核对序列化与分类,但无法判定生产端排序。仓库样例把测试期望的哈希填入原向量的空 hash 字段。[样例](fixtures/sdk-book.json) · [官方 SDK 哈希测试](https://github.com/Polymarket/py-clob-client-v2/blob/9c7c9e89cbbc11528daae90dc66ef65c9380cbdf/tests/test_utilities.py) · [官方序列化顺序](https://github.com/Polymarket/py-clob-client-v2/blob/9c7c9e89cbbc11528daae90dc66ef65c9380cbdf/py_clob_client_v2/utilities.py) + +单资产取样会记录请求资产及本机完成观测的时间 `observed_at_ms`(Unix 毫秒)。连接在响应前失败时,`http_status` 为 null;收到响应但 JSON 解码失败时保留 HTTP 状态。两类失败均写出一行带 `audit_error` 的 JSON 并以非零状态退出。重放已保存的观测要求 HTTP 状态为 2xx。成功取样中的盘口时间戳仍来自场所。 + + +## 从生产目录追到独立盘口 + +2026-12-03 的网页读取取得了两个官方生产目录。Polymarket 市场 559651 的两个结果分别有独立的 CLOB 资产 ID。Kalshi 通过其支持的生产域名返回了一个标记为 binary 的合约,其 mve_selected_legs 包含 30 条腿,每条都有 event_ticker、market_ticker 和 side。连接器在 catalog 字段保留这份清单和 mve_collection_ticker,盘口请求仍使用组合盘自身的 ticker。本次两个场所的盘口请求均未取得可解析的生产响应。[Gamma 目录](https://gamma-api.polymarket.com/markets?limit=1) · [Kalshi 目录](https://api.elections.kalshi.com/trade-api/v2/markets?limit=1) · [Kalshi 官方生产地址](https://docs.kalshi.com/getting_started/api_environments) · [Kalshi 样例字段摘录](fixtures/kalshi-combo.json) + +`orderbooks_complete` 表示该场所的所有目标盘口均已读取且通过结构检查。有效空盘口的买卖价为 null。读取失败的盘口带 `book_error` 并省略报价字段。Polymarket 单侧请求失败时,另一资产的读取仍继续。Kalshi 目录中的 binary 说明兑付有两种结果,一个二元合约仍可依赖多条腿;组合盘与任一成分的可成交量应分别计量。 + +## 识别交易与持仓合约 + +`venue-probe --replay-market FILE` 从一条原始 Gamma 市场对象生成与实时探针相同的目录字段。该命令仅读本地文件。每个结果保留标签、原顺序、`clob_token_id`、`position_id` 和实际用于盘口请求的 `asset_id`。Gamma 的 `condition_id` 单独保留。对于 V2,两项 Position ID 的高 31 字节必须相同,低字节依次为 0 和 1;探针将高位按原字节宽度导出为 `position_condition_id`。当缺少版本时,兼容旧目录按 CTF token 读取盘口,持仓操作目标留空。版本明确为 v1 但缺少 negRisk 时,同样保留盘口标识,操作目标留空。输出中的目标是合约名称。[官方市场标识](https://docs.polymarket.com/market-data/market-details) · [官方持仓操作](https://docs.polymarket.com/trading/positions/manage) + +| 重放文件 | 盘口字段 | 预期持仓结果 | 证据来源 | +|---|---|---|---| +| `fixtures/gamma-559651.json` | clobTokenIds | ConditionalTokens、CtfCollateralAdapter。两侧另有 position ID | 官方目录返回的市场 559651,本轮复核 negRisk 为 false | +| `fixtures/gamma-v2-docs.json` | positionIds | PositionManager、Router。两侧解得同一个 31 字节条件 | 取自官方 Market Details 页的两个 JSON 示例,未取得该市场同期生产盘口 | + +这两份记录验证了目录所指的标识与目标。生产盘口深度、钱包授权和链上操作仍须分别验证。[Gamma 目录](https://gamma-api.polymarket.com/markets?limit=1) · [官方市场样例](https://docs.polymarket.com/market-data/market-details) + + +## 生产盘口取样 + +2026-12-03 06:46 UTC 从官方接口匿名读取了下列快照。fixture 保存了请求 URL、HTTP 状态、响应日期和完整 JSON 响应体,可离线检查。该次取样只覆盖公开行情读取。 + +| 场所与样例 | 当时的观测 | +| --- | --- | +| [Polymarket 两个结果](fixtures/live-polymarket-books.json) | 美联储十二月降息 25 个基点市场。一个结果只有 82 档卖单,最低卖价 0.001。另一个结果只有 82 档买单,最高买价 0.999。两侧最优档均在数组末尾,两个响应的 SHA-1 都能用 SDK 字段顺序重算。 | +| [Kalshi 空盘口](fixtures/live-kalshi-book.json) | KXPLATINUMH-26DEC0303-T1377.49 返回 HTTP 200,yes_dollars 和 no_dollars 均为空数组。此时没有可从该快照读出的买一或卖一。 | + +2026-12-03 06:55 UTC 采集的[同侧报价快照](fixtures/live-side-prices.json)按请求保存前后盘口、报价、时间、方法及响应。双侧盘口最优价为 0.039 和 0.04。缺买盘的结果返回 BUY 字符串 0,缺卖盘的结果返回 SELL 字符串 1。批量 POST 返回相同字符串。文档列出的逗号分隔 GET 在这次生产取样返回 400。三个资产的前后盘口哈希各自一致。[官方单价接口](https://docs.polymarket.com/api-reference/market-data/get-market-price) + +[电竞盘双空样本](fixtures/live-empty-prices.json)保留前后盘口和两次价格请求。两个深度数组均为空,公开 BUY 返回 "0",SELL 返回 "1"。探针把该结果计为已验证的空盘报价,实际可成交数量仍为零。 diff --git a/crates/venue-probe/fixtures/gamma-559651.json b/crates/venue-probe/fixtures/gamma-559651.json new file mode 100644 index 0000000..e4adbfe --- /dev/null +++ b/crates/venue-probe/fixtures/gamma-559651.json @@ -0,0 +1,17 @@ +{ + "id": "559651", + "version": "v1", + "negRisk": false, + "updatedAt": "2026-12-02T21:08:08.650001Z", + "conditionId": "0xa467b14d51f01b957109d9cbb1d6c124fab2a089d52ed8f471d23c2812e743b7", + "outcomes": "[\"Yes\", \"No\"]", + "clobTokenIds": "[\"32338220190071351435772801779725302244575775216413325951443816017994629993401\", \"25659310674993675562345759665114759892400026242514633218387667107987341231962\"]", + "positionIds": ["895257453734540292493143124621755605615887197499956109032745153687078305792", "895257453734540292493143124621755605615887197499956109032745153687078305793"], + "enableOrderBook": true, + "acceptingOrders": true, + "bestBid": 0.012, + "bestAsk": 0.013, + "lastTradePrice": 0.012, + "orderPriceMinTickSize": 0.001, + "orderMinSize": 5 +} diff --git a/crates/venue-probe/fixtures/gamma-v2-docs.json b/crates/venue-probe/fixtures/gamma-v2-docs.json new file mode 100644 index 0000000..0af6a32 --- /dev/null +++ b/crates/venue-probe/fixtures/gamma-v2-docs.json @@ -0,0 +1,11 @@ +{ + "id": "703257", + "conditionId": "0x747dc809fb79e1b05be09c42d6179459a58de2ef3e40f02484a4e1260f741f75", + "version": "v2", + "outcomes": "[\"Yes\", \"No\"]", + "clobTokenIds": null, + "positionIds": [ + "651150819117105875331414918119047680898421632356043490229292782433651916800", + "651150819117105875331414918119047680898421632356043490229292782433651916801" + ] +} diff --git a/crates/venue-probe/fixtures/kalshi-combo.json b/crates/venue-probe/fixtures/kalshi-combo.json new file mode 100644 index 0000000..0402566 --- /dev/null +++ b/crates/venue-probe/fixtures/kalshi-combo.json @@ -0,0 +1,160 @@ +{ + "ticker": "KXMVECROSSCATEGORY-S2026K3MRPLJCSLQSASGN-76SEMBLAB", + "event_ticker": "KXMVECROSSCATEGORY-S2026K3MRPLJCSLQSASGN", + "status": "active", + "updated_time": "2026-12-02T19:26:58.602846Z", + "market_type": "binary", + "mve_collection_ticker": "KXMVECROSSCATEGORY-R", + "mve_selected_legs": [ + { + "event_ticker": "KXBRASILEIROTOTAL-26DEC02BAHATL", + "market_ticker": "KXBRASILEIROTOTAL-26DEC02BAHATL-1", + "side": "yes" + }, + { + "event_ticker": "KXBRASILEIROTOTAL-26DEC02CAPSPA", + "market_ticker": "KXBRASILEIROTOTAL-26DEC02CAPSPA-1", + "side": "yes" + }, + { + "event_ticker": "KXBRASILEIROTOTAL-26DEC02CRCOR", + "market_ticker": "KXBRASILEIROTOTAL-26DEC02CRCOR-1", + "side": "yes" + }, + { + "event_ticker": "KXBRASILEIROTOTAL-26DEC02CRUINT", + "market_ticker": "KXBRASILEIROTOTAL-26DEC02CRUINT-1", + "side": "yes" + }, + { + "event_ticker": "KXBRASILEIROTOTAL-26DEC02FLACHA", + "market_ticker": "KXBRASILEIROTOTAL-26DEC02FLACHA-2", + "side": "yes" + }, + { + "event_ticker": "KXBRASILEIROTOTAL-26DEC02GPAMIR", + "market_ticker": "KXBRASILEIROTOTAL-26DEC02GPAMIR-1", + "side": "yes" + }, + { + "event_ticker": "KXBRASILEIROTOTAL-26DEC02PALCFC", + "market_ticker": "KXBRASILEIROTOTAL-26DEC02PALCFC-1", + "side": "yes" + }, + { + "event_ticker": "KXBRASILEIROTOTAL-26DEC02RBBFLU", + "market_ticker": "KXBRASILEIROTOTAL-26DEC02RBBFLU-1", + "side": "yes" + }, + { + "event_ticker": "KXBRASILEIROTOTAL-26DEC02VDGVIT", + "market_ticker": "KXBRASILEIROTOTAL-26DEC02VDGVIT-1", + "side": "yes" + }, + { + "event_ticker": "KXCOPPAITALIAGAME-26DEC02COMCRE", + "market_ticker": "KXCOPPAITALIAGAME-26DEC02COMCRE-COM", + "side": "yes" + }, + { + "event_ticker": "KXDFBPOKALGAME-26DEC02BOCFCA", + "market_ticker": "KXDFBPOKALGAME-26DEC02BOCFCA-FCA", + "side": "yes" + }, + { + "event_ticker": "KXDFBPOKALGAME-26DEC02SGEBVB", + "market_ticker": "KXDFBPOKALGAME-26DEC02SGEBVB-SGE", + "side": "yes" + }, + { + "event_ticker": "KXDIMAYORGAME-26DEC02OCDIM", + "market_ticker": "KXDIMAYORGAME-26DEC02OCDIM-DIM", + "side": "no" + }, + { + "event_ticker": "KXDIMAYORTOTAL-26DEC02CANSFE", + "market_ticker": "KXDIMAYORTOTAL-26DEC02CANSFE-1", + "side": "yes" + }, + { + "event_ticker": "KXDIMAYORTOTAL-26DEC02OCDIM", + "market_ticker": "KXDIMAYORTOTAL-26DEC02OCDIM-1", + "side": "yes" + }, + { + "event_ticker": "KXEPLGAME-26DEC02LFCSUN", + "market_ticker": "KXEPLGAME-26DEC02LFCSUN-LFC", + "side": "yes" + }, + { + "event_ticker": "KXEPLTOTAL-26DEC02AVLEVE", + "market_ticker": "KXEPLTOTAL-26DEC02AVLEVE-1", + "side": "yes" + }, + { + "event_ticker": "KXEPLTOTAL-26DEC02BOUBRI", + "market_ticker": "KXEPLTOTAL-26DEC02BOUBRI-1", + "side": "yes" + }, + { + "event_ticker": "KXEPLTOTAL-26DEC02BREARS", + "market_ticker": "KXEPLTOTAL-26DEC02BREARS-1", + "side": "yes" + }, + { + "event_ticker": "KXEPLTOTAL-26DEC02CFCCRY", + "market_ticker": "KXEPLTOTAL-26DEC02CFCCRY-1", + "side": "yes" + }, + { + "event_ticker": "KXEPLTOTAL-26DEC02HULNFO", + "market_ticker": "KXEPLTOTAL-26DEC02HULNFO-1", + "side": "yes" + }, + { + "event_ticker": "KXEPLTOTAL-26DEC02MCILEE", + "market_ticker": "KXEPLTOTAL-26DEC02MCILEE-1", + "side": "yes" + }, + { + "event_ticker": "KXEPLTOTAL-26DEC02NEWMUN", + "market_ticker": "KXEPLTOTAL-26DEC02NEWMUN-1", + "side": "yes" + }, + { + "event_ticker": "KXLALIGAGAME-26DEC02BARATM", + "market_ticker": "KXLALIGAGAME-26DEC02BARATM-BAR", + "side": "yes" + }, + { + "event_ticker": "KXLALIGATOTAL-26DEC02BARATM", + "market_ticker": "KXLALIGATOTAL-26DEC02BARATM-2", + "side": "yes" + }, + { + "event_ticker": "KXSCOTTISHPREMGAME-26DEC02DUNCEL", + "market_ticker": "KXSCOTTISHPREMGAME-26DEC02DUNCEL-CEL", + "side": "yes" + }, + { + "event_ticker": "KXSCOTTISHPREMGAME-26DEC02FALMOT", + "market_ticker": "KXSCOTTISHPREMGAME-26DEC02FALMOT-TIE", + "side": "no" + }, + { + "event_ticker": "KXSCOTTISHPREMGAME-26DEC02HOMABE", + "market_ticker": "KXSCOTTISHPREMGAME-26DEC02HOMABE-ABE", + "side": "no" + }, + { + "event_ticker": "KXSCOTTISHPREMGAME-26DEC02JOHMIR", + "market_ticker": "KXSCOTTISHPREMGAME-26DEC02JOHMIR-TIE", + "side": "no" + }, + { + "event_ticker": "KXSCOTTISHPREMGAME-26DEC02RFCDUU", + "market_ticker": "KXSCOTTISHPREMGAME-26DEC02RFCDUU-RFC", + "side": "yes" + } + ] +} diff --git a/crates/venue-probe/fixtures/live-empty-prices.json b/crates/venue-probe/fixtures/live-empty-prices.json new file mode 100644 index 0000000..8bfe999 --- /dev/null +++ b/crates/venue-probe/fixtures/live-empty-prices.json @@ -0,0 +1,61 @@ +{ + "market": "cs2-bb3-lgc-2026-12-03-game1-round-total-27pt5", + "before": { + "method": "GET", + "url": "https://clob.polymarket.com/book?token_id=64069535502365350520464017439278800338614209934309608490621606944970108681676", + "payload": null, + "status": 200, + "date": "Thu, 03 Dec 2026 07:55:53 GMT", + "body": { + "market": "0xe5febd2f236a15ef7c1cc70a481e081bb64223d3e67aa3870677cccd72530853", + "asset_id": "64069535502365350520464017439278800338614209934309608490621606944970108681676", + "timestamp": "1796284481649", + "hash": "575e315a02461b9280427591ba1fe7e48b3b70ce", + "bids": [], + "asks": [], + "min_order_size": "5", + "tick_size": "0.01", + "neg_risk": false, + "last_trade_price": "" + } + }, + "buy": { + "method": "GET", + "url": "https://clob.polymarket.com/price?token_id=64069535502365350520464017439278800338614209934309608490621606944970108681676&side=BUY", + "payload": null, + "status": 200, + "date": "Thu, 03 Dec 2026 07:55:55 GMT", + "body": { + "price": "0" + } + }, + "sell": { + "method": "GET", + "url": "https://clob.polymarket.com/price?token_id=64069535502365350520464017439278800338614209934309608490621606944970108681676&side=SELL", + "payload": null, + "status": 200, + "date": "Thu, 03 Dec 2026 07:55:55 GMT", + "body": { + "price": "1" + } + }, + "after": { + "method": "GET", + "url": "https://clob.polymarket.com/book?token_id=64069535502365350520464017439278800338614209934309608490621606944970108681676", + "payload": null, + "status": 200, + "date": "Thu, 03 Dec 2026 07:55:56 GMT", + "body": { + "market": "0xe5febd2f236a15ef7c1cc70a481e081bb64223d3e67aa3870677cccd72530853", + "asset_id": "64069535502365350520464017439278800338614209934309608490621606944970108681676", + "timestamp": "1796284481649", + "hash": "575e315a02461b9280427591ba1fe7e48b3b70ce", + "bids": [], + "asks": [], + "min_order_size": "5", + "tick_size": "0.01", + "neg_risk": false, + "last_trade_price": "" + } + } +} diff --git a/crates/venue-probe/fixtures/live-kalshi-book.json b/crates/venue-probe/fixtures/live-kalshi-book.json new file mode 100644 index 0000000..4850c2d --- /dev/null +++ b/crates/venue-probe/fixtures/live-kalshi-book.json @@ -0,0 +1,17 @@ +{ + "venue": "kalshi", + "retrieved_at": "2026-12-03T06:46:06.218024+00:00", + "responses": [ + { + "url": "https://external-api.kalshi.com/trade-api/v2/markets/KXPLATINUMH-26DEC0303-T1377.49/orderbook?depth=5", + "status": 200, + "http_date": "Thu, 03 Dec 2026 06:46:06 GMT", + "body": { + "orderbook_fp": { + "no_dollars": [], + "yes_dollars": [] + } + } + } + ] +} diff --git a/crates/venue-probe/fixtures/live-polymarket-books.json b/crates/venue-probe/fixtures/live-polymarket-books.json new file mode 100644 index 0000000..7d37e99 --- /dev/null +++ b/crates/venue-probe/fixtures/live-polymarket-books.json @@ -0,0 +1,698 @@ +{ + "venue": "polymarket", + "retrieved_at": "2026-12-03T06:46:07.125735+00:00", + "responses": [ + { + "url": "https://clob.polymarket.com/book?token_id=77367448845023382525249480243608609306658725883285195065573683809293972009019", + "status": 200, + "http_date": "Thu, 03 Dec 2026 06:46:06 GMT", + "body": { + "market": "0xf17ad24eb4ad57926495b114149c765b9b95bc286eadc91cbbfa901ceb10d0b8", + "asset_id": "77367448845023382525249480243608609306658725883285195065573683809293972009019", + "timestamp": "1796280316915", + "hash": "019ed79339d95dcaeaefa222db1474502202a87c", + "bids": [], + "asks": [ + { + "price": "0.999", + "size": "21016611" + }, + { + "price": "0.998", + "size": "67500" + }, + { + "price": "0.997", + "size": "13583.32" + }, + { + "price": "0.996", + "size": "1750" + }, + { + "price": "0.995", + "size": "1400" + }, + { + "price": "0.994", + "size": "19166.66" + }, + { + "price": "0.993", + "size": "999.99" + }, + { + "price": "0.992", + "size": "875" + }, + { + "price": "0.991", + "size": "777.77" + }, + { + "price": "0.99", + "size": "4503.92" + }, + { + "price": "0.989", + "size": "66129.54" + }, + { + "price": "0.988", + "size": "1216.66" + }, + { + "price": "0.98", + "size": "500" + }, + { + "price": "0.97", + "size": "734.07" + }, + { + "price": "0.969", + "size": "1000" + }, + { + "price": "0.95", + "size": "245.41" + }, + { + "price": "0.939", + "size": "5000" + }, + { + "price": "0.925", + "size": "3000" + }, + { + "price": "0.91", + "size": "5" + }, + { + "price": "0.904", + "size": "4720" + }, + { + "price": "0.9", + "size": "10" + }, + { + "price": "0.899", + "size": "250" + }, + { + "price": "0.89", + "size": "90.9" + }, + { + "price": "0.888", + "size": "1999.99" + }, + { + "price": "0.855", + "size": "4810" + }, + { + "price": "0.799", + "size": "250" + }, + { + "price": "0.798", + "size": "9000" + }, + { + "price": "0.74", + "size": "38.46" + }, + { + "price": "0.54", + "size": "21.73" + }, + { + "price": "0.47", + "size": "15790.08" + }, + { + "price": "0.469", + "size": "5000" + }, + { + "price": "0.43", + "size": "10032.89" + }, + { + "price": "0.39", + "size": "7500" + }, + { + "price": "0.388", + "size": "1500" + }, + { + "price": "0.38", + "size": "1000" + }, + { + "price": "0.35", + "size": "8666.66" + }, + { + "price": "0.288", + "size": "500" + }, + { + "price": "0.28", + "size": "1005" + }, + { + "price": "0.279", + "size": "4810" + }, + { + "price": "0.22", + "size": "6" + }, + { + "price": "0.21", + "size": "10" + }, + { + "price": "0.2", + "size": "50" + }, + { + "price": "0.18", + "size": "1020.25" + }, + { + "price": "0.179", + "size": "365" + }, + { + "price": "0.175", + "size": "150" + }, + { + "price": "0.17", + "size": "1000" + }, + { + "price": "0.14", + "size": "5" + }, + { + "price": "0.139", + "size": "400" + }, + { + "price": "0.1", + "size": "500" + }, + { + "price": "0.098", + "size": "1000" + }, + { + "price": "0.097", + "size": "980" + }, + { + "price": "0.096", + "size": "100" + }, + { + "price": "0.08", + "size": "150" + }, + { + "price": "0.079", + "size": "100" + }, + { + "price": "0.039", + "size": "499.98" + }, + { + "price": "0.038", + "size": "500" + }, + { + "price": "0.034", + "size": "53" + }, + { + "price": "0.03", + "size": "50" + }, + { + "price": "0.028", + "size": "1000" + }, + { + "price": "0.025", + "size": "20" + }, + { + "price": "0.024", + "size": "1248" + }, + { + "price": "0.023", + "size": "97" + }, + { + "price": "0.022", + "size": "1292.31" + }, + { + "price": "0.021", + "size": "74" + }, + { + "price": "0.02", + "size": "50" + }, + { + "price": "0.019", + "size": "550" + }, + { + "price": "0.018", + "size": "1495" + }, + { + "price": "0.015", + "size": "400" + }, + { + "price": "0.014", + "size": "857" + }, + { + "price": "0.013", + "size": "1087" + }, + { + "price": "0.012", + "size": "45" + }, + { + "price": "0.011", + "size": "749.29" + }, + { + "price": "0.01", + "size": "1203" + }, + { + "price": "0.009", + "size": "11287.36" + }, + { + "price": "0.008", + "size": "4830" + }, + { + "price": "0.007", + "size": "1349.03" + }, + { + "price": "0.006", + "size": "850" + }, + { + "price": "0.005", + "size": "1273" + }, + { + "price": "0.004", + "size": "931.25" + }, + { + "price": "0.003", + "size": "287998.71" + }, + { + "price": "0.002", + "size": "525378.36" + }, + { + "price": "0.001", + "size": "391881.71" + } + ], + "min_order_size": "5", + "tick_size": "0.001", + "neg_risk": true, + "last_trade_price": "0.001" + } + }, + { + "url": "https://clob.polymarket.com/book?token_id=23677896678650147625251750117853328843601853501710889530409633595389256242910", + "status": 200, + "http_date": "Thu, 03 Dec 2026 06:46:06 GMT", + "body": { + "market": "0xf17ad24eb4ad57926495b114149c765b9b95bc286eadc91cbbfa901ceb10d0b8", + "asset_id": "23677896678650147625251750117853328843601853501710889530409633595389256242910", + "timestamp": "1796280316915", + "hash": "cf7a136a82ea7081f8a77202b0d8d57d6e9d7042", + "bids": [ + { + "price": "0.001", + "size": "21016611" + }, + { + "price": "0.002", + "size": "67500" + }, + { + "price": "0.003", + "size": "13583.32" + }, + { + "price": "0.004", + "size": "1750" + }, + { + "price": "0.005", + "size": "1400" + }, + { + "price": "0.006", + "size": "19166.66" + }, + { + "price": "0.007", + "size": "999.99" + }, + { + "price": "0.008", + "size": "875" + }, + { + "price": "0.009", + "size": "777.77" + }, + { + "price": "0.01", + "size": "4503.92" + }, + { + "price": "0.011", + "size": "66129.54" + }, + { + "price": "0.012", + "size": "1216.66" + }, + { + "price": "0.02", + "size": "500" + }, + { + "price": "0.03", + "size": "734.07" + }, + { + "price": "0.031", + "size": "1000" + }, + { + "price": "0.05", + "size": "245.41" + }, + { + "price": "0.061", + "size": "5000" + }, + { + "price": "0.075", + "size": "3000" + }, + { + "price": "0.09", + "size": "5" + }, + { + "price": "0.096", + "size": "4720" + }, + { + "price": "0.1", + "size": "10" + }, + { + "price": "0.101", + "size": "250" + }, + { + "price": "0.11", + "size": "90.9" + }, + { + "price": "0.112", + "size": "1999.99" + }, + { + "price": "0.145", + "size": "4810" + }, + { + "price": "0.201", + "size": "250" + }, + { + "price": "0.202", + "size": "9000" + }, + { + "price": "0.26", + "size": "38.46" + }, + { + "price": "0.46", + "size": "21.73" + }, + { + "price": "0.53", + "size": "15790.08" + }, + { + "price": "0.531", + "size": "5000" + }, + { + "price": "0.57", + "size": "10032.89" + }, + { + "price": "0.61", + "size": "7500" + }, + { + "price": "0.612", + "size": "1500" + }, + { + "price": "0.62", + "size": "1000" + }, + { + "price": "0.65", + "size": "8666.66" + }, + { + "price": "0.712", + "size": "500" + }, + { + "price": "0.72", + "size": "1005" + }, + { + "price": "0.721", + "size": "4810" + }, + { + "price": "0.78", + "size": "6" + }, + { + "price": "0.79", + "size": "10" + }, + { + "price": "0.8", + "size": "50" + }, + { + "price": "0.82", + "size": "1020.25" + }, + { + "price": "0.821", + "size": "365" + }, + { + "price": "0.825", + "size": "150" + }, + { + "price": "0.83", + "size": "1000" + }, + { + "price": "0.86", + "size": "5" + }, + { + "price": "0.861", + "size": "400" + }, + { + "price": "0.9", + "size": "500" + }, + { + "price": "0.902", + "size": "1000" + }, + { + "price": "0.903", + "size": "980" + }, + { + "price": "0.904", + "size": "100" + }, + { + "price": "0.92", + "size": "150" + }, + { + "price": "0.921", + "size": "100" + }, + { + "price": "0.961", + "size": "499.98" + }, + { + "price": "0.962", + "size": "500" + }, + { + "price": "0.966", + "size": "53" + }, + { + "price": "0.97", + "size": "50" + }, + { + "price": "0.972", + "size": "1000" + }, + { + "price": "0.975", + "size": "20" + }, + { + "price": "0.976", + "size": "1248" + }, + { + "price": "0.977", + "size": "97" + }, + { + "price": "0.978", + "size": "1292.31" + }, + { + "price": "0.979", + "size": "74" + }, + { + "price": "0.98", + "size": "50" + }, + { + "price": "0.981", + "size": "550" + }, + { + "price": "0.982", + "size": "1495" + }, + { + "price": "0.985", + "size": "400" + }, + { + "price": "0.986", + "size": "857" + }, + { + "price": "0.987", + "size": "1087" + }, + { + "price": "0.988", + "size": "45" + }, + { + "price": "0.989", + "size": "749.29" + }, + { + "price": "0.99", + "size": "1203" + }, + { + "price": "0.991", + "size": "11287.36" + }, + { + "price": "0.992", + "size": "4830" + }, + { + "price": "0.993", + "size": "1349.03" + }, + { + "price": "0.994", + "size": "850" + }, + { + "price": "0.995", + "size": "1273" + }, + { + "price": "0.996", + "size": "931.25" + }, + { + "price": "0.997", + "size": "287998.71" + }, + { + "price": "0.998", + "size": "525378.36" + }, + { + "price": "0.999", + "size": "391881.71" + } + ], + "asks": [], + "min_order_size": "5", + "tick_size": "0.001", + "neg_risk": true, + "last_trade_price": "0.001" + } + } + ] +} diff --git a/crates/venue-probe/fixtures/live-side-prices.json b/crates/venue-probe/fixtures/live-side-prices.json new file mode 100644 index 0000000..2a1536b --- /dev/null +++ b/crates/venue-probe/fixtures/live-side-prices.json @@ -0,0 +1,36 @@ +{ + "observed_at": "2026-12-03T06:55:29.016395+00:00", + "cases": [ + { + "asset": "35090254409399344650860070211816464534198960801264823587796928404808383727584", + "before": {"url":"https://clob.polymarket.com/book?token_id=35090254409399344650860070211816464534198960801264823587796928404808383727584","method":"GET","request_body":null,"http_status":200,"date":"Thu, 03 Dec 2026 06:55:26 GMT","body":{"market":"0xa5f8a44504de30fa36fff2406b2b27b3d15476ed50448e4fc3ead4861d8a5e3e","asset_id":"35090254409399344650860070211816464534198960801264823587796928404808383727584","timestamp":"1796280925073","hash":"ccc94bb833ccfc40f3d602ac0ac8494b53d4f94c","bids":[{"price":"0.001","size":"530176"},{"price":"0.002","size":"298884"},{"price":"0.003","size":"145640.58"},{"price":"0.004","size":"80238.08"},{"price":"0.005","size":"260455"},{"price":"0.006","size":"60829.44"},{"price":"0.007","size":"31843.05"},{"price":"0.008","size":"23598.75"},{"price":"0.009","size":"25083.29"},{"price":"0.01","size":"40665"},{"price":"0.011","size":"9116.3"},{"price":"0.012","size":"11175.3"},{"price":"0.013","size":"3086.9"},{"price":"0.014","size":"6360.1"},{"price":"0.015","size":"3336.6"},{"price":"0.016","size":"17510"},{"price":"0.017","size":"28475.01"},{"price":"0.018","size":"2622.14"},{"price":"0.019","size":"11079.61"},{"price":"0.02","size":"18709.61"},{"price":"0.021","size":"7399.99"},{"price":"0.022","size":"5242"},{"price":"0.023","size":"1549.09"},{"price":"0.024","size":"1175"},{"price":"0.025","size":"10"},{"price":"0.026","size":"239.99"},{"price":"0.027","size":"5200.01"},{"price":"0.028","size":"1990.19"},{"price":"0.029","size":"3634"},{"price":"0.03","size":"204.86"},{"price":"0.031","size":"10615.83"},{"price":"0.032","size":"15463.1"},{"price":"0.033","size":"6700.1"},{"price":"0.034","size":"6426.2"},{"price":"0.035","size":"6165.09"},{"price":"0.036","size":"1564.5"},{"price":"0.037","size":"1673.08"},{"price":"0.038","size":"910.1"},{"price":"0.039","size":"400.64"}],"asks":[{"price":"0.999","size":"21010368.05"},{"price":"0.998","size":"6163"},{"price":"0.997","size":"63164.32"},{"price":"0.996","size":"1750"},{"price":"0.995","size":"1400"},{"price":"0.994","size":"1166.66"},{"price":"0.993","size":"999.99"},{"price":"0.992","size":"875"},{"price":"0.991","size":"777.77"},{"price":"0.99","size":"5133.91"},{"price":"0.989","size":"64840.54"},{"price":"0.988","size":"416.66"},{"price":"0.98","size":"500"},{"price":"0.97","size":"734.07"},{"price":"0.969","size":"20665"},{"price":"0.968","size":"800"},{"price":"0.954","size":"7140.12"},{"price":"0.95","size":"245.41"},{"price":"0.939","size":"9240"},{"price":"0.91","size":"10"},{"price":"0.904","size":"5020"},{"price":"0.899","size":"174.44"},{"price":"0.89","size":"5930.9"},{"price":"0.855","size":"4530"},{"price":"0.849","size":"9000"},{"price":"0.799","size":"171.62"},{"price":"0.79","size":"1000"},{"price":"0.766","size":"5"},{"price":"0.749","size":"5000"},{"price":"0.74","size":"38.46"},{"price":"0.7","size":"2259.22"},{"price":"0.68","size":"399.99"},{"price":"0.65","size":"1500"},{"price":"0.649","size":"1000"},{"price":"0.54","size":"21.73"},{"price":"0.5","size":"288.93"},{"price":"0.49","size":"1113.31"},{"price":"0.472","size":"946.96"},{"price":"0.47","size":"11790.09"},{"price":"0.45","size":"1500"},{"price":"0.449","size":"300"},{"price":"0.43","size":"10032.89"},{"price":"0.429","size":"1000"},{"price":"0.4","size":"37.25"},{"price":"0.39","size":"7500"},{"price":"0.36","size":"5"},{"price":"0.32","size":"96.74"},{"price":"0.319","size":"1000"},{"price":"0.318","size":"4700"},{"price":"0.317","size":"439"},{"price":"0.3","size":"16.03"},{"price":"0.28","size":"5"},{"price":"0.252","size":"5000"},{"price":"0.25","size":"5"},{"price":"0.227","size":"1000"},{"price":"0.222","size":"5000"},{"price":"0.22","size":"155"},{"price":"0.193","size":"33.56"},{"price":"0.192","size":"5000"},{"price":"0.19","size":"5"},{"price":"0.18","size":"5.61"},{"price":"0.17","size":"5"},{"price":"0.162","size":"5000"},{"price":"0.16","size":"1500"},{"price":"0.15","size":"10"},{"price":"0.149","size":"400"},{"price":"0.14","size":"105"},{"price":"0.135","size":"10000"},{"price":"0.134","size":"2050"},{"price":"0.132","size":"5000"},{"price":"0.13","size":"5"},{"price":"0.121","size":"5000"},{"price":"0.12","size":"690.38"},{"price":"0.112","size":"5000"},{"price":"0.11","size":"405"},{"price":"0.102","size":"5000"},{"price":"0.1","size":"5"},{"price":"0.099","size":"5299"},{"price":"0.091","size":"5000"},{"price":"0.09","size":"10105"},{"price":"0.087","size":"13500"},{"price":"0.081","size":"5000"},{"price":"0.08","size":"10640.37"},{"price":"0.075","size":"12000"},{"price":"0.072","size":"53650.57"},{"price":"0.071","size":"5100"},{"price":"0.07","size":"19005"},{"price":"0.069","size":"5447.35"},{"price":"0.068","size":"50"},{"price":"0.067","size":"50"},{"price":"0.061","size":"10000"},{"price":"0.06","size":"6652.56"},{"price":"0.059","size":"386"},{"price":"0.057","size":"200"},{"price":"0.056","size":"1574.09"},{"price":"0.055","size":"8732"},{"price":"0.054","size":"200"},{"price":"0.053","size":"349.49"},{"price":"0.052","size":"2156.4"},{"price":"0.051","size":"362.01"},{"price":"0.05","size":"22712.68"},{"price":"0.049","size":"1103"},{"price":"0.048","size":"1063"},{"price":"0.047","size":"2549"},{"price":"0.045","size":"354"},{"price":"0.044","size":"499.03"},{"price":"0.043","size":"57"},{"price":"0.041","size":"544"},{"price":"0.04","size":"1800"}],"min_order_size":"5","tick_size":"0.001","neg_risk":true,"last_trade_price":"0.039"}}, + "buy": {"url":"https://clob.polymarket.com/price?token_id=35090254409399344650860070211816464534198960801264823587796928404808383727584&side=BUY","method":"GET","request_body":null,"http_status":200,"date":"Thu, 03 Dec 2026 06:55:27 GMT","body":{"price":"0.039"}}, + "sell": {"url":"https://clob.polymarket.com/price?token_id=35090254409399344650860070211816464534198960801264823587796928404808383727584&side=SELL","method":"GET","request_body":null,"http_status":200,"date":"Thu, 03 Dec 2026 06:55:27 GMT","body":{"price":"0.04"}}, + "batch_get": {"url":"https://clob.polymarket.com/prices?token_ids=35090254409399344650860070211816464534198960801264823587796928404808383727584&sides=BUY","method":"GET","request_body":null,"http_status":400,"date":"Thu, 03 Dec 2026 06:55:26 GMT","body":{"error":"Invalid payload"}}, + "batch_post": {"url":"https://clob.polymarket.com/prices","method":"POST","request_body":[{"token_id":"35090254409399344650860070211816464534198960801264823587796928404808383727584","side":"BUY"},{"token_id":"35090254409399344650860070211816464534198960801264823587796928404808383727584","side":"SELL"}],"http_status":200,"date":"Thu, 03 Dec 2026 06:55:27 GMT","body":{"35090254409399344650860070211816464534198960801264823587796928404808383727584":{"BUY":"0.039","SELL":"0.04"}}}, + "buy_only_post": {"url":"https://clob.polymarket.com/prices","method":"POST","request_body":[{"token_id":"35090254409399344650860070211816464534198960801264823587796928404808383727584","side":"BUY"}],"http_status":200,"date":"Thu, 03 Dec 2026 06:55:26 GMT","body":{"35090254409399344650860070211816464534198960801264823587796928404808383727584":{"BUY":"0.039"}}}, + "after": {"url":"https://clob.polymarket.com/book?token_id=35090254409399344650860070211816464534198960801264823587796928404808383727584","method":"GET","request_body":null,"http_status":200,"date":"Thu, 03 Dec 2026 06:55:27 GMT","body":{"market":"0xa5f8a44504de30fa36fff2406b2b27b3d15476ed50448e4fc3ead4861d8a5e3e","asset_id":"35090254409399344650860070211816464534198960801264823587796928404808383727584","timestamp":"1796280925073","hash":"ccc94bb833ccfc40f3d602ac0ac8494b53d4f94c","bids":[{"price":"0.001","size":"530176"},{"price":"0.002","size":"298884"},{"price":"0.003","size":"145640.58"},{"price":"0.004","size":"80238.08"},{"price":"0.005","size":"260455"},{"price":"0.006","size":"60829.44"},{"price":"0.007","size":"31843.05"},{"price":"0.008","size":"23598.75"},{"price":"0.009","size":"25083.29"},{"price":"0.01","size":"40665"},{"price":"0.011","size":"9116.3"},{"price":"0.012","size":"11175.3"},{"price":"0.013","size":"3086.9"},{"price":"0.014","size":"6360.1"},{"price":"0.015","size":"3336.6"},{"price":"0.016","size":"17510"},{"price":"0.017","size":"28475.01"},{"price":"0.018","size":"2622.14"},{"price":"0.019","size":"11079.61"},{"price":"0.02","size":"18709.61"},{"price":"0.021","size":"7399.99"},{"price":"0.022","size":"5242"},{"price":"0.023","size":"1549.09"},{"price":"0.024","size":"1175"},{"price":"0.025","size":"10"},{"price":"0.026","size":"239.99"},{"price":"0.027","size":"5200.01"},{"price":"0.028","size":"1990.19"},{"price":"0.029","size":"3634"},{"price":"0.03","size":"204.86"},{"price":"0.031","size":"10615.83"},{"price":"0.032","size":"15463.1"},{"price":"0.033","size":"6700.1"},{"price":"0.034","size":"6426.2"},{"price":"0.035","size":"6165.09"},{"price":"0.036","size":"1564.5"},{"price":"0.037","size":"1673.08"},{"price":"0.038","size":"910.1"},{"price":"0.039","size":"400.64"}],"asks":[{"price":"0.999","size":"21010368.05"},{"price":"0.998","size":"6163"},{"price":"0.997","size":"63164.32"},{"price":"0.996","size":"1750"},{"price":"0.995","size":"1400"},{"price":"0.994","size":"1166.66"},{"price":"0.993","size":"999.99"},{"price":"0.992","size":"875"},{"price":"0.991","size":"777.77"},{"price":"0.99","size":"5133.91"},{"price":"0.989","size":"64840.54"},{"price":"0.988","size":"416.66"},{"price":"0.98","size":"500"},{"price":"0.97","size":"734.07"},{"price":"0.969","size":"20665"},{"price":"0.968","size":"800"},{"price":"0.954","size":"7140.12"},{"price":"0.95","size":"245.41"},{"price":"0.939","size":"9240"},{"price":"0.91","size":"10"},{"price":"0.904","size":"5020"},{"price":"0.899","size":"174.44"},{"price":"0.89","size":"5930.9"},{"price":"0.855","size":"4530"},{"price":"0.849","size":"9000"},{"price":"0.799","size":"171.62"},{"price":"0.79","size":"1000"},{"price":"0.766","size":"5"},{"price":"0.749","size":"5000"},{"price":"0.74","size":"38.46"},{"price":"0.7","size":"2259.22"},{"price":"0.68","size":"399.99"},{"price":"0.65","size":"1500"},{"price":"0.649","size":"1000"},{"price":"0.54","size":"21.73"},{"price":"0.5","size":"288.93"},{"price":"0.49","size":"1113.31"},{"price":"0.472","size":"946.96"},{"price":"0.47","size":"11790.09"},{"price":"0.45","size":"1500"},{"price":"0.449","size":"300"},{"price":"0.43","size":"10032.89"},{"price":"0.429","size":"1000"},{"price":"0.4","size":"37.25"},{"price":"0.39","size":"7500"},{"price":"0.36","size":"5"},{"price":"0.32","size":"96.74"},{"price":"0.319","size":"1000"},{"price":"0.318","size":"4700"},{"price":"0.317","size":"439"},{"price":"0.3","size":"16.03"},{"price":"0.28","size":"5"},{"price":"0.252","size":"5000"},{"price":"0.25","size":"5"},{"price":"0.227","size":"1000"},{"price":"0.222","size":"5000"},{"price":"0.22","size":"155"},{"price":"0.193","size":"33.56"},{"price":"0.192","size":"5000"},{"price":"0.19","size":"5"},{"price":"0.18","size":"5.61"},{"price":"0.17","size":"5"},{"price":"0.162","size":"5000"},{"price":"0.16","size":"1500"},{"price":"0.15","size":"10"},{"price":"0.149","size":"400"},{"price":"0.14","size":"105"},{"price":"0.135","size":"10000"},{"price":"0.134","size":"2050"},{"price":"0.132","size":"5000"},{"price":"0.13","size":"5"},{"price":"0.121","size":"5000"},{"price":"0.12","size":"690.38"},{"price":"0.112","size":"5000"},{"price":"0.11","size":"405"},{"price":"0.102","size":"5000"},{"price":"0.1","size":"5"},{"price":"0.099","size":"5299"},{"price":"0.091","size":"5000"},{"price":"0.09","size":"10105"},{"price":"0.087","size":"13500"},{"price":"0.081","size":"5000"},{"price":"0.08","size":"10640.37"},{"price":"0.075","size":"12000"},{"price":"0.072","size":"53650.57"},{"price":"0.071","size":"5100"},{"price":"0.07","size":"19005"},{"price":"0.069","size":"5447.35"},{"price":"0.068","size":"50"},{"price":"0.067","size":"50"},{"price":"0.061","size":"10000"},{"price":"0.06","size":"6652.56"},{"price":"0.059","size":"386"},{"price":"0.057","size":"200"},{"price":"0.056","size":"1574.09"},{"price":"0.055","size":"8732"},{"price":"0.054","size":"200"},{"price":"0.053","size":"349.49"},{"price":"0.052","size":"2156.4"},{"price":"0.051","size":"362.01"},{"price":"0.05","size":"22712.68"},{"price":"0.049","size":"1103"},{"price":"0.048","size":"1063"},{"price":"0.047","size":"2549"},{"price":"0.045","size":"354"},{"price":"0.044","size":"499.03"},{"price":"0.043","size":"57"},{"price":"0.041","size":"544"},{"price":"0.04","size":"1800"}],"min_order_size":"5","tick_size":"0.001","neg_risk":true,"last_trade_price":"0.039"}} + }, + { + "asset": "77367448845023382525249480243608609306658725883285195065573683809293972009019", + "before": {"url":"https://clob.polymarket.com/book?token_id=77367448845023382525249480243608609306658725883285195065573683809293972009019","method":"GET","request_body":null,"http_status":200,"date":"Thu, 03 Dec 2026 06:55:26 GMT","body":{"market":"0xf17ad24eb4ad57926495b114149c765b9b95bc286eadc91cbbfa901ceb10d0b8","asset_id":"77367448845023382525249480243608609306658725883285195065573683809293972009019","timestamp":"1796280925613","hash":"a67af39df6dc79a0742b42cb3d8f5d0974ff4f4e","bids":[],"asks":[{"price":"0.999","size":"21016611"},{"price":"0.998","size":"67500"},{"price":"0.997","size":"13583.32"},{"price":"0.996","size":"1750"},{"price":"0.995","size":"1400"},{"price":"0.994","size":"19166.66"},{"price":"0.993","size":"999.99"},{"price":"0.992","size":"875"},{"price":"0.991","size":"777.77"},{"price":"0.99","size":"4503.92"},{"price":"0.989","size":"66129.54"},{"price":"0.988","size":"1216.66"},{"price":"0.98","size":"500"},{"price":"0.97","size":"734.07"},{"price":"0.969","size":"1000"},{"price":"0.95","size":"245.41"},{"price":"0.939","size":"5000"},{"price":"0.925","size":"3000"},{"price":"0.91","size":"5"},{"price":"0.904","size":"4720"},{"price":"0.9","size":"10"},{"price":"0.899","size":"250"},{"price":"0.89","size":"90.9"},{"price":"0.888","size":"1999.99"},{"price":"0.855","size":"4810"},{"price":"0.799","size":"250"},{"price":"0.798","size":"9000"},{"price":"0.74","size":"38.46"},{"price":"0.54","size":"21.73"},{"price":"0.47","size":"15790.08"},{"price":"0.469","size":"5000"},{"price":"0.43","size":"10032.89"},{"price":"0.39","size":"7500"},{"price":"0.388","size":"1500"},{"price":"0.38","size":"1000"},{"price":"0.35","size":"8666.66"},{"price":"0.288","size":"500"},{"price":"0.28","size":"1005"},{"price":"0.279","size":"4810"},{"price":"0.22","size":"6"},{"price":"0.21","size":"10"},{"price":"0.2","size":"50"},{"price":"0.18","size":"1020.25"},{"price":"0.179","size":"365"},{"price":"0.175","size":"150"},{"price":"0.17","size":"1000"},{"price":"0.14","size":"5"},{"price":"0.139","size":"400"},{"price":"0.1","size":"500"},{"price":"0.098","size":"1000"},{"price":"0.097","size":"980"},{"price":"0.096","size":"100"},{"price":"0.08","size":"150"},{"price":"0.079","size":"100"},{"price":"0.039","size":"499.98"},{"price":"0.038","size":"500"},{"price":"0.034","size":"53"},{"price":"0.03","size":"50"},{"price":"0.028","size":"1000"},{"price":"0.025","size":"20"},{"price":"0.024","size":"1248"},{"price":"0.023","size":"97"},{"price":"0.022","size":"1242.31"},{"price":"0.021","size":"124"},{"price":"0.02","size":"75.5"},{"price":"0.019","size":"550"},{"price":"0.018","size":"1495"},{"price":"0.015","size":"20"},{"price":"0.013","size":"152"},{"price":"0.011","size":"1275.29"},{"price":"0.01","size":"1203"},{"price":"0.009","size":"11287.36"},{"price":"0.008","size":"4830"},{"price":"0.007","size":"850"},{"price":"0.006","size":"964.03"},{"price":"0.005","size":"1273"},{"price":"0.004","size":"931.25"},{"price":"0.003","size":"159721.66"},{"price":"0.002","size":"525378.36"},{"price":"0.001","size":"504658.76"}],"min_order_size":"5","tick_size":"0.001","neg_risk":true,"last_trade_price":"0.001"}}, + "buy": {"url":"https://clob.polymarket.com/price?token_id=77367448845023382525249480243608609306658725883285195065573683809293972009019&side=BUY","method":"GET","request_body":null,"http_status":200,"date":"Thu, 03 Dec 2026 06:55:26 GMT","body":{"price":"0"}}, + "sell": {"url":"https://clob.polymarket.com/price?token_id=77367448845023382525249480243608609306658725883285195065573683809293972009019&side=SELL","method":"GET","request_body":null,"http_status":200,"date":"Thu, 03 Dec 2026 06:55:27 GMT","body":{"price":"0.001"}}, + "batch_get": {"url":"https://clob.polymarket.com/prices?token_ids=77367448845023382525249480243608609306658725883285195065573683809293972009019&sides=BUY","method":"GET","request_body":null,"http_status":400,"date":"Thu, 03 Dec 2026 06:55:26 GMT","body":{"error":"Invalid payload"}}, + "batch_post": {"url":"https://clob.polymarket.com/prices","method":"POST","request_body":[{"token_id":"77367448845023382525249480243608609306658725883285195065573683809293972009019","side":"BUY"},{"token_id":"77367448845023382525249480243608609306658725883285195065573683809293972009019","side":"SELL"}],"http_status":200,"date":"Thu, 03 Dec 2026 06:55:26 GMT","body":{"77367448845023382525249480243608609306658725883285195065573683809293972009019":{"BUY":"0","SELL":"0.001"}}}, + "buy_only_post": {"url":"https://clob.polymarket.com/prices","method":"POST","request_body":[{"token_id":"77367448845023382525249480243608609306658725883285195065573683809293972009019","side":"BUY"}],"http_status":200,"date":"Thu, 03 Dec 2026 06:55:26 GMT","body":{"77367448845023382525249480243608609306658725883285195065573683809293972009019":{"BUY":"0"}}}, + "after": {"url":"https://clob.polymarket.com/book?token_id=77367448845023382525249480243608609306658725883285195065573683809293972009019","method":"GET","request_body":null,"http_status":200,"date":"Thu, 03 Dec 2026 06:55:27 GMT","body":{"market":"0xf17ad24eb4ad57926495b114149c765b9b95bc286eadc91cbbfa901ceb10d0b8","asset_id":"77367448845023382525249480243608609306658725883285195065573683809293972009019","timestamp":"1796280925613","hash":"a67af39df6dc79a0742b42cb3d8f5d0974ff4f4e","bids":[],"asks":[{"price":"0.999","size":"21016611"},{"price":"0.998","size":"67500"},{"price":"0.997","size":"13583.32"},{"price":"0.996","size":"1750"},{"price":"0.995","size":"1400"},{"price":"0.994","size":"19166.66"},{"price":"0.993","size":"999.99"},{"price":"0.992","size":"875"},{"price":"0.991","size":"777.77"},{"price":"0.99","size":"4503.92"},{"price":"0.989","size":"66129.54"},{"price":"0.988","size":"1216.66"},{"price":"0.98","size":"500"},{"price":"0.97","size":"734.07"},{"price":"0.969","size":"1000"},{"price":"0.95","size":"245.41"},{"price":"0.939","size":"5000"},{"price":"0.925","size":"3000"},{"price":"0.91","size":"5"},{"price":"0.904","size":"4720"},{"price":"0.9","size":"10"},{"price":"0.899","size":"250"},{"price":"0.89","size":"90.9"},{"price":"0.888","size":"1999.99"},{"price":"0.855","size":"4810"},{"price":"0.799","size":"250"},{"price":"0.798","size":"9000"},{"price":"0.74","size":"38.46"},{"price":"0.54","size":"21.73"},{"price":"0.47","size":"15790.08"},{"price":"0.469","size":"5000"},{"price":"0.43","size":"10032.89"},{"price":"0.39","size":"7500"},{"price":"0.388","size":"1500"},{"price":"0.38","size":"1000"},{"price":"0.35","size":"8666.66"},{"price":"0.288","size":"500"},{"price":"0.28","size":"1005"},{"price":"0.279","size":"4810"},{"price":"0.22","size":"6"},{"price":"0.21","size":"10"},{"price":"0.2","size":"50"},{"price":"0.18","size":"1020.25"},{"price":"0.179","size":"365"},{"price":"0.175","size":"150"},{"price":"0.17","size":"1000"},{"price":"0.14","size":"5"},{"price":"0.139","size":"400"},{"price":"0.1","size":"500"},{"price":"0.098","size":"1000"},{"price":"0.097","size":"980"},{"price":"0.096","size":"100"},{"price":"0.08","size":"150"},{"price":"0.079","size":"100"},{"price":"0.039","size":"499.98"},{"price":"0.038","size":"500"},{"price":"0.034","size":"53"},{"price":"0.03","size":"50"},{"price":"0.028","size":"1000"},{"price":"0.025","size":"20"},{"price":"0.024","size":"1248"},{"price":"0.023","size":"97"},{"price":"0.022","size":"1242.31"},{"price":"0.021","size":"124"},{"price":"0.02","size":"75.5"},{"price":"0.019","size":"550"},{"price":"0.018","size":"1495"},{"price":"0.015","size":"20"},{"price":"0.013","size":"152"},{"price":"0.011","size":"1275.29"},{"price":"0.01","size":"1203"},{"price":"0.009","size":"11287.36"},{"price":"0.008","size":"4830"},{"price":"0.007","size":"850"},{"price":"0.006","size":"964.03"},{"price":"0.005","size":"1273"},{"price":"0.004","size":"931.25"},{"price":"0.003","size":"159721.66"},{"price":"0.002","size":"525378.36"},{"price":"0.001","size":"504658.76"}],"min_order_size":"5","tick_size":"0.001","neg_risk":true,"last_trade_price":"0.001"}} + }, + { + "asset": "23677896678650147625251750117853328843601853501710889530409633595389256242910", + "before": {"url":"https://clob.polymarket.com/book?token_id=23677896678650147625251750117853328843601853501710889530409633595389256242910","method":"GET","request_body":null,"http_status":200,"date":"Thu, 03 Dec 2026 06:55:26 GMT","body":{"market":"0xf17ad24eb4ad57926495b114149c765b9b95bc286eadc91cbbfa901ceb10d0b8","asset_id":"23677896678650147625251750117853328843601853501710889530409633595389256242910","timestamp":"1796280925613","hash":"ff8de0eb190fa2676e57159ccd31d4dc7d7130da","bids":[{"price":"0.001","size":"21016611"},{"price":"0.002","size":"67500"},{"price":"0.003","size":"13583.32"},{"price":"0.004","size":"1750"},{"price":"0.005","size":"1400"},{"price":"0.006","size":"19166.66"},{"price":"0.007","size":"999.99"},{"price":"0.008","size":"875"},{"price":"0.009","size":"777.77"},{"price":"0.01","size":"4503.92"},{"price":"0.011","size":"66129.54"},{"price":"0.012","size":"1216.66"},{"price":"0.02","size":"500"},{"price":"0.03","size":"734.07"},{"price":"0.031","size":"1000"},{"price":"0.05","size":"245.41"},{"price":"0.061","size":"5000"},{"price":"0.075","size":"3000"},{"price":"0.09","size":"5"},{"price":"0.096","size":"4720"},{"price":"0.1","size":"10"},{"price":"0.101","size":"250"},{"price":"0.11","size":"90.9"},{"price":"0.112","size":"1999.99"},{"price":"0.145","size":"4810"},{"price":"0.201","size":"250"},{"price":"0.202","size":"9000"},{"price":"0.26","size":"38.46"},{"price":"0.46","size":"21.73"},{"price":"0.53","size":"15790.08"},{"price":"0.531","size":"5000"},{"price":"0.57","size":"10032.89"},{"price":"0.61","size":"7500"},{"price":"0.612","size":"1500"},{"price":"0.62","size":"1000"},{"price":"0.65","size":"8666.66"},{"price":"0.712","size":"500"},{"price":"0.72","size":"1005"},{"price":"0.721","size":"4810"},{"price":"0.78","size":"6"},{"price":"0.79","size":"10"},{"price":"0.8","size":"50"},{"price":"0.82","size":"1020.25"},{"price":"0.821","size":"365"},{"price":"0.825","size":"150"},{"price":"0.83","size":"1000"},{"price":"0.86","size":"5"},{"price":"0.861","size":"400"},{"price":"0.9","size":"500"},{"price":"0.902","size":"1000"},{"price":"0.903","size":"980"},{"price":"0.904","size":"100"},{"price":"0.92","size":"150"},{"price":"0.921","size":"100"},{"price":"0.961","size":"499.98"},{"price":"0.962","size":"500"},{"price":"0.966","size":"53"},{"price":"0.97","size":"50"},{"price":"0.972","size":"1000"},{"price":"0.975","size":"20"},{"price":"0.976","size":"1248"},{"price":"0.977","size":"97"},{"price":"0.978","size":"1242.31"},{"price":"0.979","size":"124"},{"price":"0.98","size":"75.5"},{"price":"0.981","size":"550"},{"price":"0.982","size":"1495"},{"price":"0.985","size":"20"},{"price":"0.987","size":"152"},{"price":"0.989","size":"1275.29"},{"price":"0.99","size":"1203"},{"price":"0.991","size":"11287.36"},{"price":"0.992","size":"4830"},{"price":"0.993","size":"850"},{"price":"0.994","size":"964.03"},{"price":"0.995","size":"1273"},{"price":"0.996","size":"931.25"},{"price":"0.997","size":"159721.66"},{"price":"0.998","size":"525378.36"},{"price":"0.999","size":"504658.76"}],"asks":[],"min_order_size":"5","tick_size":"0.001","neg_risk":true,"last_trade_price":"0.001"}}, + "buy": {"url":"https://clob.polymarket.com/price?token_id=23677896678650147625251750117853328843601853501710889530409633595389256242910&side=BUY","method":"GET","request_body":null,"http_status":200,"date":"Thu, 03 Dec 2026 06:55:26 GMT","body":{"price":"0.999"}}, + "sell": {"url":"https://clob.polymarket.com/price?token_id=23677896678650147625251750117853328843601853501710889530409633595389256242910&side=SELL","method":"GET","request_body":null,"http_status":200,"date":"Thu, 03 Dec 2026 06:55:26 GMT","body":{"price":"1"}}, + "batch_get": {"url":"https://clob.polymarket.com/prices?token_ids=23677896678650147625251750117853328843601853501710889530409633595389256242910&sides=BUY","method":"GET","request_body":null,"http_status":400,"date":"Thu, 03 Dec 2026 06:55:26 GMT","body":{"error":"Invalid payload"}}, + "batch_post": {"url":"https://clob.polymarket.com/prices","method":"POST","request_body":[{"token_id":"23677896678650147625251750117853328843601853501710889530409633595389256242910","side":"BUY"},{"token_id":"23677896678650147625251750117853328843601853501710889530409633595389256242910","side":"SELL"}],"http_status":200,"date":"Thu, 03 Dec 2026 06:55:26 GMT","body":{"23677896678650147625251750117853328843601853501710889530409633595389256242910":{"BUY":"0.999","SELL":"1"}}}, + "buy_only_post": {"url":"https://clob.polymarket.com/prices","method":"POST","request_body":[{"token_id":"23677896678650147625251750117853328843601853501710889530409633595389256242910","side":"BUY"}],"http_status":200,"date":"Thu, 03 Dec 2026 06:55:26 GMT","body":{"23677896678650147625251750117853328843601853501710889530409633595389256242910":{"BUY":"0.999"}}}, + "after": {"url":"https://clob.polymarket.com/book?token_id=23677896678650147625251750117853328843601853501710889530409633595389256242910","method":"GET","request_body":null,"http_status":200,"date":"Thu, 03 Dec 2026 06:55:27 GMT","body":{"market":"0xf17ad24eb4ad57926495b114149c765b9b95bc286eadc91cbbfa901ceb10d0b8","asset_id":"23677896678650147625251750117853328843601853501710889530409633595389256242910","timestamp":"1796280925613","hash":"ff8de0eb190fa2676e57159ccd31d4dc7d7130da","bids":[{"price":"0.001","size":"21016611"},{"price":"0.002","size":"67500"},{"price":"0.003","size":"13583.32"},{"price":"0.004","size":"1750"},{"price":"0.005","size":"1400"},{"price":"0.006","size":"19166.66"},{"price":"0.007","size":"999.99"},{"price":"0.008","size":"875"},{"price":"0.009","size":"777.77"},{"price":"0.01","size":"4503.92"},{"price":"0.011","size":"66129.54"},{"price":"0.012","size":"1216.66"},{"price":"0.02","size":"500"},{"price":"0.03","size":"734.07"},{"price":"0.031","size":"1000"},{"price":"0.05","size":"245.41"},{"price":"0.061","size":"5000"},{"price":"0.075","size":"3000"},{"price":"0.09","size":"5"},{"price":"0.096","size":"4720"},{"price":"0.1","size":"10"},{"price":"0.101","size":"250"},{"price":"0.11","size":"90.9"},{"price":"0.112","size":"1999.99"},{"price":"0.145","size":"4810"},{"price":"0.201","size":"250"},{"price":"0.202","size":"9000"},{"price":"0.26","size":"38.46"},{"price":"0.46","size":"21.73"},{"price":"0.53","size":"15790.08"},{"price":"0.531","size":"5000"},{"price":"0.57","size":"10032.89"},{"price":"0.61","size":"7500"},{"price":"0.612","size":"1500"},{"price":"0.62","size":"1000"},{"price":"0.65","size":"8666.66"},{"price":"0.712","size":"500"},{"price":"0.72","size":"1005"},{"price":"0.721","size":"4810"},{"price":"0.78","size":"6"},{"price":"0.79","size":"10"},{"price":"0.8","size":"50"},{"price":"0.82","size":"1020.25"},{"price":"0.821","size":"365"},{"price":"0.825","size":"150"},{"price":"0.83","size":"1000"},{"price":"0.86","size":"5"},{"price":"0.861","size":"400"},{"price":"0.9","size":"500"},{"price":"0.902","size":"1000"},{"price":"0.903","size":"980"},{"price":"0.904","size":"100"},{"price":"0.92","size":"150"},{"price":"0.921","size":"100"},{"price":"0.961","size":"499.98"},{"price":"0.962","size":"500"},{"price":"0.966","size":"53"},{"price":"0.97","size":"50"},{"price":"0.972","size":"1000"},{"price":"0.975","size":"20"},{"price":"0.976","size":"1248"},{"price":"0.977","size":"97"},{"price":"0.978","size":"1242.31"},{"price":"0.979","size":"124"},{"price":"0.98","size":"75.5"},{"price":"0.981","size":"550"},{"price":"0.982","size":"1495"},{"price":"0.985","size":"20"},{"price":"0.987","size":"152"},{"price":"0.989","size":"1275.29"},{"price":"0.99","size":"1203"},{"price":"0.991","size":"11287.36"},{"price":"0.992","size":"4830"},{"price":"0.993","size":"850"},{"price":"0.994","size":"964.03"},{"price":"0.995","size":"1273"},{"price":"0.996","size":"931.25"},{"price":"0.997","size":"159721.66"},{"price":"0.998","size":"525378.36"},{"price":"0.999","size":"504658.76"}],"asks":[],"min_order_size":"5","tick_size":"0.001","neg_risk":true,"last_trade_price":"0.001"}} + } + ], + "other": [{"url":"https://clob.polymarket.com/prices","method":"POST","request_body":[{"token_id":"35090254409399344650860070211816464534198960801264823587796928404808383727584","side":"BUY"},{"token_id":"123","side":"BUY"}],"http_status":200,"date":"Thu, 03 Dec 2026 06:55:28 GMT","body":{"35090254409399344650860070211816464534198960801264823587796928404808383727584":{"BUY":"0.039"}}},{"url":"https://clob.polymarket.com/price?token_id=123&side=BUY","method":"GET","request_body":null,"http_status":404,"date":"Thu, 03 Dec 2026 06:55:28 GMT","body":{"error":"No orderbook exists for the requested token id"}},{"url":"https://clob.polymarket.com/prices","method":"POST","request_body":[{"token_id":"35090254409399344650860070211816464534198960801264823587796928404808383727584"}],"http_status":200,"date":"Thu, 03 Dec 2026 06:55:29 GMT","body":{"35090254409399344650860070211816464534198960801264823587796928404808383727584":{"SELL":"0.04"}}}] +} diff --git a/crates/venue-probe/fixtures/sdk-book.json b/crates/venue-probe/fixtures/sdk-book.json new file mode 100644 index 0000000..82a90a4 --- /dev/null +++ b/crates/venue-probe/fixtures/sdk-book.json @@ -0,0 +1,30 @@ +{ + "market": "0xaabbcc", + "asset_id": "100", + "bids": [ + { + "price": "0.3", + "size": "100" + }, + { + "price": "0.4", + "size": "100" + } + ], + "asks": [ + { + "price": "0.6", + "size": "100" + }, + { + "price": "0.7", + "size": "100" + } + ], + "hash": "0458ea5755c9f73d64a14636fa5c36ed460ec394", + "timestamp": "123456789", + "min_order_size": "100", + "neg_risk": false, + "tick_size": "0.01", + "last_trade_price": "0.5" +} diff --git a/crates/venue-probe/src/book_audit.rs b/crates/venue-probe/src/book_audit.rs new file mode 100644 index 0000000..97bbb1f --- /dev/null +++ b/crates/venue-probe/src/book_audit.rs @@ -0,0 +1,109 @@ +use crate::books::price; +use anyhow::{ensure, Context, Result}; +use serde::{Deserialize, Serialize}; +use serde_json::{json, Value}; +use sha1::{Digest, Sha1}; + +// Preserve decimal spellings and SDK field order independently of the JSON map implementation. +#[derive(Serialize, Deserialize)] +struct Snapshot { + market: String, + asset_id: String, + timestamp: String, + hash: String, + bids: Vec, + asks: Vec, + min_order_size: String, + tick_size: String, + neg_risk: bool, + last_trade_price: String, +} + +#[derive(Serialize, Deserialize)] +struct Level { + price: String, + size: String, +} + +fn side(levels: &[Level], is_bid: bool) -> Result { + let prices = levels + .iter() + .map(|l| price(&Value::String(l.price.clone()))) + .collect::>>()?; + let order = if prices.len() < 2 { + "insufficient_levels" + } else if prices.windows(2).all(|p| p[0] < p[1]) { + if is_bid { + "best_last" + } else { + "best_first" + } + } else if prices.windows(2).all(|p| p[0] > p[1]) { + if is_bid { + "best_first" + } else { + "best_last" + } + } else { + "non_monotonic_or_repeated" + }; + Ok( + json!({"levels":levels.len(),"first_price":levels.first().map(|l| &l.price), + "last_price":levels.last().map(|l| &l.price),"order":order}), + ) +} + +pub(crate) fn inspect(raw: &Value, token: &str) -> Result { + let mut book: Snapshot = + serde_json::from_value(raw.clone()).context("invalid snapshot fields")?; + ensure!( + book.asset_id == token, + "book asset differs from requested token" + ); + let bids = side(&book.bids, true)?; + let asks = side(&book.asks, false)?; + let received = std::mem::take(&mut book.hash); + let calculated = format!("{:x}", Sha1::digest(serde_json::to_vec(&book)?)); + let matches = !received.is_empty() && received == calculated; + Ok( + json!({"bids":bids,"asks":asks,"received_hash":received,"sdk_hash":calculated, + "hash_matches":matches,"supports_local_snapshot": + matches && bids["order"]=="best_last" && asks["order"]=="best_last"}), + ) +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn preserves_sdk_preimage_and_reports_each_side_independently() { + let mut raw: Value = + serde_json::from_str(include_str!("../fixtures/sdk-book.json")).unwrap(); + let audit = inspect(&raw, "100").unwrap(); + assert_eq!(audit["hash_matches"], true); + assert_eq!(audit["bids"]["order"], "best_last"); + assert_eq!(audit["asks"]["order"], "best_first"); + assert_eq!(audit["supports_local_snapshot"], false); + assert!(inspect(&raw, "101").is_err()); + raw["asks"].as_array_mut().unwrap().reverse(); + let changed = inspect(&raw, "100").unwrap(); + assert_eq!(changed["asks"]["order"], "best_last"); + assert_eq!(changed["hash_matches"], false); + raw["hash"] = changed["sdk_hash"].clone(); + assert_eq!( + inspect(&raw, "100").unwrap()["supports_local_snapshot"], + true + ); + raw["bids"][1]["price"] = json!("0.30"); + assert_eq!( + inspect(&raw, "100").unwrap()["bids"]["order"], + "non_monotonic_or_repeated" + ); + raw["asks"] = json!([]); + assert_eq!( + inspect(&raw, "100").unwrap()["asks"]["order"], + "insufficient_levels" + ); + } +} diff --git a/crates/venue-probe/src/books.rs b/crates/venue-probe/src/books.rs new file mode 100644 index 0000000..a0e7bf5 --- /dev/null +++ b/crates/venue-probe/src/books.rs @@ -0,0 +1,130 @@ +use anyhow::{ensure, Context, Result}; +use serde_json::{json, Value}; + +/// Prices fit in millionths of a dollar. Preserve size as the venue's exact +/// decimal string; the two venues accept different fractional share sizes. +fn decimal(value: &Value) -> Result<(&str, &str)> { + let raw = value.as_str().context("expected decimal string")?; + let (whole, frac) = raw.split_once('.').unwrap_or((raw, "")); + ensure!( + !whole.is_empty() + && whole.bytes().all(|b| b.is_ascii_digit()) + && !raw.ends_with('.') + && frac.bytes().all(|b| b.is_ascii_digit()), + "invalid decimal" + ); + Ok((whole, frac)) +} + +pub(crate) fn price(value: &Value) -> Result { + let (whole, frac) = decimal(value)?; + let frac = frac.trim_end_matches('0'); + ensure!(frac.len() <= 6, "price exceeds six decimal places"); + let units: u64 = whole.parse()?; + ensure!( + units == 0 || (units == 1 && frac.is_empty()), + "price outside [0,1]" + ); + let mut micros = 0; + for digit in frac.bytes() { + micros = micros * 10 + u64::from(digit - b'0'); + } + Ok(units * 1_000_000 + micros * 10_u64.pow(6 - frac.len() as u32)) +} + +fn best(levels: &Value, highest: bool, kalshi: bool) -> Result> { + let mut best: Option<(u64, &str)> = None; + for level in levels.as_array().context("missing depth array")? { + let (p, size) = if kalshi { + let pair = level.as_array().context("expected Kalshi level")?; + ensure!(pair.len() == 2, "invalid Kalshi level"); + (&pair[0], &pair[1]) + } else { + (&level["price"], &level["size"]) + }; + let p = price(p)?; + let (whole, frac) = decimal(size)?; + ensure!( + whole.bytes().chain(frac.bytes()).any(|b| b != b'0'), + "nonpositive resting size" + ); + if best.map_or( + true, + |(prior, _)| if highest { p > prior } else { p < prior }, + ) { + best = Some((p, size.as_str().context("expected size string")?)); + } + } + Ok(best) +} + +fn level(value: Option<(u64, &str)>) -> Value { + value + .map(|(p, s)| json!({"price_micros":p,"size":s})) + .unwrap_or(Value::Null) +} + +pub(crate) fn poly_book(market: &Value, asset: &str, book: &Value) -> Result { + let condition = market["conditionId"] + .as_str() + .filter(|s| !s.is_empty()) + .context("missing condition ID")?; + ensure!( + book["asset_id"].as_str() == Some(asset) && book["market"].as_str() == Some(condition), + "book differs from requested condition or asset" + ); + Ok( + json!({"asset_id":asset,"best_bid":level(best(&book["bids"],true,false)?),"best_ask":level(best(&book["asks"],false,false)?), + "venue_timestamp":book.get("timestamp"),"hash":book.get("hash")}), + ) +} + +pub(crate) fn kalshi_book(ticker: &str, book: &Value) -> Result { + let bids = &book["orderbook_fp"]; + let yes = best(&bids["yes_dollars"], true, true)?; + let no = best(&bids["no_dollars"], true, true)?; + let complement = |p: u64| 1_000_000 - p; + Ok(json!({"venue":"kalshi","ticker":ticker, + "yes":{"best_bid":level(yes),"best_ask":level(no.map(|(p,s)|(complement(p),s)))}, + "no":{"best_bid":level(no),"best_ask":level(yes.map(|(p,s)|(complement(p),s)))}})) +} + +#[cfg(test)] +mod tests { + use super::*; + #[test] + fn checks_book_identity_and_uses_exact_executable_levels() { + let m = json!({"conditionId":"condition"}); + let b = json!({"market":"condition","asset_id":"123","bids":[{"price":"0.08","size":"13.25"},{"price":"0.009","size":"7"}], + "asks":[{"price":"0.2","size":"3"},{"price":"0.085","size":"0.75"}]}); + let result = poly_book(&m, "123", &b).unwrap(); + assert_eq!( + result["best_bid"], + json!({"price_micros":80000,"size":"13.25"}) + ); + assert_eq!( + result["best_ask"], + json!({"price_micros":85000,"size":"0.75"}) + ); + assert!(poly_book(&m, "999", &b).is_err()); + assert!(poly_book(&json!({"conditionId":"other"}), "123", &b).is_err()); + let k=kalshi_book("abc",&json!({"orderbook_fp":{"yes_dollars":[["0.4200","13.00"]],"no_dollars":[["0.5005","1.25"]]}})).unwrap(); + assert_eq!( + k["yes"]["best_ask"], + json!({"price_micros":499500,"size":"1.25"}) + ); + assert_eq!( + k["no"]["best_ask"], + json!({"price_micros":580000,"size":"13.00"}) + ); + let empty = kalshi_book( + "abc", + &json!({"orderbook_fp":{"yes_dollars":[],"no_dollars":[]}}), + ) + .unwrap(); + assert!(empty["yes"]["best_ask"].is_null()); + for p in ["-0.1", "1.000001", "0.0000001", "NaN", "1."] { + assert!(price(&json!(p)).is_err()); + } + } +} diff --git a/crates/venue-probe/src/catalog.rs b/crates/venue-probe/src/catalog.rs new file mode 100644 index 0000000..9acac9f --- /dev/null +++ b/crates/venue-probe/src/catalog.rs @@ -0,0 +1,198 @@ +use anyhow::{ensure, Context, Result}; +use serde_json::{json, Value}; + +fn pair(value: &Value) -> Result<[String; 2]> { + Ok(match value.as_str() { + Some(s) => serde_json::from_str(s)?, + None => serde_json::from_value(value.clone())?, + }) +} + +// Polymarket serializes token IDs as decimal strings. Decode without f64 or u128 truncation. +fn uint256(raw: &str) -> Result<[u8; 32]> { + ensure!( + !raw.is_empty() && raw.len() <= 78 && raw.bytes().all(|b| b.is_ascii_digit()), + "invalid decimal token ID" + ); + let mut bytes = [0u8; 32]; + for digit in raw.bytes() { + let mut carry = u16::from(digit - b'0'); + for byte in bytes.iter_mut().rev() { + let n = u16::from(*byte) * 10 + carry; + *byte = n as u8; + carry = n >> 8; + } + ensure!(carry == 0, "token ID exceeds uint256"); + } + Ok(bytes) +} + +fn tokens(value: &Value) -> Result<[String; 2]> { + let ids = pair(value)?; + ensure!( + uint256(&ids[0])? != uint256(&ids[1])?, + "duplicate outcome identifiers" + ); + Ok(ids) +} + +fn position_condition(ids: &[String; 2]) -> Result { + let yes = uint256(&ids[0])?; + let no = uint256(&ids[1])?; + ensure!( + yes[..31] == no[..31] && yes[31] == 0 && no[31] == 1, + "position IDs must encode the same condition and YES/NO outcome indexes" + ); + use std::fmt::Write; + let mut condition = String::from("0x"); + for byte in &yes[..31] { + write!(condition, "{byte:02x}")?; + } + Ok(condition) +} + +pub(crate) struct Market { + pub assets: [String; 2], + pub report: Value, +} + +impl Market { + pub fn parse(m: &Value) -> Result { + let version = m + .get("version") + .filter(|v| !v.is_null()) + .map(|v| v.as_str().context("invalid market version")) + .transpose()?; + let v2 = match version { + Some("v2") => true, + Some("v1") | None => false, + _ => anyhow::bail!("unknown Polymarket market version"), + }; + let (key, aux) = if v2 { + ("positionIds", "clobTokenIds") + } else { + ("clobTokenIds", "positionIds") + }; + let assets = tokens(&m[key]).with_context(|| format!("invalid {key}"))?; + let condition = m["conditionId"] + .as_str() + .filter(|s| !s.is_empty()) + .context("missing condition ID")?; + let labels = (!m["outcomes"].is_null()) + .then(|| pair(&m["outcomes"])) + .transpose()?; + let neg_risk = m["negRisk"].as_bool(); + let target = match (version, neg_risk) { + (Some("v2"), _) => Some("Router"), + (Some("v1"), Some(true)) => Some("NegRiskCtfCollateralAdapter"), + (Some("v1"), Some(false)) => Some("CtfCollateralAdapter"), + _ => None, + }; + let position_condition_id = match version { + Some("v2") => Some(position_condition(&assets)?), + Some("v1") => Some(condition.to_owned()), + _ => None, + }; + let mut report = json!({"venue":"polymarket","market":m["id"],"condition_id":condition, + "version":version,"neg_risk":neg_risk,"book_id_field":key, + "position_ledger":version.map(|_| if v2 {"PositionManager"} else {"ConditionalTokens"}), + "position_target":target,"position_condition_id":position_condition_id}); + // An optional identifier family never prevents sampling valid books in the active family. + let alternate = if m[aux].is_null() { + None + } else { + match tokens(&m[aux]) { + Ok(ids) => Some(ids), + Err(e) => { + report["catalog_warning"] = json!(format!("invalid {aux}: {e}")); + None + } + } + }; + let (clob, positions) = if v2 { + (alternate.as_ref(), Some(&assets)) + } else { + (Some(&assets), alternate.as_ref()) + }; + report["outcomes"] = json!((0..2) + .map(|i| json!({"outcome_index":i,"asset_id":assets[i], + "label":labels.as_ref().map(|p| &p[i]),"clob_token_id":clob.map(|p| &p[i]), + "position_id":positions.map(|p| &p[i])})) + .collect::>()); + Ok(Self { assets, report }) + } +} + +#[cfg(test)] +mod tests { + use super::*; + + fn sample(raw: &str) -> Value { + serde_json::from_str(raw).unwrap() + } + + #[test] + fn live_ctf_catalog_keeps_both_id_families_and_selects_the_adapter() { + let mut m = sample(include_str!("../fixtures/gamma-559651.json")); + let parsed = Market::parse(&m).unwrap(); + let r = parsed.report; + assert_eq!(r["position_target"], "CtfCollateralAdapter"); + assert_eq!(r["position_condition_id"], m["conditionId"]); + assert_eq!(r["outcomes"][0]["position_id"], m["positionIds"][0]); + assert_eq!(r["outcomes"][0]["clob_token_id"], parsed.assets[0]); + assert_ne!( + r["outcomes"][0]["position_id"], + r["outcomes"][0]["asset_id"] + ); + m["negRisk"] = json!(true); + assert_eq!( + Market::parse(&m).unwrap().report["position_target"], + "NegRiskCtfCollateralAdapter" + ); + m["negRisk"] = Value::Null; + assert!(Market::parse(&m).unwrap().report["position_target"].is_null()); + m["positionIds"] = json!(["bad", "1"]); + let r = Market::parse(&m).unwrap().report; + assert!(r["catalog_warning"].is_string()); + assert!(r["outcomes"][0]["position_id"].is_null()); + m["version"] = Value::Null; + assert_eq!( + Market::parse(&m).unwrap().report["book_id_field"], + "clobTokenIds" + ); + } + + #[test] + fn documented_v2_pair_decodes_without_loss_and_selects_the_router() { + let mut m = sample(include_str!("../fixtures/gamma-v2-docs.json")); + let r = Market::parse(&m).unwrap().report; + assert_eq!(r["position_target"], "Router"); + assert_eq!( + r["position_condition_id"], + "0x017089ce3ba22aaa0a4cba8250b8c8e1eb0000000000000000000000000000" + ); + assert_eq!(r["outcomes"][1]["asset_id"], m["positionIds"][1]); + assert!(r["outcomes"][1]["clob_token_id"].is_null()); + m["positionIds"][1] = json!("257"); + assert!(Market::parse(&m).is_err()); + m["positionIds"] = json!(["257", "256"]); + assert!(Market::parse(&m).is_err()); + m["positionIds"] = Value::Null; + m["clobTokenIds"] = json!(["12", "13"]); + assert!(Market::parse(&m).is_err()); + m["version"] = json!("future"); + assert!(Market::parse(&m).is_err()); + assert_eq!( + uint256( + "115792089237316195423570985008687907853269984665640564039457584007913129639935" + ) + .unwrap(), + [255; 32] + ); + assert!(uint256( + "115792089237316195423570985008687907853269984665640564039457584007913129639936" + ) + .is_err()); + assert!(tokens(&json!(["1", "01"])).is_err()); + } +} diff --git a/crates/venue-probe/src/main.rs b/crates/venue-probe/src/main.rs new file mode 100644 index 0000000..fa82c3d --- /dev/null +++ b/crates/venue-probe/src/main.rs @@ -0,0 +1,101 @@ +mod book_audit; +mod books; +mod catalog; +mod price_check; +mod probes; +use anyhow::{ensure, Result}; +use reqwest::blocking::Client; +use serde_json::{json, Value}; +use std::time::{Duration, SystemTime, UNIX_EPOCH}; + +fn observe_book(client: &Client, url: reqwest::Url, token: &str) -> Result<()> { + let mut record = json!({"source":url.as_str(),"requested_asset":token, + "http_status":null,"book":null,"audit":null,"audit_error":null}); + let result: Result<()> = (|| { + let response = client.get(url).send()?; + let status = response.status(); + record["http_status"] = json!(status.as_u16()); + let raw: Value = response.json()?; + record["book"] = raw; + ensure!(status.is_success(), "venue returned HTTP {status}"); + record["audit"] = book_audit::inspect(&record["book"], token)?; + Ok(()) + })(); + record["observed_at_ms"] = + json!(SystemTime::now().duration_since(UNIX_EPOCH)?.as_millis() as u64); + if let Err(err) = &result { + record["audit_error"] = json!(format!("{err:#}")); + } + println!("{record}"); + result +} + +fn main() -> Result<()> { + let args: Vec<_> = std::env::args().skip(1).collect(); + let usage = + "usage: venue-probe [--compare-prices | --inspect-book TOKEN | --replay-book TOKEN FILE | --replay-market FILE]"; + if let [mode, file] = args.as_slice() { + if mode == "--replay-market" { + let raw = serde_json::from_reader(std::fs::File::open(file)?)?; + println!("{}", catalog::Market::parse(&raw)?.report); + return Ok(()); + } + } + if let [mode, token, file] = args.as_slice() { + ensure!(mode == "--replay-book", usage); + let input: serde_json::Value = serde_json::from_reader(std::fs::File::open(file)?)?; + if let Some(status) = input.get("http_status") { + ensure!( + status.as_u64().is_some_and(|n| (200..300).contains(&n)), + "saved observation has no successful HTTP response" + ); + } + let raw = input.get("book").unwrap_or(&input); + let report = book_audit::inspect(raw, token)?; + println!("{report}"); + return Ok(()); + } + let compare = match args.as_slice() { + [] => false, + [flag] if flag == "--compare-prices" => true, + [flag, _] if flag == "--inspect-book" => false, + _ => anyhow::bail!(usage), + }; + let client = Client::builder() + .connect_timeout(Duration::from_secs(5)) + .timeout(Duration::from_secs(15)) + .user_agent("eventbook-readonly-probe/0.1") + .build()?; + if let [_, token] = args.as_slice() { + let url = reqwest::Url::parse_with_params( + "https://clob.polymarket.com/book", + &[("token_id", token)], + )?; + return observe_book(&client, url, token); + } + let mut ok = true; + for (name, result) in [ + ("polymarket", probes::polymarket(&client, compare)), + ("kalshi", probes::kalshi(&client)), + ] { + match result { + Ok(snapshot) => { + println!("{snapshot}"); + if snapshot["orderbooks_complete"] != true { + ok = false; + eprintln!("{name}: catalog read succeeded, one or more order books failed"); + } + if name == "polymarket" && compare && snapshot["price_check_passed"] != true { + ok = false; + eprintln!("polymarket: price comparison not confirmed for both outcomes"); + } + } + Err(e) => { + ok = false; + eprintln!("{name}: {e:#}"); + } + } + } + ensure!(ok, "one or more venues failed"); + Ok(()) +} diff --git a/crates/venue-probe/src/price_check.rs b/crates/venue-probe/src/price_check.rs new file mode 100644 index 0000000..9992fec --- /dev/null +++ b/crates/venue-probe/src/price_check.rs @@ -0,0 +1,174 @@ +use crate::books; +use anyhow::{Context, Result}; +use reqwest::{blocking::Client, Url}; +use serde_json::{json, Value}; + +pub(crate) fn report(before: &Value, buy: Value, sell: Value, last: Result) -> Value { + let (after, error) = match last { + Ok(book) => (book, None), + Err(e) => (Value::Null, Some(format!("{e:#}"))), + }; + json!({"status":classify(before,&after,&buy,&sell), + "BUY":buy,"SELL":sell,"book_after":after,"book_after_error":error}) +} + +pub(crate) fn quote(client: &Client, asset: &str, side: &str) -> Value { + let read = || -> Result { + let url = Url::parse_with_params( + "https://clob.polymarket.com/price", + &[("token_id", asset), ("side", side)], + )?; + let response = client.get(url).send().context("quote request")?; + let status = response.status(); + let mut result = json!({"http_status":status.as_u16()}); + match response.json::() { + Ok(body) => { + if status.is_success() { + match books::price(&body["price"]) { + Ok(price) => result["price_micros"] = json!(price), + Err(e) => result["error"] = json!(e.to_string()), + } + } + result["response"] = body; + } + Err(e) => result["error"] = json!(e.to_string()), + } + Ok(result) + }; + read().unwrap_or_else(|e| json!({"error":format!("{e:#}")})) +} + +fn classify(before: &Value, after: &Value, buy: &Value, sell: &Value) -> &'static str { + let Some(hash) = before["hash"].as_str().filter(|h| !h.is_empty()) else { + return "inconclusive"; + }; + if after.is_null() || after["hash"].as_str().filter(|h| !h.is_empty()).is_none() { + return "inconclusive"; + } + if after["hash"] != hash + || before["best_bid"] != after["best_bid"] + || before["best_ask"] != after["best_ask"] + { + return "book_changed"; + } + let bid = before["best_bid"]["price_micros"].as_u64(); + let ask = before["best_ask"]["price_micros"].as_u64(); + let (Some(buy), Some(sell)) = (buy["price_micros"].as_u64(), sell["price_micros"].as_u64()) + else { + return "inconclusive"; + }; + match (bid, ask) { + (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", + _ => "different_prices", + } +} + +#[cfg(test)] +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 = + serde_json::from_str(include_str!("../fixtures/live-side-prices.json")).unwrap(); + for case in raw["cases"].as_array().unwrap() { + let token = case["asset"].as_str().unwrap(); + let market = json!({"conditionId":case["before"]["body"]["market"]}); + let read = |key: &str| books::poly_book(&market, token, &case[key]["body"]).unwrap(); + let price = |side: &str| { + let wire = &case[side]["body"]["price"]; + assert_eq!( + &case["batch_post"]["body"][token][side.to_uppercase().as_str()], + wire + ); + json!({"price_micros":books::price(wire).unwrap()}) + }; + assert_eq!( + classify( + &read("before"), + &read("after"), + &price("buy"), + &price("sell") + ), + "resting_side" + ); + assert_eq!(case["batch_get"]["http_status"], 400); + } + } + + #[test] + fn stable_distinct_book_differentiates_the_two_price_conventions() { + let gamma: Value = + serde_json::from_str(include_str!("../fixtures/gamma-559651.json")).unwrap(); + let tokens = crate::catalog::Market::parse(&gamma).unwrap().assets; + assert_ne!(tokens[0], gamma["positionIds"][0].as_str().unwrap()); + let level = |p: &Value| json!({"price":p.to_string(),"size":"1"}); + // Synthetic CLOB responses at the two prices observed on Gamma. + let raw = json!({"market":gamma["conditionId"],"asset_id":tokens[0],"hash":"synthetic", + "bids":[level(&gamma["bestBid"])],"asks":[level(&gamma["bestAsk"])]}); + let before = books::poly_book(&gamma, &tokens[0], &raw).unwrap(); + let bid = json!({"price_micros":12000}); + let ask = json!({"price_micros":13000}); + assert_eq!(classify(&before, &before, &ask, &bid), "opposing_side"); + assert_eq!(classify(&before, &before, &bid, &ask), "resting_side"); + assert_eq!(classify(&before, &before, &bid, &bid), "different_prices"); + assert_eq!( + classify(&before, &before, &json!({"http_status":404}), &bid), + "inconclusive" + ); + let mut after = before.clone(); + after["hash"] = json!("changed"); + assert_eq!(classify(&before, &after, &ask, &bid), "book_changed"); + after["hash"] = Value::Null; + assert_eq!(classify(&before, &after, &ask, &bid), "inconclusive"); + for (edge, expected) in [ + (Value::Null, "different_prices"), + (before["best_bid"].clone(), "inconclusive"), + ] { + let mut one = before.clone(); + one["best_ask"] = edge; + assert_eq!(classify(&one, &one, &ask, &bid), expected); + } + } +} diff --git a/crates/venue-probe/src/probes.rs b/crates/venue-probe/src/probes.rs new file mode 100644 index 0000000..cce1efb --- /dev/null +++ b/crates/venue-probe/src/probes.rs @@ -0,0 +1,231 @@ +use crate::{books, catalog::Market, price_check}; +use anyhow::{anyhow, Context, Result}; +use reqwest::{blocking::Client, Url}; +use serde_json::{json, Value}; + +fn read(client: &Client, url: Url) -> Result { + let response = client + .get(url.clone()) + .send() + .with_context(|| format!("GET {url}"))?; + response + .error_for_status() + .with_context(|| format!("HTTP {url}"))? + .json() + .with_context(|| format!("invalid JSON from {url}")) +} + +pub(crate) fn polymarket(client: &Client, compare: bool) -> Result { + let markets = read( + client, + Url::parse("https://gamma-api.polymarket.com/markets?active=true&closed=false&limit=50")?, + ) + .context("Polymarket catalog")?; + let (m, market) = markets + .as_array() + .context("expected market array")? + .iter() + .filter(|m| m["enableOrderBook"] == true && m["acceptingOrders"] == true) + .find_map(|m| Market::parse(m).ok().map(|market| (m, market))) + .context("no supported tradable binary market in sample")?; + polymarket_report(market, compare, |asset| { + let url = + Url::parse_with_params("https://clob.polymarket.com/book", &[("token_id", asset)])?; + let book = read(client, url.clone()).context("Polymarket orderbook")?; + let mut snapshot = books::poly_book(m, asset, &book)?; + if compare { + let buy = price_check::quote(client, asset, "BUY"); + let sell = price_check::quote(client, asset, "SELL"); + let after = read(client, url).and_then(|book| books::poly_book(m, asset, &book)); + snapshot["price_check"] = price_check::report(&snapshot, buy, sell, after); + } + Ok(snapshot) + }) +} + +fn polymarket_report( + market: Market, + compare: bool, + mut observe: impl FnMut(&str) -> Result, +) -> Result { + let mut result = market.report; + let outcomes = result["outcomes"] + .as_array_mut() + .context("missing catalog outcomes")?; + for (asset, outcome) in market.assets.iter().zip(outcomes.iter_mut()) { + let snapshot = + observe(asset).unwrap_or_else(|err| json!({"book_error":format!("{err:#}")})); + let fields = snapshot.as_object().context("invalid book observation")?; + outcome + .as_object_mut() + .context("invalid catalog outcome")? + .extend(fields.clone()); + } + let complete = outcomes.iter().all(|s| s.get("book_error").is_none()); + let passed = compare + && 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); + } + Ok(result) +} + +pub(crate) fn kalshi(client: &Client) -> Result { + let root = "https://external-api.kalshi.com/trade-api/v2/markets"; + let markets = read( + client, + Url::parse_with_params(root, &[("status", "open"), ("limit", "1")])?, + ) + .context("Kalshi catalog")?; + let market = markets["markets"].get(0).context("no open market")?; + kalshi_report(root, market, |url| read(client, url)) +} + +fn kalshi_report( + root: &str, + market: &Value, + observe: impl FnOnce(Url) -> Result, +) -> Result { + let ticker = market["ticker"] + .as_str() + .filter(|s| !s.is_empty()) + .context("no open market ticker")?; + let mut url = Url::parse(root)?; + url.path_segments_mut() + .map_err(|_| anyhow!("invalid market URL"))? + .extend([ticker, "orderbook"]); + let mut snapshot = match observe(url).and_then(|data| books::kalshi_book(ticker, &data)) { + Ok(mut book) => { + book["orderbooks_complete"] = json!(true); + book + } + Err(err) => { + json!({"venue":"kalshi","ticker":ticker,"orderbooks_complete":false,"book_error":format!("{err:#}")}) + } + }; + snapshot["catalog"] = json!({"event_ticker":market["event_ticker"],"market_type":market["market_type"], + "status":market["status"],"mve_collection_ticker":market["mve_collection_ticker"], + "mve_selected_legs":market["mve_selected_legs"],"updated_time":market["updated_time"]}); + Ok(snapshot) +} + +#[cfg(test)] +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 = + serde_json::from_str(include_str!("../fixtures/gamma-559651.json")).unwrap(); + let record = Market::parse(&market).unwrap(); + let assets = record.assets.clone(); + let report = polymarket_report(record, true, |id| { + if id == assets[0].as_str() { + anyhow::bail!("simulated timeout"); + } + Ok(json!({"asset_id":id,"best_bid":null,"best_ask":null})) + }) + .unwrap(); + assert_eq!(report["market"], market["id"]); + assert_eq!(report["orderbooks_complete"], false); + assert_eq!(report["price_check_passed"], false); + let rows = report["outcomes"].as_array().unwrap(); + assert_eq!(rows[0]["asset_id"].as_str(), Some(assets[0].as_str())); + assert_eq!(rows[0]["book_error"], "simulated timeout"); + assert!(rows[0].get("best_bid").is_none()); + assert_eq!(rows[1]["asset_id"].as_str(), Some(assets[1].as_str())); + assert_eq!(rows[1]["label"], "No"); + assert_eq!(rows[1].get("best_bid"), Some(&Value::Null)); + assert!(rows[1].get("book_error").is_none()); + } + + #[test] + fn kalshi_combo_keeps_all_legs_on_failed_and_empty_books() { + let market: Value = + serde_json::from_str(include_str!("../fixtures/kalshi-combo.json")).unwrap(); + let root = "https://external-api.kalshi.com/trade-api/v2/markets"; + let failed = kalshi_report(root, &market, |url| { + assert_eq!( + url.path(), + format!( + "/trade-api/v2/markets/{}/orderbook", + market["ticker"].as_str().unwrap() + ) + ); + anyhow::bail!("simulated timeout"); + }) + .unwrap(); + assert_eq!(failed["orderbooks_complete"], false); + assert!(failed.get("yes").is_none()); + assert_eq!(failed["catalog"]["market_type"], "binary"); + assert_eq!( + failed["catalog"]["mve_selected_legs"] + .as_array() + .unwrap() + .len(), + 30 + ); + assert_eq!( + failed["catalog"]["mve_selected_legs"], + market["mve_selected_legs"] + ); + let empty = kalshi_report(root, &market, |_| { + Ok(json!({"orderbook_fp":{"yes_dollars":[],"no_dollars":[]}})) + }) + .unwrap(); + assert_eq!(empty["orderbooks_complete"], true); + assert_eq!(empty["catalog"], failed["catalog"]); + assert_eq!(empty["yes"]["best_bid"], Value::Null); + assert!(empty.get("book_error").is_none()); + } +}