swap module

May 12, 2026 · View on GitHub

Perpetual contract (SWAP) trading tools. Requires API key with Read + Trade permissions.

Tools

ToolDescription
swap_place_orderPlace a perpetual contract order
swap_cancel_orderCancel an open swap order
swap_amend_orderAmend price or size of an open order
swap_batch_place_ordersPlace up to 20 orders in a single request
swap_batch_cancel_ordersCancel multiple orders in a single request
swap_close_positionClose all positions for an instrument
swap_get_orderGet details of a single order
swap_get_open_ordersList currently open orders
swap_get_order_historyOrder history (last 7 days)
swap_get_positionsCurrent open positions
swap_get_fillsRecent fills
swap_set_leverageSet leverage for an instrument
swap_get_leverageGet current leverage settings

Example prompts

  • "Open a long position on BTC-USDT-SWAP with 1 contract at market price, 10x leverage, cross margin"
  • "What are my current perpetual positions?"
  • "Close my BTC-USDT-SWAP position"
  • "Set leverage to 5x for ETH-USDT-SWAP"
  • "Show my open swap orders"

Key parameters

ParameterValuesDescription
tdModecross, isolatedMargin mode
posSidelong, short, netPosition side (net for one-way mode)
sidebuy, sellOrder side
ordTypemarket, limit, post_only, fok, iocOrder type

CLI

# View positions and orders
okx swap positions
okx swap orders --history
okx swap get --instId BTC-USDT-SWAP --ordId 123456
okx swap fills --instId BTC-USDT-SWAP

# Place and manage orders
okx swap place --instId BTC-USDT-SWAP --side buy --ordType market --sz 1 --posSide long --tdMode cross
# With attached TP/SL
okx swap place --instId BTC-USDT-SWAP --side buy --ordType market --sz 1 --posSide long --tdMode cross \
  --tpTriggerPx 100000 --tpOrdPx 99900 --slTriggerPx 85000 --slOrdPx 84900
okx swap cancel BTC-USDT-SWAP --ordId 123456
okx swap close --instId BTC-USDT-SWAP --mgnMode cross

# Leverage
okx swap leverage --instId BTC-USDT-SWAP --lever 10 --mgnMode cross
okx swap get-leverage --instId BTC-USDT-SWAP --mgnMode cross

swap 模块

永续合约交易工具。需要 API Key,开启 读取 + 交易 权限。

工具列表

工具说明
swap_place_order下永续合约单
swap_cancel_order撤销挂单
swap_amend_order改价或改量
swap_batch_place_orders批量下单(最多20笔)
swap_batch_cancel_orders批量撤单
swap_close_position一键平仓(指定合约)
swap_get_order查询单笔订单详情
swap_get_open_orders查询当前挂单
swap_get_order_history历史订单(7天内)
swap_get_positions当前持仓
swap_get_fills最新成交记录
swap_set_leverage设置杠杆倍数
swap_get_leverage查询当前杠杆设置

示例提示词

  • "以市价开 BTC-USDT-SWAP 多仓,1张,10倍杠杆,全仓模式"
  • "查看我当前的永续合约持仓"
  • "平掉我的 BTC-USDT-SWAP 仓位"
  • "将 ETH-USDT-SWAP 杠杆设为5倍"
  • "显示我当前的永续挂单"

关键参数

参数可选值说明
tdModecross, isolated保证金模式(全仓/逐仓)
posSidelong, short, net持仓方向(单向模式用 net)
sidebuy, sell买卖方向
ordTypemarket, limit, post_only, fok, ioc订单类型

CLI

# 查询持仓和订单
okx swap positions
okx swap orders --history
okx swap get --instId BTC-USDT-SWAP --ordId 123456
okx swap fills --instId BTC-USDT-SWAP

# 下单和管理
okx swap place --instId BTC-USDT-SWAP --side buy --ordType market --sz 1 --posSide long --tdMode cross
# 附带止盈止损
okx swap place --instId BTC-USDT-SWAP --side buy --ordType market --sz 1 --posSide long --tdMode cross \
  --tpTriggerPx 100000 --tpOrdPx 99900 --slTriggerPx 85000 --slOrdPx 84900
okx swap cancel BTC-USDT-SWAP --ordId 123456
okx swap close --instId BTC-USDT-SWAP --mgnMode cross

# 杠杆
okx swap leverage --instId BTC-USDT-SWAP --lever 10 --mgnMode cross
okx swap get-leverage --instId BTC-USDT-SWAP --mgnMode cross