DERIVATIVES API

Options & Futures Derivatives API for Agents

Trade perpetuals, options (calls/puts), structured products, and variance swaps across dYdX, GMX, Hyperliquid, Lyra, Dopex, and Ribbon Finance. Full Greeks, IV surface, and strategy automation.

Get API Key → Read the Docs
40+
Derivative Instruments
<50ms
Order Execution
6
Exchanges Supported
275+
Total Markets

// SUPPORTED EXCHANGES

Trade Across 6 Major Exchanges

One unified API abstracts the differences between each protocol's margin models, settlement mechanics, and order types.

dYdX — Perpetuals & Spot
GMX v2 — Perps + Options
Hyperliquid — Sub-50ms Perps
Lyra Finance — Options AMM
Dopex — Options vaults
Ribbon Finance — Structured

Perpetual Futures

Cross-margin and isolated-margin perpetuals on BTC, ETH, SOL, and 50+ altcoins. Up to 50x leverage. Funding rate tracking and automated position rebalancing on rate spikes.

📋
Vanilla Options

European-style calls and puts on BTC and ETH. Choose expiry from weekly to quarterly. Full Greeks returned on every order: delta, gamma, theta, vega, rho.

🎉
Structured Products

Access Ribbon Finance theta vaults and Dopex single-staking option vaults (SSOVs). Earn yield by systematically selling covered calls or cash-secured puts.

📈
Variance Swaps

Trade realized vs implied volatility directly. Long variance if you expect a volatility spike; short variance to harvest the volatility risk premium in calm markets.


// API REFERENCE

Derivatives Endpoints

Every order, risk query, and strategy execution flows through these four core endpoints.

POST
/v1/derivatives/order
Place any derivative order: market, limit, or stop. Specify instrument (perp, call, put), exchange, side (buy/sell), size, leverage, and optional strategy tag for portfolio tracking.
GET
/v1/derivatives/greeks
Retrieve real-time Greeks (delta, gamma, theta, vega, rho) for any options contract or portfolio position. Supports portfolio-level aggregation across all open positions.
GET
/v1/derivatives/volatility-surface
Fetch the full implied volatility surface as a matrix of strike vs. expiry. Includes term structure, skew metrics, and ATM vol for model calibration. Updated every 5 seconds.
POST
/v1/derivatives/strategies/execute
Execute multi-leg strategies atomically: Iron Condor, Straddle, Strangle, Butterfly, Calendar Spread, and Risk Reversal. All legs placed simultaneously to minimize leg risk.

// RISK ANALYTICS

Greeks & IV Surface

Every options position returns a full Greek profile in real-time. Portfolio-level Greeks let your agent manage net exposure across legs automatically.

Δ
Delta
Rate of change of option price relative to a $1 move in the underlying. Drives hedging requirements.
Γ
Gamma
Rate of change of delta. High gamma near expiry requires more frequent re-hedging of the delta.
Θ
Theta
Daily time decay in option premium. Negative for long options; positive for sellers of premium.
ν
Vega
Sensitivity to a 1% change in implied volatility. Critical for vol-trading strategies.

// BTC Implied Volatility Surface — Live

7d
14d
30d
60d
90d
+20%
82%
74%
68%
65%
62%
+10%
71%
66%
61%
58%
56%
ATM
62%
58%
55%
52%
50%
-10%
69%
64%
60%
57%
55%
-20%
88%
78%
72%
68%
65%
Negative skew: put IV > call IV (downside protection premium). Term: backwardation 7d.

// AGENT EXAMPLE

Options Strategy Builder — Iron Condor & Straddle

A complete Python class for constructing and executing multi-leg options strategies with automated Greeks monitoring.

options_strategy_builder.py
"""
Purple Flea Derivatives Agent — Options Strategy Builder
Supports Iron Condor, Straddle, and Strangle construction.
"""

import requests
from dataclasses import dataclass, field
from typing import Literal
import time

API_KEY = "pf_live_your_key_here"
BASE_URL = "https://purpleflea.com/v1/derivatives"

@dataclass
class Greeks:
    delta: float
    gamma: float
    theta: float
    vega: float
    rho: float

@dataclass
class OptionLeg:
    instrument: str       # e.g. "BTC-28MAR26-90000-C"
    side: str             # "buy" or "sell"
    contracts: int
    exchange: str = "lyra"

@dataclass
class StrategyResult:
    strategy_id: str
    legs: list[OptionLeg]
    net_premium: float    # + = credit, - = debit
    greeks: Greeks
    max_profit: float
    max_loss: float
    breakeven_low: float
    breakeven_high: float

class OptionsStrategyBuilder:
    """Build and execute multi-leg options strategies via Purple Flea."""

    def __init__(self, api_key: str):
        self.headers = {
            "Authorization": f"Bearer {api_key}",
            "Content-Type": "application/json",
        }

    def get_volatility_surface(self, underlying: str = "BTC") -> dict:
        """Fetch the full IV surface for an underlying asset."""
        resp = requests.get(
            f"{BASE_URL}/volatility-surface",
            params={"underlying": underlying},
            headers=self.headers,
            timeout=10,
        )
        resp.raise_for_status()
        return resp.json()

    def iron_condor(
        self,
        underlying: str,
        expiry: str,
        lower_put_strike: float,
        upper_put_strike: float,
        lower_call_strike: float,
        upper_call_strike: float,
        contracts: int = 1,
    ) -> StrategyResult:
        """
        Construct an Iron Condor: 4 legs.
          Buy  lower put  (wing protection)
          Sell upper put  (short put spread body)
          Sell lower call (short call spread body)
          Buy  upper call (wing protection)

        Profits when underlying stays between the two short strikes at expiry.
        """
        legs = [
            {"instrument": f"{underlying}-{expiry}-{lower_put_strike}-P",
             "side": "buy", "contracts": contracts, "exchange": "lyra"},
            {"instrument": f"{underlying}-{expiry}-{upper_put_strike}-P",
             "side": "sell", "contracts": contracts, "exchange": "lyra"},
            {"instrument": f"{underlying}-{expiry}-{lower_call_strike}-C",
             "side": "sell", "contracts": contracts, "exchange": "lyra"},
            {"instrument": f"{underlying}-{expiry}-{upper_call_strike}-C",
             "side": "buy", "contracts": contracts, "exchange": "lyra"},
        ]
        return self._execute_strategy("iron_condor", legs)

    def straddle(
        self,
        underlying: str,
        expiry: str,
        atm_strike: float,
        side: Literal["buy", "sell"] = "buy",
        contracts: int = 1,
    ) -> StrategyResult:
        """
        Long Straddle: buy ATM call + ATM put.
        Profits from large moves in either direction.
        Short Straddle: sell both — collects premium when vol is high.
        """
        opposite = "sell" if side == "buy" else "buy"
        legs = [
            {"instrument": f"{underlying}-{expiry}-{atm_strike}-C",
             "side": side, "contracts": contracts, "exchange": "lyra"},
            {"instrument": f"{underlying}-{expiry}-{atm_strike}-P",
             "side": side, "contracts": contracts, "exchange": "lyra"},
        ]
        strategy_name = f"{'long' if side == 'buy' else 'short'}_straddle"
        return self._execute_strategy(strategy_name, legs)

    def _execute_strategy(self, name: str, legs: list[dict]) -> StrategyResult:
        """Submit strategy to the Purple Flea execute endpoint."""
        payload = {"strategy": name, "legs": legs, "atomic": True}
        resp = requests.post(
            f"{BASE_URL}/strategies/execute",
            json=payload,
            headers=self.headers,
            timeout=20,
        )
        resp.raise_for_status()
        data = resp.json()
        return StrategyResult(
            strategy_id=data["strategy_id"],
            legs=[OptionLeg(**leg) for leg in data["legs"]],
            net_premium=data["net_premium"],
            greeks=Greeks(**data["greeks"]),
            max_profit=data["max_profit"],
            max_loss=data["max_loss"],
            breakeven_low=data["breakeven_low"],
            breakeven_high=data["breakeven_high"],
        )

# --- Example Usage ---
if __name__ == "__main__":
    builder = OptionsStrategyBuilder(API_KEY)

    # Check IV surface first to identify rich vol environments
    surface = builder.get_volatility_surface("BTC")
    atm_iv = surface["atm_iv_30d"]
    print(f"BTC 30d ATM IV: {atm_iv:.1%}")

    if atm_iv > 0.60:   # IV above 60% — sell premium
        result = builder.iron_condor(
            underlying="BTC",
            expiry="28MAR26",
            lower_put_strike=75000,
            upper_put_strike=80000,
            lower_call_strike=100000,
            upper_call_strike=105000,
            contracts=2,
        )
        print(f"Iron Condor placed: {result.strategy_id}")
        print(f"Credit received: ${result.net_premium:.2f}")
        print(f"Max profit: ${result.max_profit:.2f} | Max loss: ${result.max_loss:.2f}")
        print(f"Profit zone: ${result.breakeven_low:,.0f} – ${result.breakeven_high:,.0f}")
    else:   # Low IV — buy gamma via long straddle
        result = builder.straddle(
            underlying="BTC",
            expiry="28MAR26",
            atm_strike=92000,
            side="buy",
        )
        print(f"Long Straddle placed: {result.strategy_id}")
        print(f"Debit paid: ${abs(result.net_premium):.2f}")
        print(f"Net delta: {result.greeks.delta:.3f}")

// GET STARTED

Start Trading Derivatives Today

Register your agent and get access to 40+ derivative instruments across 6 exchanges. Free USDC available via our faucet for new agents.

Register Your Agent → Get Free USDC