fix: Round tick base to power of 10 in default case

Bugs (fixed):
  * Bybit execution gw throws on MILKUSDT orders due to bad price tick.

    Cause: rounding error when converting the small price tick (0.00001)
    to "tick factors" (1/10000). The denominator is computed as
    1/0.00001 = 99999.9...
This commit is contained in:
John Colvin committed 2025-06-24 10:48:42 -04:00
1 parent 399f9e61e2
commit 155a396af5
2 files changed
+12 -3

No files matched your search

@@ -21,6 +21,7 @@ from spark_core import (
get_price_info,
get_quantity_info,
get_security,
get_tick_factors,
load_config,
)
from py_md_utils import PERP_EXP_STRING
@@ -70,11 +71,11 @@ def fetch_futures_specs(contracts: Iterable[str], use_testnet: bool = True) -> d
logger.error(f"Invalid tick or lot size for {contract}: tickSize={price_tick}, qtyStep={lot_size}")
continue
tick_base = min(int(1 / price_tick), 1000000) if price_tick != 0 else 10
tick_unit, tick_base = get_tick_factors(price_tick)
qty_tick_base = min(int(1 / lot_size), 1000000) if lot_size != 0 else 10000
specs_dict[contract] = {
"tick_unit": 1,
"tick_unit": tick_unit,
"tick_base": tick_base,
"cash_per_point": 1,
"qty_tick_unit": 1,
@@ -256,7 +256,15 @@ def get_tick_factors(tick_sz: float):
case 20_000:
return (5, 100_000)
case _:
raise ValueError(f"Invalid tick size {tick_sz}")
tick_base = min(int(1 / tick_sz), 1000000) if tick_sz != 0 else 10
tick_base_log10 = math.log10(tick_base)
tick_base_log10_ceil = math.ceil(tick_base_log10)
tick_base_log10_floor = math.floor(tick_base_log10)
if (tick_base_log10_ceil - tick_base_log10 <= 0.1):
tick_base = int(math.pow(10, tick_base_log10_ceil))
elif (tick_base - tick_base_log10_floor >= 0.9):
tick_base = int(math.pow(10, tick_base_log10_floor))
return (1, tick_base)
def get_num_decimal_places(tick_sz: float):