Trading Bot Setup

Deploy and run bots 24/7

Pre-installed Tools

Your VPS comes ready with:

  • Python 3.12 with pip and venv
  • Node.js 20 LTS with npm and yarn
  • Git for version control
  • PM2 for process management
  • Common trading libraries pre-installed

Python Trading Bot Example

# Install py-clob-client
pip install py-clob-client

# bot.py
from py_clob_client import ClobClient
import os

client = ClobClient(
    host="https://clob.polymarket.com",
    key=os.environ["POLYMARKET_API_KEY"],
    chain_id=137
)

def run_bot():
    while True:
        # Get market data
        markets = client.get_markets()
        
        # Your trading logic here
        for market in markets:
            # Analyze and trade
            pass
            
        time.sleep(1)

if __name__ == "__main__":
    run_bot()

Environment Variables

Store sensitive data in environment variables:

# Create .env file
nano ~/.env

# Add your secrets
POLYMARKET_API_KEY=your-api-key
POLYMARKET_SECRET=your-secret
DISCORD_WEBHOOK=your-webhook-url

# Load in your bot
from dotenv import load_dotenv
load_dotenv()

Running 24/7 with PM2

# Start your bot
pm2 start bot.py --name "polymarket-bot" --interpreter python3

# Monitor logs
pm2 logs polymarket-bot

# Set up auto-restart on reboot
pm2 startup
pm2 save

Setting Up Alerts

Discord Webhook

import requests

def send_discord_alert(message):
    webhook_url = os.environ["DISCORD_WEBHOOK"]
    requests.post(webhook_url, json={"content": message})
    
# Usage
send_discord_alert("Trade executed: Bought 100 shares at 0.65")

Telegram Bot

import requests

def send_telegram_alert(message):
    bot_token = os.environ["TELEGRAM_BOT_TOKEN"]
    chat_id = os.environ["TELEGRAM_CHAT_ID"]
    url = f"https://api.telegram.org/bot{bot_token}/sendMessage"
    requests.post(url, json={"chat_id": chat_id, "text": message})

Best Practices

  • Always use environment variables for API keys
  • Implement proper error handling and logging
  • Set up alerts for important events and errors
  • Test thoroughly on testnet before live trading
  • Start with small position sizes
  • Monitor your bot regularly