Kalshi AI Prediction Market Trading Bot¶
Prediction markets trade around the clock on macro announcements, Federal Reserve decisions, weather outcomes, financial milestones, and sports events. This 24/7 Kalshi bot uses LumiBot’s built-in prediction-market tools (prediction_discover_markets, prediction_get_market, prediction_quote, and prediction_submit_order) to compare live news against implied YES/NO probabilities and place small, risk-capped orders on mispriced contracts.
How it works¶
With self.market = "24/7" and self.sleeptime = "30M", two agents evaluate event markets every 30 minutes:
Research agent discovers liquid open Kalshi markets with tight spreads and clear resolution rules, compares each market’s implied YES and NO prices against current news and public data available by today, and returns the top one to three mispriced contracts with exact ticker, side, estimated true probability, edge percentage, and a short thesis.
Trading agent checks live quotes and submits risk-capped Kalshi orders. It spends at most
max_bet_usdper market, holds at mostmax_open_marketsconcurrent positions, only enters when the quoted ask offers at least an 8 percentage point edge over estimated probability, and takes profits or exits when the edge disappears.
Want larger position caps or a slower polling interval? Adjust max_bet_usd, max_open_markets, or self.sleeptime in the strategy class.
Run it on BotSpot¶
Discover community bots and run 24/7 cloud strategies on BotSpot Marketplace. BotSpot hosts LumiBot strategies around the clock and connects cleanly to supported brokers and exchanges.
Building or debugging your Kalshi bot with Claude, ChatGPT, Codex, or Cursor? Connect the free BotSpot MCP to write strategies, run backtests, and review logs. Want hands-on training in AI trading bots across stocks, options, crypto, and prediction markets? Explore BotSpot Courses or join the free AI Trading Challenge.
The code¶
The full Kalshi prediction-market bot is under 80 lines of Python. LumiBot’s built-in prediction tools handle contract discovery, quotes, and order submission without custom HTTP boilerplate.
"""Kalshi AI Prediction Market Bot (24/7).
Compares live news and public data against Kalshi implied YES/NO probabilities
using LumiBot's built-in prediction-market capabilities, and places small,
risk-capped bets on mispriced event contracts around the clock.
"""
from lumibot.strategies import Strategy
class KalshiAIPredictionBot(Strategy):
parameters = {
"model": "openai/gpt-6-luna",
"max_bet_usd": 10.0,
"max_open_markets": 3,
}
def initialize(self):
self.sleeptime = "30M"
self.market = "24/7"
model = self.parameters["model"]
self.agents.create(
name="researcher",
model=model,
allow_trading=False,
allow_network=True,
system_prompt=(
"Discover liquid, open Kalshi prediction markets, focusing on near-term macro, "
"Federal Reserve, weather, finance, or sports events with tight spreads and clear "
"resolution rules. Compare each market's implied YES and NO probability against "
"current news and public data available by today. Return the top 1 to 3 mispriced "
"markets with exact ticker, side (YES or NO), current price, estimated true "
"probability, edge percentage, and a two-sentence thesis. Do not trade."
),
)
self.agents.create(
name="trader",
model=model,
allow_trading=True,
system_prompt=(
"Execute disciplined, risk-capped prediction-market trades on Kalshi using live "
"contract quotes. Spend at most max_bet_usd per market and hold at most "
"max_open_markets concurrent positions. Only buy contracts where the quoted ask "
"offers a clear positive edge of at least 8 percentage points over estimated "
"probability, and never exceed available cash. Take profits or exit if an "
"existing position's edge disappears."
),
)
def on_trading_iteration(self):
research = self.agents["researcher"].run(
task_prompt="Find the best mispriced open Kalshi prediction markets right now.",
context={
"previous_notes": self.vars.get("last_notes", "none yet"),
"max_open_markets": self.parameters["max_open_markets"],
},
)
self.vars.set("last_notes", research.summary)
self.agents["trader"].run(
task_prompt="Review live quotes and place risk-capped Kalshi orders for the best edges.",
context={
"research": research.summary,
"max_bet_usd": self.parameters["max_bet_usd"],
"max_open_markets": self.parameters["max_open_markets"],
},
)
if __name__ == "__main__":
from lumibot.credentials import IS_BACKTESTING
if IS_BACKTESTING:
from lumibot.backtesting import KalshiBacktesting
KalshiAIPredictionBot.backtest(KalshiBacktesting)
else:
KalshiAIPredictionBot().run_live()
Run it yourself¶
pip install lumibot
python -m lumibot.example_strategies.ai_kalshi_prediction_bot
Add OPENAI_API_KEY and your Kalshi credentials to your .env file:
KALSHI_API_KEY_IDKALSHI_PRIVATE_KEY(orKALSHI_PRIVATE_KEY_PATH)KALSHI_IS_DEMO=true(start in Kalshi’s demo environment before trading live capital)
Set IS_BACKTESTING=true with BACKTESTING_START and BACKTESTING_END to replay completed Kalshi candles through KalshiBacktesting, or IS_BACKTESTING=false to run 24/7 against Kalshi demo or live markets.
Good to know¶
Built-in
prediction_discover_markets,prediction_get_market,prediction_quote, andprediction_submit_orderagent tools require a LumiBot runtime version that includes the Kalshi agent toolset.Running every 30 minutes around the clock makes up to 48 research-and-trading cycles per day; start with
KALSHI_IS_DEMO=trueand monitor model token spend before scaling up.Event contracts settle to $1.00 or $0.00 at resolution, meaning any contract held to expiration can lose 100% of the stake paid. Always keep
max_bet_usdsized to risk you are willing to lose.
See AI Trading Bot Examples for more AI trading bots and Backtest, paper, or live: choose the runner for backtest and live runners.