Fast Decision-Model TopstepX Futures Bot (ES / NQ)¶
Trading full-size CME E-mini S&P 500 (ES) and E-mini Nasdaq-100 (NQ) futures on TopstepX requires fast, disciplined entries without waiting through multi-turn LLM tool loops. This short strategy pairs deterministic 5-minute futures features with LumiBot’s sub-second self.agents.decide() API (OpenAI openai/gpt-6-luna or Google google/gemini-decision-1) and strict single-contract Python risk caps.
View or Run on BotSpot Marketplace
Explore live AI trading bots, cloud backtests, and one-click TopstepX broker connections on BotSpot Marketplace without local setup.
How it works¶
Every five minutes during the us_futures session, Python computes compact intraday features and invokes a single forward-pass decision call:
Feature builder and decision agent fetches the last 30 one-minute continuous futures bars (
Asset("ES", Asset.AssetType.CONT_FUTURE)orNQ), calculates 5-bar and 20-bar moving averages, 5-minute and 20-minute returns, and 20-minute range location, and callsself.agents.decide()with three typed questions: a discreteactionchoice (BUY,SHORT,HOLD, orEXIT), a calibratedhigh_convictionpredicate probability, and atrend_strengthrubric score (choppy/moderate/strong, normalized0.0to1.0).Execution layer applies deterministic prop-firm risk guardrails: it flattens open positions immediately on
EXIT, and only opensmax_contracts(default1contract) when flat and bothconviction >= 0.68andtrend_strength >= 0.65are satisfied.
Switch between regular E-mini S&P 500 (ES, $50/point) and E-mini Nasdaq-100 (NQ, $20/point) by changing symbol in parameters, and swap decision_model between openai/gpt-6-luna and google/gemini-decision-1.
Run it on BotSpot¶
Explore ready-to-run futures bots and deploy continuously in the cloud on BotSpot Marketplace. BotSpot hosts LumiBot strategies continuously, runs historical futures backtests, and connects directly to TopstepX (ProjectX) and other supported brokers.
Building custom TopstepX fast-decision bots with Claude, ChatGPT, Codex, or Cursor? Connect the free BotSpot MCP for LumiBot skills, cloud backtesting, and logs. Want guided training on low-latency AI futures bots? Explore BotSpot Courses or join the free AI Trading Challenge.
The code¶
The complete hybrid futures strategy is under 110 lines of Python and demonstrates all three typed decision question types (choice, predicate, and score) on continuous futures.
"""Fast Decision-Model TopstepX Regular Futures Bot (ES / NQ).
Uses LumiBot's low-latency self.agents.decide(...) interface with OpenAI
"openai/gpt-6-luna" or Google "google/gemini-decision-1" to classify intraday
E-mini S&P 500 (ES) or E-mini Nasdaq-100 (NQ) futures momentum, range position,
and volatility into BUY, SHORT, HOLD, or EXIT in milliseconds without
multi-turn tool loops. Designed for TopstepX (ProjectX) regular futures
sessions with strict single-contract risk caps.
"""
from lumibot.entities import Asset
from lumibot.strategies import Strategy
class FastDecisionTopstepXFuturesBot(Strategy):
parameters = {
"symbol": "ES", # Regular CME E-mini futures: "ES" ($50/pt) or "NQ" ($20/pt)
"decision_model": "openai/gpt-6-luna", # or "google/gemini-decision-1"
"max_contracts": 1,
"min_conviction": 0.68,
}
def initialize(self):
self.sleeptime = "5M"
self.market = "us_futures"
def on_trading_iteration(self):
symbol = str(self.parameters["symbol"]).upper()
contract = Asset(symbol, Asset.AssetType.CONT_FUTURE)
bars = self.get_historical_prices(contract, 30, "minute")
if bars is None or len(bars.df) < 20:
return
df = bars.df
close = df["close"]
last = float(close.iloc[-1])
sma5 = float(close.tail(5).mean())
sma20 = float(close.tail(20).mean())
high20 = float(df["high"].tail(20).max()) if "high" in df.columns else float(close.tail(20).max())
low20 = float(df["low"].tail(20).min()) if "low" in df.columns else float(close.tail(20).min())
span = max(high20 - low20, 1e-6)
range_pos_pct = round(((last - low20) / span) * 100.0, 2)
ret5 = round((last / float(close.iloc[-6]) - 1.0) * 100.0, 3)
ret20 = round((last / float(close.iloc[-20]) - 1.0) * 100.0, 3)
pos = self.get_position(contract)
held_qty = int(round(float(pos.quantity))) if pos else 0
max_contracts = max(1, int(self.parameters["max_contracts"]))
decision = self.agents.decide(
model=self.parameters["decision_model"],
evidence={
"symbol": symbol,
"contract_type": "CME_EMINI_CONT_FUTURE",
"last_price": round(last, 2),
"sma5": round(sma5, 2),
"sma20": round(sma20, 2),
"ret_5m_pct": ret5,
"ret_20m_pct": ret20,
"range_pos_20m_pct": range_pos_pct,
"current_contracts": held_qty,
},
questions=[
{
"name": "action",
"type": "choice",
"instructions": (
"Pick the highest-expectancy intraday futures action for the next 5 to 15 minutes."
),
"choices": ["BUY", "SHORT", "HOLD", "EXIT"],
},
{
"name": "high_conviction",
"type": "predicate",
"instructions": (
"Is intraday trend alignment and range location clean enough to take or exit risk?"
),
},
{
"name": "trend_strength",
"type": "score",
"instructions": "Rate intraday trend clarity from choppy to strong directional.",
"levels": ["choppy", "moderate", "strong"],
},
],
)
action = decision.choice("action")
conviction = float(decision.probability("high_conviction"))
trend_score = float(decision.score("trend_strength"))
min_conviction = float(self.parameters["min_conviction"])
self.log_message(
f"TopstepX Decision {symbol}: action={action} conviction={conviction:.2f} "
f"trend={trend_score:.2f} price={last:.2f} held={held_qty}"
)
if action == "EXIT" and held_qty != 0:
side = "sell" if held_qty > 0 else "buy"
self.submit_order(self.create_order(contract, abs(held_qty), side))
elif action == "BUY" and conviction >= min_conviction and trend_score >= 0.65 and held_qty == 0:
self.submit_order(self.create_order(contract, max_contracts, "buy"))
elif action == "SHORT" and conviction >= min_conviction and trend_score >= 0.65 and held_qty == 0:
self.submit_order(self.create_order(contract, max_contracts, "sell"))
if __name__ == "__main__":
from lumibot.credentials import IS_BACKTESTING
from lumibot.entities import TradingFee
if IS_BACKTESTING:
from lumibot.backtesting import InteractiveBrokersRESTBacktesting
fee = TradingFee(per_contract_fee=2.50)
FastDecisionTopstepXFuturesBot.backtest(
InteractiveBrokersRESTBacktesting,
buy_trading_fees=[fee],
sell_trading_fees=[fee],
)
else:
FastDecisionTopstepXFuturesBot().run_live()
Run it yourself¶
pip install lumibot
python -m lumibot.example_strategies.ai_fast_decision_topstepx_futures_bot
Add the decision-model key and your TopstepX (ProjectX) credentials to your .env file:
OPENAI_API_KEYforopenai/gpt-6-luna(default) orGEMINI_API_KEYforgoogle/gemini-decision-1PROJECTX_TOPSTEPX_USERNAME,PROJECTX_TOPSTEPX_API_KEY, andPROJECTX_TOPSTEPX_PREFERRED_ACCOUNT_NAMEfor live or funded TopstepX execution (see TopstepX / ProjectX Futures API Trading Bot in Python)
Set IS_BACKTESTING=true with BACKTESTING_START and BACKTESTING_END to backtest continuous futures with simulated $2.50 per-contract round-turn/side fees, or IS_BACKTESTING=false to run live on TopstepX.
Good to know¶
ES($50 per point) andNQ($20 per point) carry large notional exposure per contract; keepmax_contracts=1while verifying behavior, or test micro equivalents (MES/MNQ) first.AgentReplayCachereplays cachedself.agents.decide()decisions locally in sub-millisecond time during repeated backtest iterations (measured on local 100-bar benchmark:0.111 msp50 /0.217 msp95 on replay cache hit;0.618 msp50 /1.114 msp95 local serialization + cache-write overhead excluding network RTT).TopstepX accounts enforce daily loss limits and trailing drawdown rules; review your account rules and test on a practice account before enabling live execution.
See AI Trading Bot Examples for more AI trading bots, Fast Decision Models (self.agents.decide) for the Decisions API reference, and TopstepX / ProjectX Futures API Trading Bot in Python for TopstepX setup.