一键导入
bitmex-basis-trading
Delta-neutral basis trading between BitMEX perpetuals and fixed-date futures: entry, monitoring, and exit.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Delta-neutral basis trading between BitMEX perpetuals and fixed-date futures: entry, monitoring, and exit.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
Price, funding, liquidation, and balance alerts using polling and WebSocket on bitmex-cli.
Autonomy progression for bitmex-cli agents: from read-only market data to autonomous fund management.
Dollar cost averaging on bitmex-cli: testnet-first, fixed qty per interval, limit orders, and position cap enforcement.
Error category handling, duplicate order prevention, retry logic, and partial fill management for bitmex-cli.
Minimize trading fees on bitmex-cli: maker vs taker, post-only orders, commission tiers, and fee audit.
Capture funding rate payments on BitMEX perpetuals: scan rates, entry, monitoring, yield calculation, and exit.
| name | bitmex-basis-trading |
| version | 1.0.0 |
| description | Delta-neutral basis trading between BitMEX perpetuals and fixed-date futures: entry, monitoring, and exit. |
| metadata | {"openclaw":{"category":"finance"},"requires":{"bins":["bitmex"]},"depends":["bitmex-shared","bitmex-order-execution","bitmex-position-risk"]} |
Basis trading captures the spread between a perpetual and a fixed-date future on the same underlying. The spread converges to zero at expiry, yielding a predictable return when entered at a wide basis.
Always validate on testnet first: prefix commands with bitmex --testnet until the strategy behaves as expected.
basis = (futures_price - perp_price) / perp_price * 100
A positive basis (futures above perp) typically reflects cost-of-carry. The strategy: long perp + short future (or the reverse), targeting convergence.
# Perpetual
PERP=$(bitmex market instrument --symbol XBTUSD -o json 2>/dev/null | \
jq -r '.[0].lastPrice')
# Nearest quarterly future (example: XBTM25)
FUT=$(bitmex market instrument --symbol XBTM25 -o json 2>/dev/null | \
jq -r '.[0].lastPrice')
echo "Perp: $PERP | Future: $FUT"
BASIS=$(echo "scale=6; ($FUT - $PERP) / $PERP * 100" | bc -l)
echo "Basis: ${BASIS}%"
# Days to expiry for annualized estimate
SETTLE=$(bitmex market instrument --symbol XBTM25 -o json 2>/dev/null | \
jq -r '.[0].settle')
echo "Settlement: $SETTLE"
# All active fixed-date futures
bitmex market instrument --active -o json 2>/dev/null | \
jq '[.[] | select(.typ == "FFCCSX") | {symbol, lastPrice, settle, openInterest}]'
Positive basis (futures expensive): short the future, long the perp.
QTY=1000
# Validate both legs
bitmex order buy XBTUSD $QTY --price "$PERP" \
--order-type Limit --exec-inst ParticipateDoNotInitiate \
--validate -o json 2>/dev/null
bitmex order sell XBTM25 $QTY --price "$FUT" \
--order-type Limit --exec-inst ParticipateDoNotInitiate \
--validate -o json 2>/dev/null
# Execute after user confirmation
bitmex order buy XBTUSD $QTY --price "$PERP" \
--order-type Limit --exec-inst ParticipateDoNotInitiate \
-o json 2>/dev/null
bitmex order sell XBTM25 $QTY --price "$FUT" \
--order-type Limit --exec-inst ParticipateDoNotInitiate \
-o json 2>/dev/null
# Check current basis
PERP_NOW=$(bitmex market instrument --symbol XBTUSD -o json 2>/dev/null | jq -r '.[0].lastPrice')
FUT_NOW=$(bitmex market instrument --symbol XBTM25 -o json 2>/dev/null | jq -r '.[0].lastPrice')
BASIS_NOW=$(echo "scale=6; ($FUT_NOW - $PERP_NOW) / $PERP_NOW * 100" | bc -l)
echo "Current basis: ${BASIS_NOW}%"
# Check both legs' PnL
bitmex position list -o json 2>/dev/null | \
jq '[.[] | select(.symbol == "XBTUSD" or .symbol == "XBTM25") | {symbol, currentQty, unrealisedPnl, realisedPnl}]'
Exit both legs simultaneously when basis is near zero or at expiry:
TARGET_BASIS=0.1 # exit if basis below 0.1%
if [ "$(echo "${BASIS_NOW#-} < $TARGET_BASIS" | bc -l)" = "1" ]; then
echo "Basis converged: ${BASIS_NOW}% — exiting both legs"
# Close perp leg
bitmex order close-position XBTUSD -o json 2>/dev/null
# Close futures leg
bitmex order close-position XBTM25 -o json 2>/dev/null
fi
# Annualized carry for a given basis and days to expiry
DAYS=90
echo "scale=4; $BASIS / $DAYS * 365" | bc -l
# e.g., 2% basis over 90 days = ~8.1% annualized