PolymarketClob.Order.Rounding (PolymarketClob v0.2.0)

Copy Markdown View Source

Float-based rounding helpers ported from py-clob-client-v2.

These helpers intentionally use floats, not Decimal, because order amount parity with the official client is more important than decimal arithmetic aesthetics.

Summary

Functions

Returns the Python-client rounding config for a tick size.

Returns the number of decimal places in the shortest float string.

Rounds down to sig_digits decimal places.

Rounds normally to sig_digits decimal places.

Rounds up to sig_digits decimal places.

Converts a float token amount to CLOB 6-decimal integer units.

Types

round_config()

@type round_config() :: %{
  price: non_neg_integer(),
  size: non_neg_integer(),
  amount: non_neg_integer()
}

tick_size()

@type tick_size() :: String.t()

Functions

config!(tick_size)

@spec config!(tick_size()) :: round_config()

Returns the Python-client rounding config for a tick size.

decimal_places(value)

@spec decimal_places(number()) :: non_neg_integer()

Returns the number of decimal places in the shortest float string.

round_down(value, sig_digits)

@spec round_down(number(), non_neg_integer()) :: float()

Rounds down to sig_digits decimal places.

round_normal(value, sig_digits)

@spec round_normal(number(), non_neg_integer()) :: float()

Rounds normally to sig_digits decimal places.

round_up(value, sig_digits)

@spec round_up(number(), non_neg_integer()) :: float()

Rounds up to sig_digits decimal places.

to_token_decimals(value)

@spec to_token_decimals(number()) :: integer()

Converts a float token amount to CLOB 6-decimal integer units.