Overview
The Simple Kalshi Bot is configured using environment variables stored in a.env file. This guide covers all available configuration options for both paper trading (bot.py) and real trading (consensus.py).
Environment File Setup
Create a.env file in your project root by copying the example:
.env with your configuration values.
Core Configuration
Kalshi API Credentials
Your Kalshi API key ID. Create this in your Kalshi account profile under API Keys.Required for: Real trading with
consensus.pyExample: KALSHI_API_KEY_ID=your-api-key-idPath to your RSA private key file for API authentication.Required for: Real trading with
consensus.pyDefault: ~/.key/kalshi/keyExample: KALSHI_PRIVATE_KEY_PATH=~/.key/kalshi/keyWhether to use the Kalshi demo API or production API.
true- Use demo API (https://demo-api.kalshi.co)false- Use production API (https://api.elections.kalshi.com)
KALSHI_USE_DEMO=trueAlways start with
KALSHI_USE_DEMO=true to test your configuration without risking real funds.Trading Safety
Simulate trades without executing real orders.
true- Simulate orders (recommended for testing)false- Execute real orders
DRY_RUN=trueTrading Parameters
Position Sizing
Amount in USD to stake per trade for paper trading strategies.Used by:
bot.py for PREVIOUS, MOMENTUM, and other paper trading strategiesExample: STAKE_USD=5Initial bankroll for CONSENSUS strategy risk management.Used by:
bot.py for calculating position sizes based on risk percentageExample: INITIAL_BANKROLL_USD=500Market Selection
Market series to watch and trade.Example:
KALSHI_EVENT_TICKER_PREFIX=KXBTC15MPopular options:KXBTC15M- Bitcoin 15-minute price marketsKXETH15M- Ethereum 15-minute price markets
Timing
How often to check for new markets and price updates (in seconds).Example:
POLL_SECONDS=5Lookback window for BTC momentum strategy (in seconds).The bot compares current BTC price to the price from this many seconds ago to determine momentum direction.Example:
MOMENTUM_WINDOW_SECONDS=60CONSENSUS Strategy Risk Controls
These parameters control risk management for the CONSENSUS and CONSENSUS_2 strategies:Target risk per trade as a percentage of bankroll.Example:
CONSENSUS_RISK_PCT=0.01 (risk 1% of bankroll per trade)Maximum risk per trade as a percentage of bankroll.Example:
CONSENSUS_MAX_RISK_PCT=0.02 (max 2% of bankroll per trade)Maximum price to pay for a contract (0.00-1.00).Higher prices mean less edge. Only trades when ask price is below this threshold.Example:
CONSENSUS_MAX_PRICE=0.55 (skip trades above $0.55)Trading fee percentage to account for in P&L calculations.Example:
CONSENSUS_FEE_PCT=0.0 (0% fees)Number of recent trades to use for rolling performance metrics.The bot calculates win rate over the last N trades to ensure the strategy is still performing above break-even.Example:
CONSENSUS_ROLLING_WINDOW=30Loss Caps
Daily loss cap in R-multiples (where R = CONSENSUS_RISK_PCT × bankroll).Trading stops for the day if daily losses exceed this threshold.Example:
CONSENSUS_DAILY_LOSS_CAP_R=3 (stop after losing 3R in one day)Weekly loss cap in R-multiples.Trading stops for the week if weekly losses exceed this threshold.Example:
CONSENSUS_WEEKLY_LOSS_CAP_R=8 (stop after losing 8R in one week)Output Configuration
CSV file path for paper trading results from
bot.py.Example: MOCK_TRADES_CSV_PATH=data/mock_trades.csvCSV file path for real trading results from
consensus.py.Example: CONSENSUS_TRADES_CSV=data/consensus_trades.csvExample Configurations
Conservative Paper Trading
Aggressive Real Trading
Validation
Before running the bot, verify your configuration:Check API credentials
Ensure
KALSHI_API_KEY_ID and KALSHI_PRIVATE_KEY_PATH are set correctly for real trading.Review risk parameters
Calculate maximum position size:
INITIAL_BANKROLL_USD × CONSENSUS_MAX_RISK_PCTNext Steps
Running the Bot
Learn how to run paper and real trading modes
Analyzing Results
Understand trading performance metrics