BAiSEDagent

futures-trading

0
0
# Install this skill:
npx skills add BAiSEDagent/openclaw-skills --skill "futures-trading"

Install specific skill from multi-skill repository

# Description

Perpetual futures trading on Base. Position management, funding rates, liquidation. Use when building or executing futures trading strategies.

# SKILL.md


name: futures-trading
description: "Perpetual futures trading on Base. Position management, funding rates, liquidation. Use when building or executing futures trading strategies."
metadata:
openclaw:
emoji: "πŸ“Š"


Futures Trading on Base

Perpetual futures (perps) allow leveraged directional bets without expiry. Key protocols on Base.

Perps Protocols on Base

Protocol Type Leverage Key Feature
Synthetix Perps V3 Orderbook-like Up to 50x Deep liquidity via SNX stakers
Kwenta Frontend for Synthetix Up to 50x Best UI for Synthetix perps
Perpetual Protocol vAMM Up to 10x Established, multi-chain
Vertex Hybrid DEX Up to 20x Orderbook + AMM
BMX GMX fork Up to 50x Base-native

Core Concepts

Perpetual Futures

  • No expiry β€” positions stay open indefinitely
  • Funding rate: Periodic payment between longs and shorts to keep price aligned with spot
  • Positive funding = longs pay shorts (market is bullish)
  • Negative funding = shorts pay longs (market is bearish)

Position Anatomy

interface Position {
  market: string;           // 'ETH-USD'
  side: 'long' | 'short';
  size: bigint;             // Position size in base asset
  entryPrice: bigint;       // Average entry price
  leverage: number;         // 1x - 50x
  margin: bigint;           // Collateral (USDC)
  liquidationPrice: bigint; // Price at which position is liquidated
  unrealizedPnl: bigint;   // Current profit/loss
  fundingAccrued: bigint;   // Accumulated funding payments
}

PnL Calculation

function calculatePnL(position: Position, currentPrice: bigint): bigint {
  const priceDiff = currentPrice - position.entryPrice;
  const rawPnl = position.side === 'long'
    ? (priceDiff * position.size) / PRICE_PRECISION
    : (-priceDiff * position.size) / PRICE_PRECISION;
  return rawPnl - position.fundingAccrued;
}

Liquidation Price

function liquidationPrice(position: Position): bigint {
  const maintenanceMargin = position.size * MAINTENANCE_MARGIN_RATIO / PRECISION;
  if (position.side === 'long') {
    return position.entryPrice - ((position.margin - maintenanceMargin) * PRICE_PRECISION) / position.size;
  } else {
    return position.entryPrice + ((position.margin - maintenanceMargin) * PRICE_PRECISION) / position.size;
  }
}

Synthetix Perps V3 Integration

// Open a long position
const marketId = 100; // ETH-USD on Base
const sizeDelta = parseEther('0.1'); // 0.1 ETH long
const acceptablePrice = currentPrice * 101n / 100n; // 1% slippage

const tx = await perpsMarket.commitOrder({
  marketId,
  accountId,
  sizeDelta,
  settlementStrategyId: 0,
  acceptablePrice,
  referrer: ethers.ZeroAddress,
  trackingCode: ethers.encodeBytes32String('baisedagent'),
});

// Order settles after delay (async settlement)

Funding Rate Strategy

// Funding rate arbitrage: collect funding on favorable side
async function checkFundingOpportunity(marketId: number) {
  const fundingRate = await perpsMarket.currentFundingRate(marketId);
  const annualized = fundingRate * 365 * 24; // Hourly β†’ annualized

  if (annualized > 0.20) { // >20% APR for shorts
    return { action: 'short', reason: 'High positive funding β€” shorts earn' };
  }
  if (annualized < -0.20) { // >20% APR for longs
    return { action: 'long', reason: 'High negative funding β€” longs earn' };
  }
  return { action: 'none', reason: 'Funding rate not attractive' };
}

Risk Management

  • Position sizing: Never risk >2% of portfolio on a single trade
  • Stop losses: Always set, preferably on-chain
  • Max leverage: Start with 2-5x, never exceed 10x without explicit approval
  • Funding monitoring: Check funding rates before holding positions overnight
  • Correlation risk: Don't stack same-direction bets across correlated assets
  • Human approval: Required for any position >$100 notional

Safety Rules

  • ⚠️ No autonomous trading without explicit human approval
  • ⚠️ Always calculate liquidation price before opening position
  • ⚠️ Monitor positions β€” liquidation = total loss of margin
  • Paper trade first, live trade with tiny amounts, scale up with track record

Cross-References

  • spot-trading: Underlying spot markets
  • leverage-trading: General leverage patterns (Aave, Compound)
  • agent-wallet-management: Fund management for margin
  • onchain-analytics: Trade performance analysis

# Supported AI Coding Agents

This skill is compatible with the SKILL.md standard and works with all major AI coding agents:

Learn more about the SKILL.md standard and how to use these skills with your preferred AI coding agent.