fix: don't silently use 0 when a wire price/size fails to parse (market order at 0) - #172
Merged
Merged
Conversation
parseFloat returns 0.0 on any parse error. Two financial call sites relied on it for values coming off the API: - SlippagePrice (market order price): a malformed mid price became a market order priced at 0, with no error. - MarketClose (position size): a malformed pos.Szi became size 0 (a no-op / wrong close). Add parseFloatStrict (error-returning) and use it at both sites, which both already return an error. parseFloat is unchanged for its display callers, so this is non-breaking. Adds a unit test contrasting the two parsers.
chiliec
force-pushed
the
fix/slippage-price-silent-zero
branch
from
August 31, 2026 09:51
31b99d8 to
aef9531
Compare
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.
Description
parseFloatreturns0.0on any parse error (it swallows the error). Two call sites use it for financial values coming off the API, where a silent0is dangerous:1.
SlippagePrice— market order price. For a market order (px == nil) it parses the mid price:A malformed mid price from
AllMidsbecomes0, and the caller places a market order priced at 0 with no error surfaced.2.
MarketClose— position size. It parses the position size:A malformed
pos.Szibecomes0, sosize = abs(0) = 0— a no-op / wrong close, again silently.Fix
Add
parseFloatStrict(error-returning) and use it at both sites. BothSlippagePriceandMarketClosealready return anerror, so the parse failure now propagates instead of turning into a0.parseFloatis left unchanged for its existing display callers, so this is non-breaking.Type of Change
Testing
TestParseFloatStrict— valid inputs matchparseFloat; invalid inputs error instead of silently returning 0go test ./passes (full suite)go vet ./andgofmtcleanCode Quality
Additional Notes
First-time contributor.
parseFloat's third caller is a display/formatting path where a0default is harmless, so I left it as-is — happy to convert that too if you'd prefer all parses to be strict.