Skip to content
Open
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions sdks/python/pmxt/_hosted_mappers.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@
from .errors import InvalidOrder
from .models import Balance, BuiltOrder, Order, Position, UserTrade

SIX_DEC_SCALE = 1_000_000
_SIX_DEC_SCALE = 1_000_000

_T = TypeVar("_T")


def to_6dec(amount: float | str | Decimal) -> int:
"""Convert a decimal amount to integer micro-units with no rounding."""
d = Decimal(str(amount))
scaled = d * SIX_DEC_SCALE
scaled = d * _SIX_DEC_SCALE
if scaled != scaled.to_integral_value():
raise InvalidOrder(f"amount precision exceeds 6 decimals: {amount!r}")
return int(scaled)
Expand Down
5 changes: 5 additions & 0 deletions sdks/python/tests/test_hosted_mappers.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ def _mapper(*names):
to_6dec = _hosted_mappers.to_6dec


def test_six_decimal_scale_is_module_private():
assert not hasattr(_hosted_mappers, "SIX_DEC_SCALE")
assert _hosted_mappers._SIX_DEC_SCALE == 1_000_000


def _iso_ms(value: str) -> int:
return int(datetime.fromisoformat(value.replace("Z", "+00:00")).timestamp() * 1000)

Expand Down