DeFi Trading

DeFi Trading Integrations

Overview

VIBE AI agents can trade autonomously on decentralized exchanges and manage DeFi positions.

Supported Platforms

1. Solana DEXes (Jupiter + Meteora)

High-performance decentralized trading on Solana

FeatureDescription
Jupiter AggregatorBest price routing across all Solana DEXes
Meteora DLMMDynamic liquidity market maker pools
NetworksSolana mainnet + devnet
SpeedSub-second confirmations
Fees~$0.00025 per transaction

Configuration

solana_wallet:
  enabled: true
  network: "mainnet"

  trading:
    max_position_size: "1000"  # USD
    slippage_tolerance: "0.5"  # percent
    priority_fee: "auto"  # or specific lamports

Tools

# Get token price via Jupiter
price = await jupiter.get_token_price("SOL")

# Get swap quote
quote = await jupiter.get_swap_quote(
    input_mint="So11111111111111111111111111111111111111112",  # SOL
    output_mint="EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",  # USDC
    amount=1000000000,  # 1 SOL in lamports
    slippage_bps=50  # 0.5%
)

# Execute swap
result = await jupiter.execute_swap(
    quote=quote,
    wallet_address=wallet_address
)

# Meteora DLMM pools
pools = await meteora.get_active_pools()
position = await meteora.add_liquidity(
    pool_address=pool_address,
    amount_a=1000,
    amount_b=1000
)

2. Hyperliquid

High-performance perpetual and spot DEX

FeatureDescription
PerpetualsUp to 50x leverage
SpotDirect token trading
Order TypesMarket, Limit, Stop
APIREST + WebSocket

Configuration

hyperliquid:
  enabled: true
  network: "mainnet"
  wallet_type: "agent"  # Hyperliquid agent wallet
  
  trading:
    max_position_size: "1000"  # USDC
    max_leverage: 10
    allowed_markets: ["BTC-PERP", "ETH-PERP"]

Tools

# Get market data
await hyperliquid.get_price("BTC-PERP")
await hyperliquid.get_orderbook("BTC-PERP")
await hyperliquid.get_funding_rate("BTC-PERP")

# Trading
await hyperliquid.place_order(
    market="BTC-PERP",
    side="buy",
    size=0.1,
    order_type="limit",
    price=50000
)

# Position management
await hyperliquid.get_positions()
await hyperliquid.close_position("BTC-PERP")

3. CDP Trade API (Uniswap)

Token swaps via DEX aggregation

FeatureDescription
DEXesUniswap, SushiSwap, Curve
NetworksEthereum
RoutingBest price aggregation
GasAuto-sponsored

Configuration

cdp_trade:
  enabled: true
  network: "ethereum"
  
  settings:
    slippage_tolerance: "0.5"  # percent
    gas_sponsorship: true

Tools

# Get swap quote
quote = await cdp.get_swap_quote(
    from_token="ETH",
    to_token="USDC",
    amount="1.0"
)

# Execute swap
result = await cdp.execute_swap(
    from_token="ETH",
    to_token="USDC",
    amount="1.0",
    slippage="0.5"
)

4. Polymarket (Prediction Markets)

Bet on real-world outcomes

FeatureDescription
MarketsPolitics, Sports, Crypto
Order BookCLOB-based
SettlementUSDC

Tools

# Browse markets
markets = await polymarket.search_markets("AI regulation")

# Get market details
market = await polymarket.get_market(market_id)

# Place bet
await polymarket.place_order(
    market_id=market_id,
    outcome="Yes",
    amount=100,  # USDC
    price=0.65  # 65 cents per share
)

# Check positions
positions = await polymarket.get_positions()

Trading Strategies

1. Funding Rate Arbitrage

# Monitor funding rates across perpetuals
async def funding_arbitrage():
    while True:
        rate = await hyperliquid.get_funding_rate("BTC-PERP")
        
        if rate > 0.01:  # High positive rate
            # Short perp, long spot
            await hyperliquid.place_order("BTC-PERP", "sell", 1)
            await cdp.execute_swap("USDC", "BTC", 1)
            
        await asyncio.sleep(3600)

2. DCA (Dollar Cost Averaging)

# Automated DCA strategy
@trigger(cron="0 12 * * *")  # Daily at noon
async def daily_btc_dca():
    await cdp.execute_swap(
        from_token="USDC",
        to_token="BTC",
        amount="100"
    )

3. Rebalancing

# Portfolio rebalancing
async def rebalance_portfolio():
    portfolio = await get_portfolio()
    target = {"BTC": 0.5, "ETH": 0.3, "USDC": 0.2}
    
    for asset, target_pct in target.items():
        current_pct = portfolio[asset] / portfolio.total
        diff = target_pct - current_pct
        
        if abs(diff) > 0.05:  # 5% threshold
            # Rebalance
            await execute_rebalance(asset, diff)

Risk Management

Position Limits

risk_management:
  max_position_size: "1000"  # USDC per position
  max_total_exposure: "5000"  # Total USDC at risk
  max_loss_per_day: "200"
  
  stop_loss:
    enabled: true
    default_percentage: 5

Kill Switch

# Emergency stop all trading
@trigger(condition="daily_loss > 200")
async def emergency_stop():
    await close_all_positions()
    await disable_trading()
    await notify_user("Trading disabled: daily loss limit reached")

Resources


Next: Prediction Markets →