Marketplace gate-exchange-futures
The USDT perpetual futures trading function of Gate Exchange: open position, close position, cancel order, amend order. Trigger phrases: open position, close position, cancel order, amend order, reverse, close all.
git clone https://github.com/aiskillstore/marketplace
T=$(mktemp -d) && git clone --depth=1 https://github.com/aiskillstore/marketplace "$T" && mkdir -p ~/.claude/skills && cp -r "$T/skills/gate/gate-exchange-futures" ~/.claude/skills/aiskillstore-marketplace-gate-exchange-futures && rm -rf "$T"
skills/gate/gate-exchange-futures/SKILL.mdGate Futures Trading Suite
This skill is the single entry for Gate USDT perpetual futures. It supports four operations only: open position, close position, cancel order, amend order. User intent is routed to the matching workflow.
Module overview
| Module | Description | Trigger keywords |
|---|---|---|
| Open | Limit/market open long or short, cross/isolated mode | , , , , |
| Close | Full close, partial close, reverse position | , , |
| Cancel | Cancel one or many orders | , |
| Amend | Change order price or size | , |
Routing rules
| Intent | Example phrases | Route to |
|---|---|---|
| Open position | "BTC long 1 contract", "market short ETH", "10x leverage long" | Read |
| Close position | "close all BTC", "close half", "reverse to short", "close everything" | Read |
| Cancel orders | "cancel that buy order", "cancel all orders", "list my orders" | Read |
| Amend order | "change price to 60000", "change order size" | Read |
| Unclear | "help with futures", "show my position" | Clarify: query position/orders, then guide user |
Execution workflow
1. Intent and parameters
- Determine module (Open/Close/Cancel/Amend).
- Extract:
,contract
,side
,size
,price
.leverage - Missing: if required params missing (e.g. size), ask user (clarify mode).
2. Pre-flight checks
-
Contract: call
to ensure contract exists and is tradeable.get_futures_contract -
Account: check balance and conflicting positions (e.g. when switching margin mode).
-
Risk: do not pre-calculate valid limit price from
(actual deviation limit depends on risk_limit_tier). Onorder_price_deviate
, show the valid range from the error message.PRICE_TOO_DEVIATED -
Margin mode vs position mode (only when user explicitly requested a margin mode and it differs from current): call
to get position mode. From responseget_futures_accounts(settle)
:position_mode
= single position mode,single
= dual (hedge) position mode. Margin mode from position: use position query per dual/single above →dual
(cross/isolated). If user did not specify margin mode, do not switch; place order in current mode.pos_margin_mode- Single position (
): do not interrupt. Prompt user: "You already have a {currency} position; switching margin mode will apply to this position too. Continue?" (e.g. currency from contract: BTC_USDT → BTC). Wait for user confirmation, then continue.position_mode === "single" - Dual position (
): interrupt flow. Tell user: "Please close the position first, then open a new one."position_mode === "dual"
- Single position (
-
Dual mode vs single mode (API choice): call
first. Ifget_futures_accounts(settle)
(orposition_mode === "dual"
):in_dual_mode === true- Position / leverage query: use
orlist_futures_positions(settle, holding=true)
. Do not useget_futures_dual_mode_position(settle, contract)
in dual mode (API returns an array and causes parse error).get_futures_position - Margin mode switch: use
(do not useupdate_futures_dual_comp_position_cross_mode(settle, contract, mode)
in dual mode).update_futures_position_cross_mode - Leverage: use
(do not useupdate_futures_dual_mode_position_leverage(settle, contract, leverage)
in dual mode; it returns array and causes parse error). If single mode: useupdate_futures_position_leverage
for position;get_futures_position(settle, contract)
for mode switch;update_futures_dual_comp_position_cross_mode
for leverage.update_futures_position_leverage
- Position / leverage query: use
3. Module logic
Module A: Open position
- Unit conversion: if user does not specify size in contracts, get
,mark_price
fromquanto_multiplier
, then convert:get_futures_contract- U (USDT notional): contracts = u ÷ mark_price ÷ quanto_multiplier (no leverage); with leverage: contracts = u × leverage ÷ mark_price ÷ quanto_multiplier
- Base (e.g. BTC, ETH): contracts = base_amount ÷ quanto_multiplier
- Round/truncate to
and size precision.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
). If user explicitly wants isolated, check leverage.pos_margin_mode - Mode switch: only when user explicitly requested a margin mode and it differs from current (current from position:
), then before callingpos_margin_mode
: get position mode viaupdate_futures_dual_comp_position_cross_mode
→get_futures_accounts(settle)
(single/dual); ifposition_mode
, show prompt "You already have a {currency} position; switching margin mode will apply to this position too. Continue?" and continue only after user confirms; ifposition_mode === "single"
, do not switch—interrupt and tell user "Please close the position first, then open a new one."position_mode === "dual" - 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
withupdate_futures_dual_comp_position_cross_mode(settle, contract, mode)mode
or"CROSS"
. Do not switch if the user did not explicitly request a margin mode."ISOLATED" - Leverage: if user specified leverage and it differs from current (from position query per dual/single above), call
in dual mode orupdate_futures_dual_mode_position_leverage
in single mode first, then proceed.update_futures_position_leverage - Pre-order confirmation: get current leverage from position query (dual:
orlist_futures_positions
; single:get_futures_dual_mode_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.get_futures_position - Place order: call
(market:create_futures_order
,tif=ioc
).price=0 - Verify: confirm position via position query (dual:
orlist_futures_positions(holding=true)
; single:get_futures_dual_mode_position
).get_futures_position
Module B: Close position
- Position: get current
and side via position query (dual:size
orlist_futures_positions(settle, holding=true)
; single:get_futures_dual_mode_position(settle, contract)
).get_futures_position(settle, contract) - Branch: full close (query then close with reduce_only); partial (compute size,
reduce_only); reverse (close then open opposite in two steps).create_futures_order - Verify: confirm remaining position via same position query as step 1.
Module C: Cancel order
- Locate: by order_id, or
and let user choose.list_futures_orders - Cancel: single
only (no batch cancel).cancel_futures_order - Verify:
==finish_as
.cancelled
Module D: Amend order
- Check: order status must be
.open - Precision: validate new price/size against contract.
- Amend: call
to update price or size.amend_futures_order
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
. 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."create_futures_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 |
|---|---|
| Suggest deposit or lower leverage/size. |
| Extract actual valid price range from the error message and show to user (do not rely on contract ; actual limit depends on risk_limit_tier). |
(mode switch) | API returns this (not ). Ask user to close position first. |
| Contract invalid or not tradeable. Confirm contract name (e.g. BTC_USDT) and settle; suggest listing contracts. |
| Order already filled, cancelled, or wrong order_id. Suggest checking order history. |
| Order size exceeds limit. Suggest reducing size or check contract . |
| FOK order could not be filled entirely. Suggest different price/size or use GTC/IOC. |
| POC order would have taken liquidity; exchange rejected. Suggest different price for maker-only. |
| Often in dual mode when wrong API or params used (e.g. or in dual). Use dual-mode APIs: , ; for position use or . |