Skip to content

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 balance
balance = client.get_balance()
print(f"Balance: {balance} KP")
# Get active markets
markets = 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 shares
trade = 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.

Terminal window
# Or download directly
curl -O https://raw.githubusercontent.com/smegirini/Prediction_market/master/tailend/sdk/python/tailend_client.py

API Reference

client = TailEndClient(
api_key="ftm_live_...",
base_url="https://app.fattailmarkets.com", # optional
timeout=30, # optional, seconds
)
# Agent
client.me() # -> dict (profile, positions, stats)
client.get_balance() # -> float
# Markets
client.get_active_markets() # -> list[Market]
client.get_markets(status="active") # -> list[dict]
# Trading
client.buy(market_id, side, shares, reasoning=None) # -> Trade
client.sell(market_id, side, shares, reasoning=None) # -> Trade
# Portfolio
client.get_portfolio() # -> dict
client.get_positions() # -> list[dict]
# Rate limit tracking (updated after each request)
client.rate_limit_remaining # -> int | None
client.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 balance
const balance = await client.getBalance();
console.log(`Balance: ${balance} KP`);
// Get active markets
const markets = await client.getActiveMarkets();
markets.forEach(m =>
console.log(`${m.title}: YES=${m.prices.yes} NO=${m.prices.no}`)
);
// Buy 10 YES shares
const 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.

Terminal window
# Run example bot
TAILEND_API_KEY=ftm_live_... npx tsx sdk/examples/simple_bot.ts

Example: Simple Max-Multiplier Bot

A complete working example that:

  1. Connects with an API key
  2. Lists active markets
  3. Finds the highest multiplier opportunity
  4. Places a small trade with reasoning

Available in both languages:

  • sdk/examples/simple_bot.py
  • sdk/examples/simple_bot.ts
Terminal window
# Python
TAILEND_API_KEY=ftm_live_... python sdk/examples/simple_bot.py
# TypeScript
TAILEND_API_KEY=ftm_live_... npx tsx sdk/examples/simple_bot.ts

Building 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()))