Launchpad

Lots or units? The same order, ten times the size

One broker API reads the order quantity as lots, another as units. The same code placed one lot on one account and ten on the other.

What went wrong

We run the same strategies across accounts at more than one broker. For a commodity future with a lot size of 10, our code sent an order with a quantity of 10. One broker placed 1 lot (10 units). The other placed 10 lots (100 units). Same code, same contract, same number: ten times the position.

What it cost, or could have cost

An order ten times the intended size, at full leverage. On a NIFTY option with a lot of 65, sending lots where units are expected, or the reverse, is a 65-times error: enough to breach margin limits or wipe out months of gains in a single move.

Root cause

“Quantity” doesn’t mean the same thing everywhere:

  • One broker reads quantity as units for every segment.
  • The other reads it as units for equity derivatives but as lots for commodity contracts.

Our code passed the number straight through, assuming every API agreed. Nothing in either API’s response warned us; the orders were valid, just different.

The fix

  1. One internal unit. Everywhere inside the bot, size is stored as a number of lots. Nothing else.
  2. Convert at the last moment, in one place. A single function turns lots into whatever this broker and this segment expect, just before the order goes out:
def broker_quantity(lots: int, lot_size: int, broker: str, segment: str) -> int:
    """Convert our internal size (lots) into the quantity this broker's API expects."""
    if (broker, segment) in LOTS_BASED:      # e.g. {("broker_b", "commodity")}
        return lots
    return lots * lot_size                   # everyone else wants units
  1. A size sanity check before every order. If the value of the order is more than a set multiple of what the strategy normally trades, the order is blocked and an alert goes out.
  2. Test each new broker and segment with the smallest size first, and confirm the filled quantity before scaling up.

Checklist item

  • For every broker and segment you trade, you have confirmed with a one-lot live order whether “quantity” means lots or units, and all conversions happen in one function.

Was this useful?

More to say, or spotted a mistake? Write to [email protected]. We read everything.

Topics