Skip to content

Commit

Permalink
Merge pull request #36 from siropkin/develop
Browse files Browse the repository at this point in the history
Add ability to exclude stocks from trading
  • Loading branch information
siropkin authored Dec 9, 2024
2 parents 19974ce + 5a75d1a commit e974d03
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 14 deletions.
17 changes: 9 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,11 @@ This is a scientific experiment to see how AI can trade stocks better than human

### Features
- **AI-Powered Trading**: Leverages OpenAI to provide smart, data-driven trading decisions.
- **Post-Decision Adjustments**: Refines trading moves based on trade outcomes.
- **Post-Decision Adjustments (beta)**: Refines trading moves based on trade outcomes.
- **Portfolio & Watchlist Integration**: Analyze and trade stocks from both your Robinhood portfolio and watchlist.
- **Customizable Parameters**: Set trading limits and conditions to fit your strategy.
- **Trading Exceptions**: Exclude specific stocks from trading.
- **Pattern Day Trader Protection (beta)**: Avoids PDT restrictions by considering the number of day trades.
- **Demo Mode**: Safely test trades without real execution.
- **Manual Mode**: Approve each trade individually.
- **Auto Mode**: Automate trades based on AI guidance.
Expand Down Expand Up @@ -296,20 +298,19 @@ LOG_LEVEL = "INFO" # Log level (DEBUG, INFO)
RUN_INTERVAL_SECONDS = 600 # Trading interval in seconds (if the market is open)
# Robinhood config parameters
TRADE_EXCEPTIONS = [] # List of stocks to exclude from trading (e.g. ["AAPL", "TSLA", "AMZN"])
WATCHLIST_NAMES = [] # Watchlist names (can be empty, or "My First List", "My Second List", etc.)
WATCHLIST_OVERVIEW_LIMIT = 10 # Number of stocks to process in decision-making (e.g. 20)
PORTFOLIO_LIMIT = 10 # Number of stocks to hold in the portfolio
# OpenAI config params
OPENAI_MODEL_NAME = "gpt-4o-mini" # OpenAI model name
MAX_POST_DECISIONS_ADJUSTMENTS = False # Maximum number of adjustments to make (False - disable adjustments)
# Trading parameters
MIN_SELLING_AMOUNT_USD = 1.0 # Minimum sell amount in USD (False - disable setting)
MAX_SELLING_AMOUNT_USD = 10.0 # Maximum sell amount in USD (False - disable setting)
MIN_BUYING_AMOUNT_USD = 1.0 # Minimum buy amount in USD (False - disable setting)
MAX_BUYING_AMOUNT_USD = 10.0 # Maximum buy amount in USD (False - disable setting)
PDT_PROTECTION = True # [Beta] Pattern day trader protection (False - disable protection). See: https://robinhood.com/us/en/support/articles/pattern-day-trade-protection/
PDT_PROTECTION = False # [Beta] Pattern day trader protection (False - disable protection). See: https://robinhood.com/us/en/support/articles/pattern-day-trade-protection/
# OpenAI config params
OPENAI_MODEL_NAME = "gpt-4o-mini" # OpenAI model name
MAX_POST_DECISIONS_ADJUSTMENTS = False # Maximum number of adjustments to make (False - disable adjustments)
```

### Run
Expand Down
11 changes: 5 additions & 6 deletions config.py.sample
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,16 @@ LOG_LEVEL = "INFO" # Log level (DEBUG, INFO, WARNING, E
RUN_INTERVAL_SECONDS = 600 # Trading interval in seconds (if the market is open)

# Robinhood config parameters
TRADE_EXCEPTIONS = [] # List of stocks to exclude from trading (e.g. ["AAPL", "TSLA", "AMZN"])
WATCHLIST_NAMES = [] # Watchlist names (can be empty, or "My First List", "My Second List", etc.)
WATCHLIST_OVERVIEW_LIMIT = 10 # Number of stocks to process in decision-making (e.g. 20)
PORTFOLIO_LIMIT = 10 # Number of stocks to hold in the portfolio

# OpenAI config params
OPENAI_MODEL_NAME = "gpt-4o-mini" # OpenAI model name
MAX_POST_DECISIONS_ADJUSTMENTS = False # Maximum number of adjustments to make (False - disable adjustments)

# Trading parameters
MIN_SELLING_AMOUNT_USD = 1.0 # Minimum sell amount in USD (False - disable setting)
MAX_SELLING_AMOUNT_USD = 10.0 # Maximum sell amount in USD (False - disable setting)
MIN_BUYING_AMOUNT_USD = 1.0 # Minimum buy amount in USD (False - disable setting)
MAX_BUYING_AMOUNT_USD = 10.0 # Maximum buy amount in USD (False - disable setting)
PDT_PROTECTION = False # [Beta] Pattern day trader protection (False - disable protection). See: https://robinhood.com/us/en/support/articles/pattern-day-trade-protection/

# OpenAI config params
OPENAI_MODEL_NAME = "gpt-4o-mini" # OpenAI model name
MAX_POST_DECISIONS_ADJUSTMENTS = False # [Beta] Maximum number of adjustments to make (False - disable adjustments)
9 changes: 9 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ def make_ai_decisions(buying_power, portfolio_overview, watchlist_overview):
constraints.append(f"- Buy Amounts Guidelines: {buy_guidelines}")
if len(symbols_under_limit) > 0:
constraints.append(f"- Stocks under PDT Limit: {', '.join(symbols_under_limit)}")
if len(TRADE_EXCEPTIONS) > 0:
constraints.append(f"- Trade Exceptions (exclude from trading in any decisions): {', '.join(TRADE_EXCEPTIONS)}")

ai_prompt = (
"**Decision-Making AI Prompt:**\n\n"
Expand Down Expand Up @@ -123,6 +125,8 @@ def make_ai_post_decisions_adjustment(buying_power, trading_results):
constraints.append(f"- Buy Amounts Guidelines: {buy_guidelines}")
if len(symbols_under_limit) > 0:
constraints.append(f"- Stocks under PDT Limit: {', '.join(symbols_under_limit)}")
if len(TRADE_EXCEPTIONS) > 0:
constraints.append(f"- Trade Exceptions (exclude from trading in any decisions): {', '.join(TRADE_EXCEPTIONS)}")

ai_prompt = (
"**Post-Decision Adjustments AI Prompt:**\n\n"
Expand Down Expand Up @@ -258,6 +262,11 @@ def trading_bot():
quantity = decision_data['quantity']
log_info(f"{symbol} > Decision: {decision} of {quantity}")

if symbol in TRADE_EXCEPTIONS:
trading_results[symbol] = {"symbol": symbol, "quantity": quantity, "decision": decision, "result": "error", "details": "Trade exception"}
log_warning(f"{symbol} > Decision skipped due to trade exception")
continue

if decision == "sell":
try:
sell_resp = sell_stock(symbol, quantity)
Expand Down

0 comments on commit e974d03

Please sign in to comment.