Live Trading
Live trading mode enables the Hydra to execute real transactions using your funds. This mode should only be used after extensive testing in paper mode.
Prerequisites
Section titled “Prerequisites”Before enabling live trading, ensure you have the following:
- Ethereum Wallet: A dedicated trading wallet. Do not use your primary personal wallet.
- Private Key: The Ethereum private key for your trading wallet.
- Funds on Polygon:
- USDC: Your trading capital must be in the Polygon USDC contract (the version used by Polymarket).
- MATIC: A small amount of MATIC is required to cover transaction fees (gas) on the Polygon network.
- Polymarket Account: Ensure your wallet is registered and has the necessary approvals to trade on Polymarket.
Enabling Live Mode
Section titled “Enabling Live Mode”To enable live trading, set the execution mode to live in your config.yaml:
mode: liveEnvironment Variables
Section titled “Environment Variables”For security, the bot does not store private keys in configuration files. You must provide credentials via environment variables.
Standard Setup (MetaMask / EOA Wallet)
Section titled “Standard Setup (MetaMask / EOA Wallet)”If you created your Polymarket account via MetaMask or another browser wallet:
export POLYMARKET_PRIVATE_KEY="your_private_key_here"hydra run --mode liveMagic/Email Login Setup (Proxy Wallet)
Section titled “Magic/Email Login Setup (Proxy Wallet)”If you created your Polymarket account via email/Magic login, you need additional configuration. Polymarket uses a proxy wallet architecture where:
- Your EOA (Externally Owned Account) is the wallet derived from Magic
- Your Proxy Wallet is a smart contract wallet that holds your funds
# Export private key from: https://reveal.magic.link/polymarketexport POLYMARKET_PRIVATE_KEY="0x..."
# Your Polymarket profile address (NOT the EOA address)export POLYMARKET_PROXY_ADDRESS="0x..."
hydra run --mode liveRisk Management
Section titled “Risk Management”The bot includes several built-in safety mechanisms to protect your capital. Risk management operates on two levels: continuous monitoring and pre-trade validation.
Pre-Trade Validation
Section titled “Pre-Trade Validation”Before any order is submitted to the exchange, the execution layer performs real-time validation:
- Risk Mode Check: Orders are blocked if the risk mode is not
active(i.e., if the kill switch has been triggered or trading is paused). - Position Limit Check: The system calculates whether the proposed trade would breach the
maxPositionSizeUSDClimit for that specific market. - Exposure Limit Check: The system calculates whether the proposed trade would breach the
maxTotalExposureUSDClimit across all positions.
If any check fails, the order is rejected before it reaches the exchange.
Risk Limits
Section titled “Risk Limits”Configure hard limits in the risk.limits section of your configuration file:
| Parameter | Description |
|---|---|
maxDrawdownPercent | The maximum allowed percentage loss from the peak equity. If breached, the kill switch is triggered. |
maxPositionSizeUSDC | The maximum dollar value (in USDC) allowed for any single position. Enforced both reactively and preventively. |
maxTotalExposureUSDC | The maximum total exposure across all positions. Enforced both reactively and preventively. |
maxOrdersPerMinute | Limits the rate of order placement to prevent runaway execution or API rate limiting. |
Example configuration:
risk: limits: maxDrawdownPercent: 10 maxPositionSizeUSDC: 500 maxTotalExposureUSDC: 2500 maxOrdersPerMinute: 30Reconciliation
Section titled “Reconciliation”The reconciliation feature periodically synchronizes the bot’s local state with the actual state on the Polymarket exchange. This ensures that the bot is always trading based on accurate balance and position information.
- Sync Interval: Configured via
risk.reconciliation.intervalMs(default is 60000ms). - Mismatch Protection: If a discrepancy is detected between local state and the exchange (e.g., unknown orders or missing positions), the bot will trigger the kill switch as a safety measure.
risk: reconciliation: enabled: true intervalMs: 60000Operational Safety
Section titled “Operational Safety”Kill Switch
Section titled “Kill Switch”The kill switch is a terminal state that halts all trading activity. Once triggered, the bot:
- Sets the risk mode to
killed, blocking all new orders - Cancels all open orders on the exchange
- Neutralizes all positions by selling any held tokens (UP/DOWN)
- Logs detailed warnings for investigation
The kill switch is triggered automatically if:
- Any risk limit is breached (drawdown, position size, or exposure)
- A reconciliation mismatch is detected
- Data feeds become excessively stale
After a kill switch event, the bot will not resume trading until manually restarted.
Emergency Stop
Section titled “Emergency Stop”You can manually trigger the kill switch at any time through the Terminal User Interface (TUI).
- Open the TUI.
- Ensure the interface is “Armed” (if arming is enabled).
- Select the Kill command to immediately halt the bot.
Monitoring Trades
Section titled “Monitoring Trades”You can monitor your live trading performance through three primary channels:
- Terminal UI (TUI): Real-time dashboard showing current positions, P&L, and recent events.
- Trade Ledger: Durable, append-only history of every trade execution.
- Telemetry: High-resolution metrics streamed to InfluxDB/Grafana.
Using the Trade Ledger
Section titled “Using the Trade Ledger”The Trade Ledger is the authoritative source for your trading history. It records every fill event with precise execution details.
To view your live trading history:
hydra trades --mode liveTo view a summary of your live performance:
hydra trades --mode live --summarySee the Trade Ledger guide for more information.
Heartbeat (Dead Man’s Switch)
Section titled “Heartbeat (Dead Man’s Switch)”In live trading mode, the bot maintains a heartbeat connection with the Polymarket API. This acts as a “dead man’s switch” - if the bot stops sending heartbeats (due to crash, network failure, or other issues), the exchange will automatically cancel all open orders.
How It Works
Section titled “How It Works”- The
RealExecutionlayer initializes aHeartbeatManagerwhen starting - The manager sends periodic heartbeat signals to Polymarket at a configurable interval
- If the bot crashes or loses connectivity, heartbeats stop
- The exchange detects the missing heartbeats and cancels all open orders
- This prevents orphaned orders from remaining on the book during outages
Benefits
Section titled “Benefits”- Crash Protection: Orders are automatically cleaned up if the bot crashes
- Network Failure Safety: Connectivity issues don’t leave stale orders on the book
- Capital Protection: Prevents unintended fills during bot downtime
This mechanism is critical for production deployments where unattended operation is expected.
Deployment Considerations
Section titled “Deployment Considerations”Latency Optimization
Section titled “Latency Optimization”For latency arbitrage strategies, deployment location is critical. The bot’s edge depends on receiving price data faster than the market can react.
Recommended Regions
Section titled “Recommended Regions”| Region | Latency to Binance | Latency to Polymarket | Notes |
|---|---|---|---|
| AWS ap-northeast-1 (Tokyo) | Best (~1-5ms) | Good (~100-150ms) | Binance matching engine location |
| AWS ap-southeast-1 (Singapore) | Good (~20-30ms) | Good (~120-150ms) | Good balance |
| AWS us-east-1 (N. Virginia) | Poor (~150-200ms) | Best (~10-30ms) | Polymarket servers |
Recommendation: For latency arbitrage, deploy to ap-northeast-1 (Tokyo) to minimize Binance latency. The Polymarket leg is less latency-sensitive since you’re reacting to Binance price changes.
Measuring Latency
Section titled “Measuring Latency”Use the built-in latency check utility to measure actual latency from your deployment location:
# Using the hydra binaryhydra latency # Check all exchangeshydra latency -e binance # Check specific exchangehydra latency -e polymarkethydra latency -e coinbase
# Or from sourcebun run latencybun run latency -- -e binanceRun this utility from your production environment before going live to verify acceptable latency.
Active Monitoring Requirements
Section titled “Active Monitoring Requirements”The heartbeat mechanism will cancel open orders if the bot disconnects, but positions will remain open. In a crash scenario, you must manually manage any open positions.
Best Practices
Section titled “Best Practices”- Start Small: Begin with very small
maxPositionSizeUSDCvalues to verify execution logic in a live environment. - Paper Trade First: Run your configuration in
mode: paperfor at least 24-48 hours of active market time before going live. - Monitor Connectivity: Use the TUI to monitor WebSocket staleness. If your internet connection is unstable, the bot’s risk manager may pause trading frequently.
- Dedicated Wallet: Always use a fresh wallet with only the amount of capital you are willing to risk.
- Monitor the TUI: Keep the TUI dashboard open to track Bal, Real/Unrl PnL, and DD metrics in real-time.
- Test Latency First: Run
hydra latencyfrom your production environment before going live. - Deploy to Low-Latency Region: For latency arbitrage, deploy to ap-northeast-1 (Tokyo) or ap-southeast-1 (Singapore).