gate-exchange-futures
Original:🇺🇸 English
Translated
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.
3installs
Sourcegate/gate-skills
Added on
NPX Install
npx skill4agent add gate/gate-skills gate-exchange-futuresTags
Translated version includes tags in frontmatterSKILL.md Content
View Translation Comparison →Gate 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, top gainer/loser order | |
| 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", "top gainer long 10U" | 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 - Top gainer/loser: if user requests "top gainer" / "top loser" (or equivalent) instead of a specific contract, call , sort by
list_futures_tickers(settle="usdt")(descending for gainer, ascending for loser), pick the top contract. Then continue the open flow with that contract.changePercentage - Missing: if required params missing (e.g. size), ask user (clarify mode).
2. Pre-flight checks
-
Contract: callto 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). On
order_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): callto get position mode. From response
get_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): callfirst. If
get_futures_accounts(settle)(orposition_mode === "dual"):in_dual_mode === true- Position / leverage query: use or
list_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 use
update_futures_dual_comp_position_cross_mode(settle, contract, mode)in dual mode).update_futures_position_cross_mode - Leverage: use (do not use
update_futures_dual_mode_position_leverage(settle, contract, leverage)in dual mode; it returns array and causes parse error). If single mode: useupdate_futures_position_leveragefor position;get_futures_position(settle, contract)for mode switch;update_futures_dual_comp_position_cross_modefor 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, distinguish between USDT cost ("spend 100U") and USDT value ("100U worth"), get from
quanto_multiplierand best bid/ask fromget_futures_contract:list_futures_order_book(settle, contract, limit=1)- USDT cost (margin-based): open long: ; open short:
contracts = cost / (0.0015 + 1/leverage) / quanto_multiplier / order_price.contracts = cost / (0.0015 + 1.00075/leverage) / quanto_multiplier / max(order_price, best_bid): limit → specified price; market → best ask (long) or best bid (short).order_pricemust come from the current position query (step 5); do not assume a default.leverage - USDT value (notional-based): buy/open long: ; sell/open short:
contracts = usdt_value / price / quanto_multiplier.contracts = usdt_value / max(best_bid, order_price) / quanto_multiplier: limit → specified price; market → best ask (buy) or best bid (sell).price - Base (e.g. BTC, ETH): contracts = base_amount ÷ quanto_multiplier
- Floor to integer; must satisfy .
order_size_min
- USDT cost (margin-based): open long:
- 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 calling
pos_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 with
update_futures_dual_comp_position_cross_mode(settle, contract, mode)modeor"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 or
update_futures_dual_mode_position_leveragein 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).update_futures_position_leverage - Pre-order confirmation: get current leverage from position query (dual: or
list_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: or
list_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:
sizeorlist_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 |
| API returns this (not |
| 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. |