원클릭으로
bitmex-rebalancing
Rebalancing positions on bitmex-cli: check allocations, calculate deltas, place orders, and validate on testnet.
Codex 또는 Claude로 설치 이 Prompt를 복사해 Codex, Claude 또는 다른 어시스턴트에 붙여 넣으면 Skill 페이지를 검토하고 설치를 진행할 수 있습니다.
메뉴
Rebalancing positions on bitmex-cli: check allocations, calculate deltas, place orders, and validate on testnet.
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.
Delta-neutral basis trading between BitMEX perpetuals and fixed-date futures: entry, monitoring, and exit.
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.
| name | bitmex-rebalancing |
| version | 1.0.0 |
| description | Rebalancing positions on bitmex-cli: check allocations, calculate deltas, place orders, and validate on testnet. |
| metadata | {"openclaw":{"category":"finance"},"requires":{"bins":["bitmex"]},"depends":["bitmex-shared","bitmex-order-execution","bitmex-position-risk"]} |
Rebalancing adjusts current positions toward target allocations. On BitMEX, this means adding to or reducing perpetual/futures positions, not converting between currencies.
# All open positions with mark-to-market value
bitmex position list -o json 2>/dev/null | \
jq '[.[] | select(.isOpen == true) | {
symbol,
currentQty,
markPrice,
notional: (.currentQty * .markPrice),
unrealisedPnl
}]'
# Total wallet balance
bitmex wallet balance --currency XBt -o json 2>/dev/null | \
jq '{currency, amount}'
# Account margin summary
bitmex account margin --currency XBt -o json 2>/dev/null | \
jq '{marginBalance, availableMargin, unrealisedPnl}'
Example: 60% long XBTUSD, 40% long ETHUSD by notional.
MARGIN=$(bitmex account margin --currency XBt -o json 2>/dev/null | jq -r '.marginBalance')
echo "Total margin (satoshis): $MARGIN"
# Target notional per symbol (in USD equivalent)
# These are user-defined constants
TARGET_XBTUSD=6000 # contracts
TARGET_ETHUSD=4000 # contracts
MIN_REBAL_QTY=50 # ignore deltas smaller than this
CURRENT_XBT=$(bitmex position list --symbol XBTUSD -o json 2>/dev/null | \
jq -r '.[0].currentQty // 0')
CURRENT_ETH=$(bitmex position list --symbol ETHUSD -o json 2>/dev/null | \
jq -r '.[0].currentQty // 0')
DELTA_XBT=$((TARGET_XBTUSD - CURRENT_XBT))
DELTA_ETH=$((TARGET_ETHUSD - CURRENT_ETH))
echo "XBTUSD: current=$CURRENT_XBT target=$TARGET_XBTUSD delta=$DELTA_XBT"
echo "ETHUSD: current=$CURRENT_ETH target=$TARGET_ETHUSD delta=$DELTA_ETH"
FLAG="--testnet"
# Validate XBTUSD rebalance
if [ "${DELTA_XBT#-}" -ge "$MIN_REBAL_QTY" ]; then
if [ "$DELTA_XBT" -gt 0 ]; then
SIDE="buy"; QTY=$DELTA_XBT
else
SIDE="sell"; QTY=${DELTA_XBT#-}
fi
OB_SIDE=$([ "$SIDE" = "buy" ] && echo "Buy" || echo "Sell")
PRICE=$(bitmex $FLAG market orderbook XBTUSD --depth 1 -o json 2>/dev/null | \
jq --arg s "$OB_SIDE" '[.[] | select(.side == $s)] | .[0].price')
bitmex $FLAG order $SIDE XBTUSD $QTY --price "$PRICE" \
--order-type Limit --validate -o json 2>/dev/null | \
jq '{side, ordQty, price, ordType}'
fi
place_rebal_order() {
local SYMBOL=$1
local DELTA=$2
ABS_DELTA=${DELTA#-}
if [ "$ABS_DELTA" -lt "$MIN_REBAL_QTY" ]; then
echo "$SYMBOL delta $DELTA below threshold, skipping"
return 0
fi
if [ "$DELTA" -gt 0 ]; then
SIDE="buy"
PRICE=$(bitmex market orderbook $SYMBOL --depth 1 -o json 2>/dev/null | jq '[.[] | select(.side == "Buy")] | .[0].price')
else
SIDE="sell"
PRICE=$(bitmex market orderbook $SYMBOL --depth 1 -o json 2>/dev/null | jq '[.[] | select(.side == "Sell")] | .[0].price')
fi
echo "Rebalancing $SYMBOL: $SIDE $ABS_DELTA @ $PRICE"
bitmex order $SIDE $SYMBOL $ABS_DELTA \
--price "$PRICE" \
--order-type Limit \
--exec-inst ParticipateDoNotInitiate \
-o json 2>/dev/null | jq '{orderID, side, price, ordQty}'
}
# Execute after user confirmation
place_rebal_order "XBTUSD" "$DELTA_XBT"
place_rebal_order "ETHUSD" "$DELTA_ETH"
sleep 10
bitmex position list -o json 2>/dev/null | \
jq '[.[] | select(.isOpen == true) | {symbol, currentQty, unrealisedPnl}]'
Always enforce MIN_REBAL_QTY to avoid excessive small orders that erode returns with fees. A good threshold is 1–5% of target position size.