fix: Lighter stop/take-profit orders must use TimeInForce=0 (ImmediateOrCancel)

Lighter SDK validates that StopLossOrder (type=2) and TakeProfitOrder (type=4)
must have TimeInForce=0 (ImmediateOrCancel), not TimeInForce=1 (GoodTillTime).

This was causing stop-loss and take-profit orders to fail validation and not
be submitted to Lighter exchange.
This commit is contained in:
tinkle-community
2025-12-15 22:34:29 +08:00
parent 3f084005e4
commit 05c480d3f0
3 changed files with 3 additions and 2 deletions

BIN
img.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 492 KiB

BIN
img_1.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 360 KiB

View File

@@ -626,7 +626,8 @@ func (t *LighterTraderV2) CreateStopOrder(symbol string, isAsk bool, quantity fl
priceValue = uint32(triggerPrice * 1.05 * 1e2)
}
// Stop orders use GoodTillTime with expiry
// Stop orders MUST use ImmediateOrCancel (0) with expiry set
// Lighter SDK validates: StopLossOrder/TakeProfitOrder require TimeInForce=0 (ImmediateOrCancel)
orderExpiry := time.Now().Add(30 * 24 * time.Hour).UnixMilli() // 30 days
txReq := &types.CreateOrderTxReq{
@@ -636,7 +637,7 @@ func (t *LighterTraderV2) CreateStopOrder(symbol string, isAsk bool, quantity fl
Price: priceValue,
IsAsk: boolToUint8(isAsk),
Type: orderTypeValue,
TimeInForce: 1, // GoodTillTime
TimeInForce: 0, // ImmediateOrCancel - REQUIRED for stop/take-profit orders!
ReduceOnly: 1, // Stop orders should be reduce-only
TriggerPrice: triggerPriceValue,
OrderExpiry: orderExpiry,