Example Bots
Real-world bot implementations demonstrating different patterns and strategies.
eurusdtreebot.py
Decision tree-based strategy for EUR/USD.
Pattern: Simple decisionFunction() with multiple thresholds
class EURUSDTreeBot(Bot):
def decisionFunction(self, row):
if row["trend_sma_slow"] <= self.sma_slow_threshold:
if row["trend_macd_signal"] <= self.macd_signal_threshold:
return -1
# ... more conditions
return 0
feargreedbot.py
Uses external Fear & Greed Index API.
Pattern: Override makeOneIteration() for external data
class FearGreedBot(Bot):
def makeOneIteration(self):
index = get_fear_greed_index()
if index < 20: # Extreme fear
self.buy("QQQ")
elif index > 80: # Extreme greed
self.sell("QQQ")
return 0
sharpeportfoliooptweekly.py
Portfolio optimization with Sharpe ratio.
Pattern: Complex makeOneIteration() for multi-asset optimization
class SharpePortfolioOptWeekly(Bot):
def makeOneIteration(self):
# Fetch multiple symbols
data = self.getYFDataMultiple(["QQQ", "GLD", "TLT"])
# Optimize portfolio
weights = optimize_sharpe_ratio(data)
# Rebalance
self.rebalancePortfolio(weights)
return 0
xauzenbot.py
Gold (XAU) trading bot.
Pattern: Simple decisionFunction() with RSI and MACD
gptbasedstrategytabased.py
GPT-based strategy with technical analysis.
Pattern: Uses LLM for decision making with TA indicators
aihedgefundbot.py
AI-driven portfolio rebalancing.
Pattern: Reads decisions from external database and rebalances
deepseektoolbot.py
AI-driven portfolio research and rebalancing with tools. The main LLM uses tools (market data, news, earnings, insider trades, portfolio, recent trades) to research symbols and submits target weights via a custom submit_portfolio_weights tool. The cheap LLM then sanity-checks the submitted weights; if it rejects them, the bot retries once with the main LLM. Requires OPENROUTER_API_KEY.
Pattern: Override get_ai_tools() for custom tools; use main LLM for tool flow, cheap LLM for output validation and fallback
ta_regime_bot.py (TARegimeAdaptiveBot)
Single-asset bot that uses only historic OHLCV and TA (no Fear & Greed). It classifies regime as trend vs mean reversion via a Hurst-style proxy (lag-1 autocorrelation of returns), then applies ADX/MACD/EMA in trend regime and RSI/Bollinger BBP (and optional z-score) in mean-reversion regime. All decision logic lives in utils.ta_regime; the bot only fetches data and delegates.
Pattern: Minimal bot; reusable logic in utils.ta_regime; decisionFunction(row) calls ta_regime_decision(row, self.data, **self._ta_params).
For the mathematical and quant concepts (Hurst, R/S, variance ratio, z-score, Hilbert/Ehlers, entropy) and source links, see TA Regime Bot: Mathematical and Quant Concepts.
Learning from Examples
Each example demonstrates: - Different implementation approaches - Common patterns and best practices - Real-world trading strategies - Error handling and edge cases
Next Steps
- Creating a Bot - Build your own
- Bot Class System - Understand patterns