Skip to Content
While25SDK docs
Trading

Instrument rules

A venue's size and price rules for one instrument: lot sizes, price steps, what it accepts.

inst = while25.data.instrument("EQ:US:AAPL")
inst2 = while25.data.instruments(["EQ:US:AAPL", "EQ:US:MSFT"])   # a list, same order

The venue's own size and price rules for one instrument, so a strategy can size an order it already knows will be accepted — or explain a rejection without a round trip. With a broker attached they are that broker's own (its instrument list or its contract lookup); with none, the data source's. Every rule is Decimal | None (absent means the venue stated none): size_increment, min_qty, max_qty, lot_multiple, price_increment, sub_band_price_increment, price_band_floor, multiplier; min_notional is a Money | None; price_steps is the tick by price where it changes with the price (IBKR's rule for the contract), (from_price, increment) rows lowest first, () when the venue states none — when present it governs every price in place of price_increment and the band. quote_currency, settlement_currency, tradeable and untradeable_reason describe the row itself. An unknown key raises While25Error (code INSTRUMENT_NOT_FOUND).

inst.step                          # lot_multiple, else size_increment; None if neither
inst.tick_for(101.30)              # the tick that governs THIS price (ladder step, else band)
inst.check(quantity=15, price=101.30)   # None = would pass; else the reason it would not
inst.notice(quantity=15, price=101.30)  # None = every rule on file; else what the venue judges
inst.snap(ltp)                     # a float from the feed -> the exact tick-grid Decimal
inst.offset(ltp, -2)               # two ticks below, exact
inst.ticks_between(ltp, target)    # whole ticks apart, exact; None across a band floor

Prices reach a script as floats and stay floats — indicators want them so. snap(), offset() and ticks_between() are where a float becomes an exact figure: the float is read by its shortest decimal form (the tape's 100.05, stored as 100.0499999999999971, reads back as 100.05) and put on the venue's tick ONCE, so "two ticks below" and "how many ticks apart" are exact and the order you build from them is on the grid. Do the arithmetic on the snapped Decimal, never on the float (100.05 - 0.10 is 99.94999999999999 in floats, and check() would refuse it as off-tick). snap(price, mode="down") and "up" pick the buyer's and the seller's side of a between-tick price.

On a ladder a tick is one step along the venue's grid (every price on the tick that governs it), so offset() and ticks_between() change increment at a step edge:

# price_steps (0, 0.05), (3, 0.10): 0.05 below 3, 0.10 from 3 on
inst.tick_for(3)                   # 0.10: the step AT 3
inst.offset(2.95, 2)               # 3.10 (2.95, 3.00, 3.10)
inst.offset(3.10, -2)              # 2.95, not 2.90
inst.ticks_between(2.95, 3.10)     # 2

check() is a local, advisory pre-check — it never calls While25 — mirroring the same size and price rules While25 itself enforces (check_size/check_price): positive; on-step; between the minimum and the maximum; at or above min_notional when a price is also given; on the tick tick_for() names when a price is given. Only a rule the venue states is judged: a missing step, minimum or tick, or a min_notional stated in another currency than the order's, refuses nothing — the order goes as typed and the venue judges it. A min_notional the venue states for orders by amount only (min_notional_amount_orders_only: Coinbase's quote_min_size, stated for the quote asset alone) holds no quantity either: such an order goes to the venue. notice() names each such gap so a script can log it, and returns None when every rule the order touches is on file. check() returning None means "While25 is expected to accept this," not a guarantee — While25 re-checks every order regardless, and its verdict is the one that counts.

msg = inst.check(quantity=7)
if msg:
    while25.log(f"skipping: {msg}")
else:
    while25.buy("EQ:US:AAPL", 7)