-
Notifications
You must be signed in to change notification settings - Fork 136
Description
Hi, I’m building a simple TradingView → Flask → Lighter bot using SignerClient, and I’m confused about how to correctly send short orders and long closes via create_market_order.
Right now:
-
Open long works 100% of the time.
-
Close short works when there is an actual short position.
-
However:
- When I try to open a short, the order appears in the UI but is always Canceled with
filled = 0. - When I send a “close short” while I have no short position, it opens a new long instead of doing nothing.
- In my tests, the other 2 patterns (open short / close long) end up canceled.
- When I try to open a short, the order appears in the UI but is always Canceled with
On the backend I’m always using create_market_order (I don’t use limit orders).
My TV → bot signal looks like this:
{
"account_id": "default",
"symbol": "BTCUSDT",
"side": "sell", // or "buy"
"size_usd": 100.0,
"price": 87413.54, // TradingView price, NOT sent to Lighter
"order_type": "open", // "open" or "close"
"is_new_entry": true,
"is_close": false,
"raw": { ... original webhook ... }
}Then I convert it to Lighter params like this:
symbol = "BTC" # from "BTCUSDT"
mconf = MARKET_CONFIG[symbol] # {"market_index": 1, "size_decimals": 5}
market_index = mconf["market_index"]
size_decimals = mconf["size_decimals"]
# USD size → base_amount_int
base_amount_human = size_usd / price
base_amount_int = round(base_amount_human * 10**size_decimals)
is_ask = (side == "sell") # buy = bid, sell = ask
reduce_only = bool(is_close) # close -> True, open -> False
client_order_index = int(time.time() * 1000)
result = await client.transactions.create_market_order(
market_index=market_index,
base_amount=base_amount_int,
client_order_index=client_order_index,
is_ask=is_ask,
reduce_only=reduce_only,
)So my mapping is:
- Open long:
side="buy",is_ask=False,reduce_only=False - Close long:
side="sell",is_ask=True,reduce_only=True - Open short:
side="sell",is_ask=True,reduce_only=False - Close short:
side="buy",is_ask=False,reduce_only=True
From the Python side the API call returns code=200 and looks OK, but on the UI the open short and close long orders show as Canceled with filled = 0.
Could you please confirm:
-
Is this
is_ask/reduce_onlymapping correct for:- open long
- close long
- open short
- close short
-
Is there any extra parameter or flag required for short market orders or long close with reduce_only?
-
Under what conditions would
create_market_orderreturn success but the order be immediately canceled withfilled = 0on the UI?
I’ve attached screenshots and log snippets showing one successful long open & close, and a canceled short open with the corresponding debug fields if that helps.