Skip to content
This repository was archived by the owner on May 25, 2026. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions py_clob_client/order_builder/helpers.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
from math import floor, ceil
from decimal import Decimal
from decimal import Decimal, ROUND_FLOOR, ROUND_HALF_EVEN, ROUND_CEILING


def round_down(x: float, sig_digits: int) -> float:
return floor(x * (10**sig_digits)) / (10**sig_digits)
d = Decimal(str(x))
return float(d.quantize(Decimal(10) ** -sig_digits, rounding=ROUND_FLOOR))


def round_normal(x: float, sig_digits: int) -> float:
return round(x * (10**sig_digits)) / (10**sig_digits)
d = Decimal(str(x))
return float(d.quantize(Decimal(10) ** -sig_digits, rounding=ROUND_HALF_EVEN))


def round_up(x: float, sig_digits: int) -> float:
return ceil(x * (10**sig_digits)) / (10**sig_digits)
d = Decimal(str(x))
return float(d.quantize(Decimal(10) ** -sig_digits, rounding=ROUND_CEILING))


def to_token_decimals(x: float) -> int:
f = (10**6) * x
if decimal_places(f) > 0:
f = round_normal(f, 0)
return int(f)
d = Decimal(str(x)) * Decimal("1000000")
return int(d.quantize(Decimal("1"), rounding=ROUND_HALF_EVEN))


def decimal_places(x: float) -> int:
Expand Down