fix(clob): tolerate empty-string Decimals and missing tx_hash when deserializing fills - #65
Open
popoxhb wants to merge 1 commit into
Open
fix(clob): tolerate empty-string Decimals and missing tx_hash when deserializing fills#65popoxhb wants to merge 1 commit into
popoxhb wants to merge 1 commit into
Conversation
The live Polymarket CLOB /trades endpoint occasionally returns empty strings for the Decimal money fields on TradeResponse (size, fee_rate_bps, price) and MakerOrder (matched_amount, price, fee_rate_bps), and omits TradeResponse.transaction_hash for maker fills that are not yet on-chain. Either case makes the whole trades batch fail to deserialize and silently drops every fill. Reuse the existing empty_string_as_zero deserializer (already applied to PostOrderResponse making/taking amounts) on those fields, and mark transaction_hash #[serde(default)] so a missing hash deserializes to B256::default(). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The live Polymarket CLOB API occasionally serializes
Decimalmoney fields as empty strings ("") and omitstransaction_hashfor maker fills that are not yet on-chain. With the current strict typing this makes the entire/tradesresponse batch fail to deserialize — a single""in one record fails the wholePage<TradeResponse>parse, silently dropping every fill in that batch.Observed in production on
GET /trades:TradeResponse.size,TradeResponse.fee_rate_bps,TradeResponse.price→ sometimes""MakerOrder.matched_amount,MakerOrder.price,MakerOrder.fee_rate_bps→ sometimes""TradeResponse.transaction_hash→ absent for maker fills not yet settled on-chainFix
empty_string_as_zerodeserializer (already used onPostOrderResponse.making_amount/taking_amount) to the sixDecimalfields above, so""parses asDecimal::ZEROinstead of erroring.TradeResponse.transaction_hashas#[serde(default)], so a missing hash deserializes toB256::default()(the zero hash) rather than failing.Compatibility
Backward compatible: well-formed responses with present, non-empty values deserialize exactly as before. Only the previously-fatal empty/missing cases change — from "whole batch errors out" to "that field is zero / default".
empty_string_as_zeroalready exists inresponse.rs, so this is attribute-only — no new helpers and no API/signature changes.Note
Low Risk
Attribute-only serde changes on response DTOs; no API or logic changes, with backward-compatible parsing for well-formed payloads.
Overview
Hardens
/tradesdeserialization so a single malformed field no longer fails an entirePage<TradeResponse>batch from the live CLOB API.On
TradeResponse,size,fee_rate_bps, andpricenow use the existingempty_string_as_zerodeserializer (same pattern asPostOrderResponse), so""becomesDecimal::ZERO.transaction_hashgets#[serde(default)], so omitted hashes (e.g. maker fills not yet on-chain) deserialize to the defaultB256instead of erroring.On
MakerOrder,matched_amount,price, andfee_rate_bpsget the sameempty_string_as_zerotreatment. Normal non-empty values behave unchanged; only previously fatal empty/missing wire shapes are relaxed.Reviewed by Cursor Bugbot for commit d36cc61. Bugbot is set up for automated code reviews on this repo. Configure here.