fix: tolerate empty-string decimal fields in trade responses - #96
Open
Envy-Life wants to merge 1 commit into
Open
fix: tolerate empty-string decimal fields in trade responses#96Envy-Life wants to merge 1 commit into
Envy-Life wants to merge 1 commit into
Conversation
The CLOB can return "" for size, fee_rate_bps, and price on trades (and their maker orders) before settlement details are populated, which made TradeResponse deserialization fail with: invalid value: string "", expected a Decimal type representing a fixed-point number Apply the existing empty_string_as_zero deserializer (already used for PostOrderResponse amounts and TradeResponse.transaction_hash) to the Decimal fields of TradeResponse and MakerOrder.
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
GET /data/tradesresponses can carry""inDecimal-typed fields, which makes the whole trades fetch fail to deserialize:We hit this in production while paging a user's trades through
Client::trades— one trade with an empty decimal field poisons the entire page.This is the same venue behavior already handled for
TradeResponse.transaction_hash(empty until the async execution pipeline broadcasts the trade's transaction, tolerated viaempty_string_as_zero_hash) and forPostOrderResponse.making_amount/taking_amount(empty_string_as_zero) — but theDecimalfields ofTradeResponseand itsMakerOrders still hard-fail on"".Fix
Apply the existing
empty_string_as_zerodeserializer to:TradeResponse:size,fee_rate_bps,priceMakerOrder:matched_amount,price,fee_rate_bpsNo API change — only widens accepted wire input, mirroring the established pattern.
Testing
Added
trades_should_tolerate_empty_decimal_fields(mirrorstrades_should_tolerate_empty_transaction_hash), asserting all six fields deserialize toDecimal::ZEROwhen the venue sends"".(Note: couldn't apply the
wiplabel from a fork — maintainers, feel free to add if desired.)Note
Low Risk
Deserialization-only widening with an established helper; no API or trading logic changes, though callers may see zero instead of a hard error for malformed venue data.
Overview
Trade list deserialization no longer fails when the venue sends
""for numeric trade fields onGET /data/trades.TradeResponse(size,fee_rate_bps,price) and nestedMakerOrder(matched_amount,price,fee_rate_bps) now use the existingempty_string_as_zerodeserializer, matchingPostOrderResponseand the emptytransaction_hashhandling. Empty strings map toDecimal::ZERO; valid numeric strings behave as before.A CLOB integration test asserts a full trades page still parses when those six fields are empty on the trade and its maker order.
Reviewed by Cursor Bugbot for commit 9e59efc. Bugbot is set up for automated code reviews on this repo. Configure here.