"""EventTrader AIB Fund SDK (Python) — create, store and modify your own custom AIB funds programmatically. Quick start: from eventtrader_aib import EventTraderAIB et = EventTraderAIB(api_key="YOUR_API_KEY") # or session cookie fund = et.create_fund("Desalination Tech", prompts=["desalination", "water scarcity"]) print(fund["symbol"], fund["legs"]) mine = et.my_funds() et.edit_basket(fund["symbol"], [ {"symbol": "XYL", "asset_class": "stocks"}, {"symbol": "AWK", "asset_class": "stocks"}, ]) Auth (any one of): - api_key: your platform API key, sent as the X-API-Key header — the key from MCP agent registration (mcp_...) works here too; - access_token: a JWT from POST /auth/login, sent as Authorization: Bearer; - session_cookie: reuse a logged-in browser session cookie. Fund creation charges the one-time creation fee from YOUR account's USDC balance (USDT auto-covers 1:1) — real money. Dependencies: requests (pip install requests). """ from __future__ import annotations from typing import Any, Dict, List, Optional import requests BASE_URL = "https://cymetica.com" class EventTraderAIBError(RuntimeError): """Raised when the API refuses a call; str(e) is the user-safe reason.""" class EventTraderAIB: def __init__(self, api_key: Optional[str] = None, access_token: Optional[str] = None, session_cookie: Optional[str] = None, base_url: str = BASE_URL, timeout: float = 30.0): self.base_url = base_url.rstrip("/") self.timeout = timeout self._s = requests.Session() if api_key: self._s.headers["X-API-Key"] = api_key if access_token: self._s.headers["Authorization"] = f"Bearer {access_token}" if session_cookie: self._s.headers["Cookie"] = session_cookie # ── internals ──────────────────────────────────────────────────── def _req(self, method: str, path: str, **kw) -> Dict[str, Any]: r = self._s.request(method, self.base_url + path, timeout=self.timeout, **kw) try: data = r.json() except ValueError: data = {} if r.status_code >= 400: raise EventTraderAIBError( str(data.get("detail") or data.get("error") or f"HTTP {r.status_code}")) return data # ── custom AIB funds (create / store / modify) ─────────────────── def discover(self, prompts: List[str], asset_class: str = "stocks", vetoes: Optional[List[str]] = None) -> Dict[str, Any]: """FREE preview: the 10 assets the Tuatara vector model connects to your theme prompts. Iterate here before paying to create.""" return self._req("POST", "/api/v1/aib-builder/discover", json={ "prompts": prompts, "asset_class": asset_class, "vetoes": vetoes or []}) def create_fund(self, title: str, prompts: List[str], *, public: bool = True, asset_class: str = "stocks", direction: str = "long", vetoes: Optional[List[str]] = None) -> Dict[str, Any]: """Mint the fund (charges the creation fee from your balance).""" return self._req("POST", "/api/v1/aib-builder/create", json={ "title": title, "prompts": prompts, "public": public, "asset_class": asset_class, "direction": direction, "vetoes": vetoes or []}) def my_funds(self) -> Dict[str, Any]: """Your funds + builder limits + the current creation fee.""" return self._req("GET", "/api/v1/aib-builder/mine") def edit_basket(self, symbol: str, legs: List[Dict[str, str]]) -> Dict[str, Any]: """Atomically replace a self-directed fund's full membership. legs = [{"symbol": "XYL", "asset_class": "stocks"}, ...]""" return self._req("POST", f"/api/v1/aib-builder/{symbol}/basket", json={"legs": legs}) def set_strategy(self, symbol: str, strategy: Optional[Dict[str, Any]]) -> Dict[str, Any]: """Apply/replace (or clear with None) the advisory strategy config.""" return self._req("POST", f"/api/v1/aib-builder/{symbol}/strategy", json={"strategy": strategy}) def clone_preview(self, source_symbol: str) -> Dict[str, Any]: """FREE preview of cloning an existing AIB/community fund.""" return self._req( "GET", f"/api/v1/aib-builder/clone/{source_symbol}/preview") # ── trading the live funds ─────────────────────────────────────── def buy(self, symbol: str, usdc_amount: float) -> Dict[str, Any]: """Buy fund shares at live NAV (spends your trading balance).""" return self._req("POST", f"/api/v1/aib/{symbol}/buy", json={"usdc_amount": usdc_amount}) def sell(self, symbol: str, shares: float) -> Dict[str, Any]: """Sell fund shares back at the live NAV-based bid.""" return self._req("POST", f"/api/v1/aib/{symbol}/sell", json={"shares": shares}) def holdings(self) -> Dict[str, Any]: """Your AIB share positions.""" return self._req("GET", "/api/v1/aib/portfolio/holdings") def quote(self, symbol: str) -> Dict[str, Any]: """Live NAV / bid / ask for a fund (public).""" return self._req("GET", f"/api/v1/aib/{symbol}/quote")