Build a Trading Bot
Build a bot that trades BTC 15-minute prediction markets on Turbine using Claude Code. This guide covers wallet setup, funding, bot generation via the /create-bot skill, and cloud deployment.
BTC Quick Markets ask "Will BTC be above $X in 15 minutes?" — a new market rotates in every 15 minutes. Your bot detects each transition and moves to the new market automatically.
Prerequisites
- Python 3.9+ and pip
- Git
- Claude Code CLI — install with
npm install -g @anthropic-ai/claude-code - A terminal (macOS, Linux, or WSL)
Create a Wallet
Your bot signs orders with a raw private key. Use a dedicated wallet — not your main wallet.
Export from MetaMask
- Open MetaMask and select the account you want to use
- Click the three dots next to the account name
- Go to Account Details > Show Private Key
- Enter your password and copy the hex string (starts with
0x)
Generate a New Wallet
Using Python:
from eth_account import Account
acct = Account.create()
print(f"Address: {acct.address}")
print(f"Private Key: {acct.key.hex()}")Or using Foundry's cast:
cast wallet newSave the private key. You will need it during /setup when Claude asks for your wallet credentials.
**⚠️ Security:** Never share your private key or commit it to version control. Use a wallet with only the funds you intend to trade.
Fund Your Wallet with USDC
Your bot needs USDC on Polygon (chain ID 137) to place orders. $10 is enough to start.
No MATIC is required. All Turbine operations — USDC approval, order signing, position claiming — are gasless.
Bridge from Another Chain
If you already hold USDC on Ethereum, Arbitrum, or another chain, use a bridge service to transfer to Polygon.
Buy and Withdraw from an Exchange
- Purchase USDC on Coinbase, Binance, Kraken, or any exchange that supports Polygon withdrawals
- Withdraw USDC to your wallet address on the Polygon network (chain ID 137)
Verify
USDC contract on Polygon: 0x3c499c542cEF5E3811e1192ce70d8cC03d5c3359
Check your balance on Polygonscan or in MetaMask after adding the Polygon network:
| Setting | Value |
|---|---|
| Network Name | Polygon |
| RPC URL | https://polygon-rpc.com |
| Chain ID | 137 |
| Currency Symbol | MATIC |
| Block Explorer | https://polygonscan.com |
One-Line Install
Run a single command to clone the SDK, install dependencies, create a .env template, and launch Claude Code with the bot generator:
curl -sSL turbinefi.com/claude | bashThis executes scripts/create-bot.sh, which does the following:
Clone the SDK
git clone https://github.com/ojo-network/turbine-py-client.git turbine-bot
cd turbine-botLaunch Claude Code
claude "/setup"Claude walks you through environment setup (Python, wallet, .env configuration, USDC funding) and then helps you generate a trading bot with /create-bot.
The /setup Skill
The /setup skill handles environment configuration. It walks you through:
- Python environment — verifies Python 3.9+, creates a virtual environment, installs the SDK
- Wallet credentials — asks for your Ethereum private key and writes it to
.env - USDC funding — guides you through funding your wallet on Polygon
If .env already has a key configured, those steps are skipped.
API Credentials
API credentials are not configured during setup — they are registered automatically when the bot runs for the first time. The SDK calls TurbineClient.request_api_credentials(), which signs a message with your wallet to prove ownership and receives Ed25519 API keys. These are saved to .env so subsequent runs reuse them:
TURBINE_API_KEY_ID=abc123...
TURBINE_API_PRIVATE_KEY=base64encodedkey...The /create-bot Skill Flow
After setup, run /create-bot in Claude Code to generate your trading bot. The skill walks through two steps interactively.
Algorithm Selection
Claude presents six algorithm choices:
| Algorithm | Description | Risk |
|---|---|---|
| Price Action | Fetches live BTC price from Pyth Network and compares to the market strike price. BTC above strike = buy YES, below = buy NO. Confidence scales with distance. | Medium |
| Simple Spread | Places symmetric bid/ask orders around the current mid-price with a fixed spread. | Medium |
| Inventory-Aware | Like Simple Spread, but skews quotes to reduce accumulated position. | Lower |
| Momentum | Detects price direction from recent trades. Buys with the trend. | Higher |
| Mean Reversion | Fades large price moves, betting on reversion to the mean. | Higher |
| Probability-Weighted | Bets that prices far from 500000 ($0.50) will revert toward 50%. | Medium |
**Recommended:** Price Action is recommended for BTC Quick Markets. It uses the Pyth Network oracle — the same data source Turbine uses to resolve markets — so the bot's signal is directly aligned with the resolution mechanism.
Bot Generation
Claude generates a complete Python file (e.g., price_action_bot.py) based on your algorithm choice. The generated code follows the structure of examples/price_action_bot.py, the SDK's reference implementation.
What the Bot Does
The generated bot handles the full trading lifecycle:
Startup
- Loads
TURBINE_PRIVATE_KEYfrom.env - Checks for existing API credentials in
.env— if missing, callsTurbineClient.request_api_credentials()to register and saves them automatically - Initializes
TurbineClientwithhost="https://api.turbinefi.com"andchain_id=137
First trade on a new market
- Signs a gasless EIP-2612 max USDC permit for the settlement contract (
approve_usdc_for_settlement()). This is a one-time operation per settlement contract.
Each cycle (every ~10 seconds)
- Fetches the active BTC Quick Market via
get_quick_market("BTC") - Fetches the current BTC price from Pyth Network
- Runs the algorithm's signal logic
- Places a limit order if the signal has sufficient confidence
- Tracks positions in USDC terms and respects
--max-position
Market transitions
- Detects when the current market is expiring and switches to the new market
Background tasks
- Claims winnings from resolved markets via
claim_winnings()(gasless, relayer-submitted) - Syncs positions from the API periodically
Shutdown (Ctrl+C)
- Cancels all open orders and exits cleanly
Run Your Bot
Run the generated bot file:
python price_action_bot.pyOr use the reference implementation directly:
python examples/price_action_bot.py --order-size 1 --max-position 10By default, the bot trades all supported assets (BTC, ETH, SOL). To trade specific assets:
python examples/price_action_bot.py --assets BTC,ETHParameters
| Parameter | Description | Default |
|---|---|---|
--order-size / -s | USDC amount per order | 1.0 |
--max-position / -m | Maximum USDC exposure per asset per market | 10.0 |
--assets / -a | Comma-separated list of assets to trade | BTC,ETH,SOL |
Environment Variables
| Variable | Description | Required |
|---|---|---|
TURBINE_PRIVATE_KEY | Wallet private key (hex, 0x-prefixed) | Yes |
TURBINE_API_KEY_ID | Ed25519 API key ID (auto-registered on first run) | No |
TURBINE_API_PRIVATE_KEY | Ed25519 API private key (auto-registered on first run) | No |
CHAIN_ID | Blockchain chain ID | Yes (137 for Polygon) |
TURBINE_HOST | API server URL | Yes (https://api.turbinefi.com) |
CLAIM_ONLY_MODE | Set to true to disable trading and only claim winnings | No |
Expected Output
Registering new API credentials...
API credentials registered and saved to .env
Starting Price Action Bot...
Chain: Polygon (137)
Order size: $1.00 USDC
Max position: $10.00 USDC
Approving USDC for settlement (gasless)...
USDC approved via gasless max permit
Fetched BTC Quick Market: Will BTC be above $97,432.15 in 15 minutes?
Market ID: 0xabc123...
Expires in: 12m 30s
BTC Price: $97,489.22 (above strike by 0.06%)
Signal: BUY YES (confidence: 0.58)
Placed order: BUY 1.72 YES @ 580000 ($0.58)
Market transition detected — switching to new market...
Claimed winnings from resolved market: +$1.72 USDCPress Ctrl+C to stop. The bot cancels all open orders before exiting.
Deploy on Railway
Railway runs your bot 24/7 in the cloud. The free tier includes $5 credit for 30 days.
Using the /railway-deploy Skill
From your bot directory:
claude "/railway-deploy"The skill identifies your bot file, generates deployment config files (requirements.txt, main.py, railway.toml), commits everything to git, pushes to a private GitHub repo, and walks you through connecting the repo to Railway for automatic deployment.
Prerequisites: GitHub CLI (gh) must be installed and authenticated.
Manual Deployment
- Push your code to GitHub:
gh repo create turbine-bot --private --source=. --pushConnect to Railway:
- Go to railway.com/new
- Click Deploy from GitHub repo
- Select your repo — Railway auto-deploys on connect
Set environment variables in the Railway dashboard (service → Variables tab):
| Variable | Value |
|---|---|
TURBINE_PRIVATE_KEY | Your wallet private key |
TURBINE_API_KEY_ID | From your .env (auto-generated on first bot run) |
TURBINE_API_PRIVATE_KEY | From your .env (auto-generated on first bot run) |
CHAIN_ID | 137 |
TURBINE_HOST | https://api.turbinefi.com |
Redeployment
Future deploys are automatic — just push to GitHub:
git add . && git commit -m "update bot" && git pushRailway redeploys on every push. Monitor your bot via the Logs tab in the Railway dashboard.