Skip to content

Conversation

@qualiaenjoyer
Copy link

@qualiaenjoyer qualiaenjoyer commented Oct 15, 2025

Overview

I noticed I was placing an order with size 9.53 and I was getting back one with size 9.52.
Turns out it was due to round_down(9.53, 2) = 9.52 in order_builder/helpers.

Description

  • Changed round_up and round_down from floor/ceil to Decimal.quantize to eliminate binary float errors and ensure the expected base-10 behavior (e.g. round_down(9.53, 2) = 9.53).
  • Changed round_normal and to_token_decimals for style consistency with the above changes.

Types of changes

  • Bug fix/behavior correction

Status

  • Prefix PR title with [WIP] if necessary (changes not yet made).
  • Add tests to cover changes as needed. (NA)
  • Update documentation/changelog as needed. (NA)
  • Verify all tests run correctly in CI and pass. - all 82 tests pass
  • Ready for review/merge.

same "Found 108 errors in 10 files (checked 21 source files)" linting errors as py-clob-client 0.25.0.


Note

Replace float-based rounding with Decimal.quantize for base-10 precision and simplify to_token_decimals.

  • Rounding behavior (py_clob_client/order_builder/helpers.py):
    • round_down, round_normal, round_up now use Decimal.quantize with ROUND_FLOOR, ROUND_HALF_UP, and ROUND_CEILING to ensure base-10 precision.
    • to_token_decimals rewritten to use Decimal.quantize after scaling by 10**6, removing intermediate float checks.

Written by Cursor Bugbot for commit 292d0c3. This will update automatically on new commits. Configure here.

@qualiaenjoyer
Copy link
Author

@JonathanAmenechi any chance for a review? it can cause a bunch of problems in automated trading systems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant