limit → specified price; market → best ask (buy) or best bid (sell).
Base (e.g. BTC, ETH)
contracts = base_amount ÷ quanto_multiplier
Floor to integer; must satisfy
order_size_min
.
Mode
:
Switch margin mode only when the user explicitly requests it
switch to isolated only when user explicitly asks for isolated (e.g. "isolated"); switch to cross only when user explicitly asks for cross (e.g. "cross").
If the user does not specify margin mode, do not switch — place the order in the current margin mode
(from position
pos_margin_mode
). If user explicitly wants isolated, check leverage.
Mode switch
only when user
explicitly
requested a margin mode and it
differs from current
(current from position:
pos_margin_mode
), then
before
calling
cex_fx_update_fx_dual_position_cross_mode
get
position mode
via
cex_fx_get_fx_accounts(settle)
→
position_mode
(single/dual); if
position_mode === "single"
, show prompt
"You already have a {currency} position; switching margin mode will apply to this position too. Continue?"
and continue only after user confirms; if
position_mode === "dual"
,
do not
switch—interrupt and tell user
"Please close the position first, then open a new one."
Mode switch (no conflict)
only when user
explicitly
requested cross or isolated and that target differs from current: if no position, or single position and user confirmed, call
Do not switch if the user did not explicitly request a margin mode.
Leverage
if user specified leverage and it
differs from current
(from position query per dual/single above), call
cex_fx_update_fx_dual_position_leverage
in dual mode or
cex_fx_update_fx_position_leverage
in single mode
first
, then proceed.
If user did not specify leverage, do not change it — use the current leverage from the position query for all calculations (e.g. USDT cost formula). Do not default to any value (e.g. 10x or 20x).
Pre-order confirmation
get current leverage from
position query
(dual:
cex_fx_list_fx_positions
or
cex_fx_get_fx_dual_position
; single:
cex_fx_get_fx_position
) for contract + side. Show
final order summary
(contract, side, size, price or market, mode,
leverage
, estimated margin/liq price). Ask user to confirm (e.g. "Reply 'confirm' to place the order.").
Only after user confirms
, place order.
Place order
call
cex_fx_create_fx_order
(market:
tif=ioc
,
price=0
).
Verify
confirm position via
position query
(dual:
cex_fx_list_fx_positions(holding=true)
or
cex_fx_get_fx_dual_position
; single:
cex_fx_get_fx_position
).
Module B: Close position
Position
get current
size
and side via
position query
(dual:
cex_fx_list_fx_positions(settle, holding=true)
or
cex_fx_get_fx_dual_position(settle, contract)
; single:
cex_fx_get_fx_position(settle, contract)
).
Branch
full close (query then close with reduce_only); partial (compute size,
cex_fx_create_fx_order
reduce_only); reverse (close then open opposite in two steps).
Verify
confirm remaining position via same position query as step 1.
Module C: Cancel order
Locate
by order_id, or
cex_fx_list_fx_orders
and let user choose.
Cancel
single
cex_fx_cancel_fx_order
only (no batch cancel).
Verify
:
finish_as
==
cancelled
.
Module D: Amend order
Check
order status must be
open
.
Precision
validate new price/size against contract.
Amend
call
cex_fx_amend_fx_order
to update price or size.
Report template
After each operation, output a short standardized result.
Safety rules
Confirmation
Open
show final order summary (contract, side, size, price/market, mode, leverage, estimated liq/margin), then ask for confirmation before
cex_fx_create_fx_order
. Do
not
add text about mark price vs limit price, order_price_deviate, or suggesting to adjust price. Example:
"Reply 'confirm' to place the order."
Close all, reverse, batch cancel
show scope and ask for confirmation. Example:
"Close all positions? Reply to confirm."
/
"Cancel all orders for this contract. Continue?"
Errors
Code
Action
BALANCE_NOT_ENOUGH
Suggest deposit or lower leverage/size.
PRICE_TOO_DEVIATED
Extract
actual valid price range from the error message
and show to user (do not rely on contract
order_price_deviate
; actual limit depends on risk_limit_tier).
POSITION_HOLDING
(mode switch)
API returns this (not
POSITION_NOT_EMPTY
). Ask user to close position first.
CONTRACT_NOT_FOUND
Contract invalid or not tradeable. Confirm contract name (e.g. BTC_USDT) and settle; suggest listing contracts.
ORDER_NOT_FOUND
Order already filled, cancelled, or wrong order_id. Suggest checking order history.
SIZE_TOO_LARGE
Order size exceeds limit. Suggest reducing size or check contract
order_size_max
.
ORDER_FOK
FOK order could not be filled entirely. Suggest different price/size or use GTC/IOC.
ORDER_POC
POC order would have taken liquidity; exchange rejected. Suggest different price for maker-only.
INVALID_PARAM_VALUE
Often in dual mode when wrong API or params used (e.g.
cex_fx_update_fx_position_cross_mode
or
cex_fx_update_fx_position_leverage
in dual). Use dual-mode APIs:
cex_fx_update_fx_dual_position_cross_mode
,
cex_fx_update_fx_dual_position_leverage
; for position use
cex_fx_list_fx_positions
or
cex_fx_get_fx_dual_position
.