Trading Bot
Overview
The Trading Bot is an autonomous trading system that continuously monitors markets and executes trades based on AI-powered decisions. It trades across three market types: Trenches (spot), Polymarket (yes/no positions), and Hyperliquid (perpetual futures with long/short positions).
Key Features
Automated Trading
Continuous Operation: Runs 24/7, even when the page is closed
Multi-Market Trading: Trades across Trenches, Polymarket, and Hyperliquid
AI Decision Making: Uses Claude Sonnet 4.5 for intelligent trade decisions
Background Execution: Trades execute via background workers
Position Management
Long Positions: For spot tokens and perpetual futures
Short Positions: For perpetual futures (Hyperliquid)
Yes/No Positions: For Polymarket prediction markets
Position Tracking: Real-time monitoring of all open positions
Risk Management
Cash Management: Prevents negative cash balances
Position Sizing: Dynamic trade sizing based on available capital
Stop Loss Logic: Built-in risk controls
Portfolio Limits: Maximum position sizes and exposure limits
Trading Bot Configuration
Initial Capital
Default: $2,000 USD
Configurable: Can be adjusted in the code
Starting Cash: All capital starts as available cash
Trade Parameters
Minimum Trade: $10 USD
Maximum Trade: $100 USD (or available cash - $50)
Trade Frequency: Every 30 seconds (background trading)
Decision Interval: AI makes decisions before each trade
Trading Logic
Market Selection
The bot selects markets from:
Trenches: Top 10 tokens from DexScreener
Polymarket: Top 10 markets by volume
Hyperliquid: Top 10 perpetuals by price change
AI Decision Process
Market Analysis
Fetches current market data
Analyzes price trends
Evaluates volume and liquidity
Considers open positions
Decision Generation
AI receives market context
Current holdings information
Available cash
Portfolio performance
Action Selection
For Trenches:
buyorsellFor Polymarket:
yesornoFor Perpetuals:
long,short,close_long, orclose_short
Trade Execution
Validates cash availability
Calculates position size
Executes trade
Updates portfolio
Portfolio Tracking
Metrics Displayed
Portfolio Value: Total value including cash and holdings
Available Cash: Liquid funds available for trading
Total Trades: Number of trades executed
Win Rate: Percentage of profitable trades
P&L: Profit and loss in USD and percentage
Holdings Display
Symbol: Token or market identifier
Amount: Quantity held
Average Price: Entry price
Current Value: Market value of position
P&L: Unrealized profit/loss
Position Type: Long or Short (for perpetuals)
Trade History
Each trade is logged with:
Timestamp: Exact time of execution
Action: Buy, Sell, Long, Short, Close Long, Close Short
Symbol: Market identifier
Amount: Quantity traded
Price: Execution price
Trade Value: Total value of trade
P&L: Realized profit/loss (for closed positions)
Background Trading
The bot continues trading even when:
The trading page is closed
No users are viewing the site
The server is running
Background Worker
Runs on every page load
Calls trading API every 30 seconds
Executes trades independently
Syncs state to database
Managing the Trading Bot
Viewing Performance
Navigate to the Trading page
View real-time portfolio metrics
Monitor active positions
Review trade history
Cash Management
The bot automatically:
Prevents trades that would result in negative cash
Rejects trades with insufficient funds
Closes positions if needed to free up cash (future feature)
Last updated

