Environment
- OpenAlice:
dev (checked 2026-08-02, commit 6fba9da)
- OS: macOS (likely platform-independent — failure is in N-API unwrapping)
- Broker: Longbridge (paper/demo account)
- Longbridge Node SDK: 4.0.5
Summary
Submitting or replacing an order through the Longbridge broker pack fails at
runtime: the N-API binding cannot unwrap decimal fields such as
SubmitOrderOptions.submittedQuantity because the adapter passes decimal.js
instances instead of the SDK's native longbridge.Decimal class. The
as unknown as never casts in LongbridgeBroker.ts only suppress the
TypeScript error — the class mismatch survives to runtime.
Expected behavior
A limit/trailing order on a Longbridge paper account submits successfully, and
modifyOrder replaces quantity/price/trigger successfully.
Actual behavior
tradeCtx.submitOrder() / tradeCtx.replaceOrder() fail at the native
boundary when the payload contains decimal.js values.
Actual error:
Reproduction steps
- Configure a Longbridge paper/demo account in UTA.
- Place an order through the Longbridge broker pack (e.g., AAPL.US limit buy
with quantity + limit price + trigger price).
submitOrder fails at the N-API unwrap step.
- (Optional) call
modifyOrder — replaceOrder fails the same way on
quantity/price/trigger fields.
Root cause
services/uta/src/domain/trading/brokers/longbridge/LongbridgeBroker.ts
builds SubmitOrderOptions/ReplaceOrderOptions directly from OpenAlice's
decimal.js Decimal values (lines ~297–327 on dev), then casts with
as unknown as never. The Longbridge SDK 4.0.5 write APIs require instances
of the SDK's exported Decimal class; N-API unwrapping expects that exact
class at runtime.
Proposed fix
PR #704 (#704) converts at the
write boundary via new LongbridgeDecimal(value.toString()) — a string
round-trip, so no precision is lost through JavaScript number — covering:
- submit: quantity, limit price, trigger price, trailing percent
- replace: quantity, limit price, trigger price
It includes regression tests asserting SDK Decimal class identity and exact
decimal strings; tsc --noEmit and the package typecheck pass. Live-paper
verification was not possible locally (no independently verified paper
account available) — happy to run it if a paper account can be provided or
once the fix is integrated.
Environment
dev(checked 2026-08-02, commit 6fba9da)Summary
Submitting or replacing an order through the Longbridge broker pack fails at
runtime: the N-API binding cannot unwrap decimal fields such as
SubmitOrderOptions.submittedQuantitybecause the adapter passesdecimal.jsinstances instead of the SDK's native
longbridge.Decimalclass. Theas unknown as nevercasts inLongbridgeBroker.tsonly suppress theTypeScript error — the class mismatch survives to runtime.
Expected behavior
A limit/trailing order on a Longbridge paper account submits successfully, and
modifyOrderreplaces quantity/price/trigger successfully.Actual behavior
tradeCtx.submitOrder()/tradeCtx.replaceOrder()fail at the nativeboundary when the payload contains
decimal.jsvalues.Actual error:
Reproduction steps
with quantity + limit price + trigger price).
submitOrderfails at the N-API unwrap step.modifyOrder—replaceOrderfails the same way onquantity/price/trigger fields.
Root cause
services/uta/src/domain/trading/brokers/longbridge/LongbridgeBroker.tsbuilds
SubmitOrderOptions/ReplaceOrderOptionsdirectly from OpenAlice'sdecimal.jsDecimalvalues (lines ~297–327 ondev), then casts withas unknown as never. The Longbridge SDK 4.0.5 write APIs require instancesof the SDK's exported
Decimalclass; N-API unwrapping expects that exactclass at runtime.
Proposed fix
PR #704 (#704) converts at the
write boundary via
new LongbridgeDecimal(value.toString())— a stringround-trip, so no precision is lost through JavaScript
number— covering:It includes regression tests asserting SDK
Decimalclass identity and exactdecimal strings;
tsc --noEmitand the package typecheck pass. Live-paperverification was not possible locally (no independently verified paper
account available) — happy to run it if a paper account can be provided or
once the fix is integrated.