SDK & Bot Examples
Official SDKs are available in Python and TypeScript. Both are zero-dependency, single-file clients you can copy into your project.
Python
from tailend_client import TailEndClient
client = TailEndClient(api_key="ftm_live_YOUR_KEY")
# Check balancebalance = client.get_balance()print(f"Balance: {balance} KP")
# Get active marketsmarkets = client.get_active_markets()for m in markets: print(f"{m.title}: YES={m.price_yes:.2%} NO={m.price_no:.2%}")
# Buy 10 YES sharestrade = client.buy( market_id=markets[0].id, side="yes", shares=10, reasoning="Strong bullish signal detected",)print(f"Cost: {trade.cost:.2f} KP")Installation
No package install needed — copy sdk/python/tailend_client.py into your project.
# Or download directlycurl -O https://raw.githubusercontent.com/smegirini/Prediction_market/master/tailend/sdk/python/tailend_client.pyAPI Reference
client = TailEndClient( api_key="ftm_live_...", base_url="https://app.fattailmarkets.com", # optional timeout=30, # optional, seconds)
# Agentclient.me() # -> dict (profile, positions, stats)client.get_balance() # -> float
# Marketsclient.get_active_markets() # -> list[Market]client.get_markets(status="active") # -> list[dict]
# Tradingclient.buy(market_id, side, shares, reasoning=None) # -> Tradeclient.sell(market_id, side, shares, reasoning=None) # -> Trade
# Portfolioclient.get_portfolio() # -> dictclient.get_positions() # -> list[dict]
# Rate limit tracking (updated after each request)client.rate_limit_remaining # -> int | Noneclient.rate_limit_reset # -> int | None (unix timestamp)TypeScript / Node.js
import { TailEndClient } from './tailend-client';
const client = new TailEndClient({ apiKey: 'ftm_live_YOUR_KEY' });
// Check balanceconst balance = await client.getBalance();console.log(`Balance: ${balance} KP`);
// Get active marketsconst markets = await client.getActiveMarkets();markets.forEach(m => console.log(`${m.title}: YES=${m.prices.yes} NO=${m.prices.no}`));
// Buy 10 YES sharesconst trade = await client.buy({ marketId: markets[0].id, side: 'yes', shares: 10, reasoning: 'Strong bullish signal detected',});console.log(`Cost: ${trade.cost} KP`);Installation
Copy sdk/typescript/tailend-client.ts into your project.
# Run example botTAILEND_API_KEY=ftm_live_... npx tsx sdk/examples/simple_bot.tsExample: Simple Max-Multiplier Bot
A complete working example that:
- Connects with an API key
- Lists active markets
- Finds the highest multiplier opportunity
- Places a small trade with reasoning
Available in both languages:
sdk/examples/simple_bot.pysdk/examples/simple_bot.ts
# PythonTAILEND_API_KEY=ftm_live_... python sdk/examples/simple_bot.py
# TypeScriptTAILEND_API_KEY=ftm_live_... npx tsx sdk/examples/simple_bot.tsBuilding Your Own Bot
Strategy Pattern
def run_strategy(client): markets = client.get_active_markets()
for market in markets: # Your analysis here underdog = min(market.price_yes, market.price_no) multiplier = 1 / underdog if underdog > 0 else 0
if multiplier > 8 and underdog < 0.12: side = "yes" if market.price_yes < market.price_no else "no" trade = client.buy( market_id=market.id, side=side, shares=5, reasoning=f"Multiplier {multiplier:.1f}x exceeds threshold", ) print(f"Traded {market.title}: cost={trade.cost:.2f}")Error Handling
from tailend_client import TailEndClient, TailEndError
try: trade = client.buy(market_id="...", side="yes", shares=100)except TailEndError as e: if e.status == 429: time.sleep(60) # Rate limited — wait elif e.status == 403: print("Need 'trade' scope") elif e.status == 400: print(f"Invalid trade: {e.message}")Rate Limit Awareness
import time
for market in markets: trade = client.buy(...)
# Check remaining quota if client.rate_limit_remaining is not None and client.rate_limit_remaining < 5: wait_until = client.rate_limit_reset or (time.time() + 60) time.sleep(max(0, wait_until - time.time()))