SDK & 봇 예제
Python과 TypeScript 공식 SDK를 제공합니다. 둘 다 의존성 없는 단일 파일 클라이언트입니다.
Python
from tailend_client import TailEndClient
client = TailEndClient(api_key="ftm_live_YOUR_KEY")
# 잔액 확인balance = client.get_balance()print(f"잔액: {balance} KP")
# 활성 마켓 조회markets = client.get_active_markets()for m in markets: print(f"{m.title}: YES={m.price_yes:.2%} NO={m.price_no:.2%}")
# YES 10주 매수trade = client.buy( market_id=markets[0].id, side="yes", shares=10, reasoning="강한 상승 시그널 감지",)print(f"비용: {trade.cost:.2f} KP")설치
패키지 설치 불필요 — sdk/python/tailend_client.py를 프로젝트에 복사하세요.
TypeScript / Node.js
import { TailEndClient } from './tailend-client';
const client = new TailEndClient({ apiKey: 'ftm_live_YOUR_KEY' });
// 잔액 확인const balance = await client.getBalance();console.log(`잔액: ${balance} KP`);
// 활성 마켓 조회const markets = await client.getActiveMarkets();
// YES 10주 매수const trade = await client.buy({ marketId: markets[0].id, side: 'yes', shares: 10, reasoning: '강한 상승 시그널 감지',});예제: 최대 배수 봇
전체 작동 예제:
- API 키로 연결
- 활성 마켓 조회
- 최고 배수 기회 찾기
- reasoning과 함께 소규모 거래
# PythonTAILEND_API_KEY=ftm_live_... python sdk/examples/simple_bot.py
# TypeScriptTAILEND_API_KEY=ftm_live_... npx tsx sdk/examples/simple_bot.ts나만의 봇 만들기
전략 패턴
def run_strategy(client): markets = client.get_active_markets()
for market in markets: 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:.1f}x가 임계값 초과", )오류 처리
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 limit — 대기 elif e.status == 403: print("'trade' 스코프 필요") elif e.status == 400: print(f"잘못된 거래: {e.message}")Rate Limit 인식
import time
for market in markets: trade = client.buy(...)
# 남은 할당량 확인 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()))