#1513·OpenAlice

IBKR order placement always rejected with error 10244: UNSET_DECIMAL sentinel leaks across decimal.js copies

Author: Ban921Created Sep 14, 2026Updated Sep 14, 2026

Summary

Every IBKR order placement is rejected by TWS with error 10244: Cash Quantity is not supported for this order, even though cashQty is never supplied by the caller. The UNSET_DECIMAL sentinel leaks onto the wire as a literal value because the app and the IBKR broker pack each bundle a separate copy of decimal.js, so the instanceof guard in the pack's wire encoder fails for Decimals constructed by the app.

Impact

IBKR trading is fully blocked — no order type can be placed. Reads (account, portfolio, contract search/details, market clock) are unaffected.

Environment

  • OpenAlice 0.93.0 (com.traderalice.openalice), macOS 15 (Darwin 25.6.0)
  • IBKR broker pack 0.93.0-ed679c9ba890242c
  • IB Gateway, live mode, API port 4001, ApiOnly=true

Repro

bash
alice-uta order place \
  --alice-id '<acct>|849555205' --symbol SNXX \
  --action BUY --order-type LMT \
  --total-quantity 1 --lmt-price 14.00 --tif DAY \
  --commit-message 'test'
# then approve + push in the Web UI

Result:

json
{"status":"rejected","error":"IBKR error 10244: 該委託單不能使用\"現金數量\""}

Evidence

1. The persisted operation carries no cashQty. From data/trading/<account>/commit.json:

operations[0].order.totalQuantity = '1'
operations[0].order.orderType     = 'LMT'
operations[0].order.lmtPrice      = '14'
operations[0].order.tif           = 'DAY'

No cashQty key — so the application layer never sets it. TradingGit.rehydrateOrder correctly skips it (if (order.cashQty != null) is false), leaving the new Order() class default cashQty = UNSET_DECIMAL.

2. Two independent decimal.js instances. The broker pack resolves [email protected] from its own runtime/broker-packs/ibkr/releases/<rel>/node_modules/, while app.asar bundles its own copy. Decimals created by the app are therefore not instanceof the pack's Decimal.

3. The encoder gates the sentinel conversion behind instanceof. Broker pack dist/index.js:1676:

javascript
function makeFieldHandleEmpty(val) {
  if (val === null || val === void 0) throw new Error("Cannot send None to TWS");
  if (val instanceof Decimal3) {                        // <-- fails for a foreign Decimal
    if (val.equals(UNSET_DECIMAL)) return makeField(""); // <-- the sentinel -> empty conversion
    return makeField(val);
  }
  if (val === UNSET_INTEGER || val === UNSET_DOUBLE) return makeField("");
  if (val === DOUBLE_INFINITY) return makeField(INFINITY_STR);
  return makeField(val);                                 // <-- falls through to String(val)
}

A foreign Decimal misses both the instanceof branch and the primitive === checks, so it reaches makeField(val), which likewise tests instanceof Decimal3 and ends at String(val).

Reproduced in isolation with two copies of the same decimal.js:

same-copy sentinel    -> ""                                        (correct: TWS reads it as unset)
foreign-copy sentinel -> "1.70141183460469231731687303715884105727e+38"
foreign-copy value(1) -> "1"                                       (correct by coincidence)

TWS therefore sees a populated cashQty on a LMT order and returns 10244.

4. Why only cashQty surfaces. Only Decimal-typed sentinels are affected. UNSET_INTEGER / UNSET_DOUBLE fields are primitives and still match by === across copies, and ordinary Decimal values such as totalQuantity / lmtPrice stringify to the correct text by coincidence. On the placeOrder path cashQty (dist/index.js:24250) is the only Decimal sentinel routed through makeFieldHandleEmpty — totalQuantity uses makeField (:23976) and always holds a real value.

No available workaround

  • MKT with --total-quantity — cashQty is still the sentinel, same 10244.
  • --cash-qty on MKT — shifts the problem to totalQuantity, whose sentinel then leaks through makeField.
  • Broker pack 0.92.0-b9f9dfcf963278db carries the identical instanceof Decimal3 guard (:1661, :1680).

Suggested fix

Do not rely on instanceof across the app/broker-pack module boundary. Either:

  • Duck-type the check in makeField / makeFieldHandleEmpty — e.g. test for Decimal.isDecimal(val) or the presence of .equals/.toFixed, and compare against the sentinel by string value rather than object identity; or
  • Share one decimal.js instance between the host and broker packs (external/peer dependency rather than a bundled copy).

The duck-typed comparison seems the more robust of the two, since broker packs are versioned and loaded independently — any future package that bundles its own copy of a value type will hit the same class of bug.