gate-exchange-futures
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseGate Futures Trading Suite
Gate期货交易套件
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.
本Skill是Gate USDT永续合约的唯一入口。它仅支持四种操作:开仓、平仓、撤单、改单。用户的意图会被路由到对应的工作流中。
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 | |
| 模块 | 描述 | 触发关键词 |
|---|---|---|
| Open | 限价/市价开多或开空,全仓/逐仓模式,领涨/领跌合约下单 | |
| Close | 全部平仓、部分平仓、反向仓位 | |
| Cancel | 撤销单个或多个订单 | |
| Amend | 修改订单价格或数量 | |
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 |
| 意图 | 示例短语 | 路由至 |
|---|---|---|
| 开仓 | "BTC long 1 contract", "market short ETH", "10x leverage long", "top gainer long 10U" | 阅读 |
| 平仓 | "close all BTC", "close half", "reverse to short", "close everything" | 阅读 |
| 撤单 | "cancel that buy order", "cancel all orders", "list my orders" | 阅读 |
| 改单 | "change price to 60000", "change order size" | 阅读 |
| 意图不明确 | "help with futures", "show my position" | 澄清:查询仓位/订单,然后引导用户 |
Execution workflow
执行工作流
1. Intent and parameters
1. 意图与参数
- 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).
- 确定对应的模块(Open/Close/Cancel/Amend)。
- 提取参数:、
contract、side、size、price。leverage - 领涨/领跌合约:如果用户请求"top gainer"/"top loser"(或等效表述)而非指定具体合约,则调用接口,按
list_futures_tickers(settle="usdt")(涨跌幅)排序(领涨合约降序,领跌合约升序),选取排名第一的合约。之后使用该合约继续开仓流程。changePercentage - 参数缺失:如果必填参数缺失(如数量),则询问用户(澄清模式)。
2. Pre-flight checks
2. 前置检查
-
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
-
合约验证:调用接口确保合约存在且可交易。
get_futures_contract -
账户检查:检查账户余额及冲突仓位(如切换保证金模式时)。
-
风险检查:不要通过预先计算有效限价(实际偏差限制取决于risk_limit_tier)。当出现
order_price_deviate错误时,从错误信息中提取并展示有效价格范围。PRICE_TOO_DEVIATED -
保证金模式与仓位模式(仅当用户明确请求的保证金模式与当前模式不同时):调用**接口获取仓位模式**。从返回结果的**
get_futures_accounts(settle)**字段判断:position_mode=单向持仓模式,single=双向(对冲)持仓模式。仓位的保证金模式:根据上述单向/双向模式查询仓位 →dual(全仓/逐仓)。如果用户未指定保证金模式,请勿切换;使用当前模式下单。pos_margin_mode- 单向持仓():不要中断流程。提示用户:"您已持有{currency}仓位;切换保证金模式将同时应用于该仓位。是否继续?"(例如:合约BTC_USDT对应currency为BTC)。等待用户确认后继续。
position_mode === "single" - 双向持仓():中断流程。告知用户:"请先平仓,再开新仓。"
position_mode === "dual"
- 单向持仓(
-
双向模式与单向模式(API选择):先调用**接口。如果
get_futures_accounts(settle)(或position_mode === "dual"**):in_dual_mode === true- 仓位/杠杆查询:使用**或
list_futures_positions(settle, holding=true)**。不要在双向模式下使用get_futures_dual_mode_position(settle, contract)接口(API返回数组会导致解析错误)。get_futures_position - 保证金模式切换:使用****(不要在双向模式下使用
update_futures_dual_comp_position_cross_mode(settle, contract, mode))。update_futures_position_cross_mode - 杠杆调整:使用**(不要在双向模式下使用
update_futures_dual_mode_position_leverage(settle, contract, leverage);该接口返回数组会导致解析错误)。 如果是单向模式:使用update_futures_position_leverage查询仓位;使用get_futures_position(settle, contract)切换模式;使用update_futures_dual_comp_position_cross_mode**调整杠杆。update_futures_position_leverage
- 仓位/杠杆查询:使用**
3. Module logic
3. 模块逻辑
Module A: Open position
模块A:开仓
- 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
- 单位转换:如果用户未以合约数指定数量,需区分USDT成本(基于保证金)和USDT面值(基于名义价值),从接口获取
get_futures_contract,从quanto_multiplier接口获取最优买卖价:list_futures_order_book(settle, contract, limit=1)- USDT成本(基于保证金):开多:;开空:
contracts = cost / (0.0015 + 1/leverage) / quanto_multiplier / order_price。contracts = cost / (0.0015 + 1.00075/leverage) / quanto_multiplier / max(order_price, best_bid):限价→指定价格;市价→最优卖价(开多)或最优买价(开空)。order_price必须来自当前仓位查询结果(步骤5);请勿使用默认值。leverage - USDT面值(基于名义价值):买入/开多:;卖出/开空:
contracts = usdt_value / price / quanto_multiplier。contracts = usdt_value / max(best_bid, order_price) / quanto_multiplier:限价→指定价格;市价→最优卖价(买入)或最优买价(卖出)。price - 基础货币(如BTC、ETH):合约数 = 基础货币数量 ÷ quanto_multiplier
- 向下取整为整数;必须满足要求。
order_size_min
- USDT成本(基于保证金):开多:
- 模式设置:仅当用户明确请求时才切换保证金模式:仅当用户明确要求逐仓时切换为逐仓(如提到"isolated");仅当用户明确要求全仓时切换为全仓(如提到"cross")。如果用户未指定保证金模式,请勿切换 — 使用当前仓位的模式下单。如果用户明确要求逐仓,需检查杠杆。
pos_margin_mode - 模式切换(冲突处理):仅当用户明确请求的保证金模式与当前模式(从仓位查询的获取)不同时,在调用
pos_margin_mode接口之前:通过update_futures_dual_comp_position_cross_mode接口获取仓位模式→get_futures_accounts(settle)(单向/双向);如果position_mode,显示提示信息*"您已持有{currency}仓位;切换保证金模式将同时应用于该仓位。是否继续?",仅在用户确认后继续;如果position_mode === "single",请勿切换—中断流程并告知用户"请先平仓,再开新仓。"*position_mode === "dual" - 模式切换(无冲突):仅当用户明确请求全仓或逐仓且目标模式与当前模式不同时:如果无仓位,或单向持仓且用户已确认,调用接口,**
update_futures_dual_comp_position_cross_mode(settle, contract, mode)**参数设为mode或"CROSS"。如果用户未明确请求保证金模式,请勿切换。"ISOLATED" - 杠杆调整:如果用户指定的杠杆与当前杠杆(根据双向/单向模式的仓位查询结果)不同,先调用双向模式下的**接口或单向模式下的
update_futures_dual_mode_position_leverage**接口,再继续流程。如果用户未指定杠杆,请勿修改 — 使用仓位查询得到的当前杠杆进行所有计算(如USDT成本公式)。请勿使用默认值(如10倍或20倍)。update_futures_position_leverage - 下单前确认:从仓位查询(双向模式:或
list_futures_positions;单向模式:get_futures_dual_mode_position)获取合约+方向的当前杠杆。展示最终订单摘要(合约、方向、数量、价格或市价、模式、杠杆、预估保证金/强平价格)。请求用户确认(例如:"回复'confirm'以下单。")。仅在用户确认后下单。get_futures_position - 下单:调用接口(市价单:
create_futures_order,tif=ioc)。price=0 - 验证:通过仓位查询确认仓位(双向模式:或
list_futures_positions(holding=true);单向模式:get_futures_dual_mode_position)。get_futures_position
Module B: Close position
模块B:平仓
- 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.
- 仓位查询:通过仓位查询获取当前和方向(双向模式:
size或list_futures_positions(settle, holding=true);单向模式:get_futures_dual_mode_position(settle, contract))。get_futures_position(settle, contract) - 分支处理:全部平仓(查询后以reduce_only方式平仓);部分平仓(计算数量,调用接口并设置reduce_only);反向操作(分两步:先平仓再开反向仓位)。
create_futures_order - 验证:通过步骤1的同一仓位查询接口确认剩余仓位。
Module C: Cancel order
模块C:撤单
- 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
- 定位订单:通过order_id定位,或调用接口让用户选择。
list_futures_orders - 撤单:仅调用单个接口(不支持批量撤单)。
cancel_futures_order - 验证:确认==
finish_as。cancelled
Module D: Amend order
模块D:改单
- Check: order status must be .
open - Precision: validate new price/size against contract.
- Amend: call to update price or size.
amend_futures_order
- 状态检查:订单状态必须为。
open - 精度验证:验证新价格/数量是否符合合约要求。
- 改单:调用接口更新价格或数量。
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?"
- 开仓:展示最终订单摘要(合约、方向、数量、价格/市价、模式、杠杆、预估强平价格/保证金),然后在调用接口前请求用户确认。不要添加标记价格 vs 限价、order_price_deviate或建议调整价格的文字。示例:"回复'confirm'以下单。"
create_futures_order - 全部平仓、反向操作、批量撤单:展示操作范围并请求确认。示例:"是否全部平仓?回复确认。" / "撤销该合约的所有订单。是否继续?"
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. |
| 错误码 | 处理方式 |
|---|---|
| 建议充值或降低杠杆/数量。 |
| 从错误信息中提取实际有效价格范围并展示给用户(不要依赖合约的 |
| API返回该错误(而非 |
| 合约无效或不可交易。确认合约名称(如BTC_USDT)和结算货币;建议列出可交易合约。 |
| 订单已成交、已撤销或order_id错误。建议查看订单历史。 |
| 订单数量超过限制。建议减少数量或查看合约的 |
| FOK订单无法全部成交。建议调整价格/数量或使用GTC/IOC订单。 |
| POC订单将占用流动性;交易所拒绝该订单。建议调整价格以满足maker-only要求。 |
| 通常在双向模式下使用错误API或参数时出现(如在双向模式下使用 |