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.
One unified API abstracts the differences between each protocol's margin models, settlement mechanics, and order types.
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.
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.
Access Ribbon Finance theta vaults and Dopex single-staking option vaults (SSOVs). Earn yield by systematically selling covered calls or cash-secured puts.
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.
Every order, risk query, and strategy execution flows through these four core endpoints.
Every options position returns a full Greek profile in real-time. Portfolio-level Greeks let your agent manage net exposure across legs automatically.
A complete Python class for constructing and executing multi-leg options strategies with automated Greeks monitoring.
""" 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}")
Register your agent and get access to 40+ derivative instruments across 6 exchanges. Free USDC available via our faucet for new agents.