-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
479fc79
commit 1d7fbcb
Showing
1 changed file
with
29 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
from selenium import webdriver | ||
from webdriver_manager.chrome import ChromeDriverManager | ||
|
||
def rule_based_trading_bot(stock_symbol): | ||
stock_data = get_stock_data(stock_symbol) | ||
stock_data = moving_average_crossover_strategy(stock_data) | ||
|
||
# Use Selenium to automate login to TD Ameritrade website | ||
driver = webdriver.Chrome(ChromeDriverManager().install()) | ||
driver.get("https://www.tdameritrade.com/login.page") | ||
driver.find_element_by_id("username").send_keys("YOUR_USERNAME") | ||
driver.find_element_by_id("password").send_keys("YOUR_PASSWORD") | ||
driver.find_element_by_id("accept").click() | ||
|
||
# Use Selenium to automate trades | ||
for i in range(len(stock_data)): | ||
if stock_data.iloc[i]["position"] == 1: | ||
# Use Selenium to navigate to trade page and enter trade details | ||
driver.get("https://www.tdameritrade.com/trading") | ||
driver.find_element_by_id("symbol").send_keys(stock_symbol) | ||
driver.find_element_by_id("order-quantity").send_keys("1") | ||
driver.find_element_by_id("submit-button").click() | ||
elif stock_data.iloc[i]["position"] == -1: | ||
# Use Selenium to navigate to trade page and enter trade details | ||
driver.get("https://www.tdameritrade.com/trading") | ||
driver.find_element_by_id("symbol").send_keys(stock_symbol) | ||
driver.find_element_by_id("order-quantity").send_keys("1") | ||
driver.find_element_by_id("submit-button").click() | ||
driver.quit() |