-
-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathmain.py
184 lines (157 loc) · 8.88 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
# BSD 3-Clause License
#
# Copyright (c) 2023-Present, Prem Patel
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# 3. Neither the name of the copyright holder nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
import os
import json
import sys
import argparse
import shutil
import traceback
import subprocess
from dotenv import load_dotenv
load_dotenv()
parser = argparse.ArgumentParser(description="Process stock trading arguments.")
parser.add_argument("tickers", nargs='?', default="JOB", help="Tickers to process")
args = parser.parse_args()
TICKERS = args.tickers.upper()
if "," in TICKERS: print(f"{'-'*100}\nTICKERS passed:\t{TICKERS}\n{'-'*40}")
FILE_TASK_MAP = {
"CHASE_AI": {"file": os.path.join("src", "Selenium_IDE", "Chase_Auto.side"), "task": ""},
"FIRSTRADE_AI": {"file": os.path.join("src", "Selenium_IDE", "Firstrade_Auto.side"), "task": ""},
"VANGUARD_AI": {"file": os.path.join("src", "Selenium_IDE", "Vanguard_Auto.side"), "task": ""},
"FIDELITY_AI": {"file": os.path.join("src", "Selenium_IDE", "Fidelity_Auto.side"), "task": ""},
"SCHWAB_AI": {"file": os.path.join("src", "Selenium_IDE", "Schwab_Auto.side"), "task": ""},
"SOFI_AI": {"file": os.path.join("src","Selenium_IDE","Sofi Helper.side"), "task": ""},
"ALLY_AI": {"file": os.path.join("src", "Selenium_IDE", "Ally_Auto.side"), "task": ""},
"MERRILL_AI": {"file": os.path.join("src", "Selenium_IDE", "Merrill_Auto.side"), "task": ""},
}
CUSTOM_DIR = os.environ.get("CUSTOM_DIR", os.path.join(os.path.expanduser('~'), 'Desktop', 'AutoStockTrader'))
os.makedirs(CUSTOM_DIR, exist_ok=True)
FILES = []
LOGINS = []
def main():
result = subprocess.run(['git', 'pull'], capture_output=True, text=True)
if 'Your local changes to the following files would be overwritten by merge' in result.stderr:
subprocess.run(['git', 'reset', '--hard'], check=True)
result = subprocess.run(['git', 'pull'], capture_output=False, text=False)
if CUSTOM_DIR:
dest_path = os.path.join(CUSTOM_DIR, "Account_Management_Tools.side")
try: shutil.copyfile(os.path.join("src", "Selenium_IDE", "Account_Management_Tools.side"), dest_path)
except shutil.SameFileError: pass
print('-'*100)
for var_name, info in FILE_TASK_MAP.items():
if os.environ.get(var_name):
FILES.append(info["file"])
print(f"{var_name} is enabled.")
if var_name == "SCHWAB_AI":
info["task"] = "Array.from({length: " + os.environ[var_name] + "}, (_, i) => i);"
elif var_name == "MERRILL_AI" or var_name == "VANGUARD_AI":
info["task"] = "Array.from({length: " +os.environ[var_name] + "}, (_, i) => i + 1);"
else:
info["task"] = os.environ[var_name].replace(" ", "")
try:
LOGINS.append(os.environ[var_name.split("_")[0] + "_LOGIN"])
except:
LOGINS.append("LOGIN:HERE")
else:
print(f"{var_name} is disabled. Skipping...")
print(f'\n{"-"*100}\n')
for filePath in FILES:
task = ""
for var_name, info in FILE_TASK_MAP.items():
if info["file"].lower() in filePath.lower():
task = info["task"]
break
# Load the JSON data
with open(filePath, 'r') as file:
data = json.load(file)
for test in data['tests']:
for command in test['commands']:
# Store Login information, if provided
if command['command'] == 'store' and 'LOGIN' in command['value']:
command['target'] = LOGINS.pop(0)
# Update Ticker, if provided
if TICKERS is not None and command['value'] == 'TICKER':
command['target'] = f"return '{TICKERS}'" if command['command'] == 'executeScript' else TICKERS
if command['command'] == 'store' and command['value'] == 'dynamic':
command['target'] = os.environ.get("DYNAMIC", 0)
# Update the account number(s) and break to next test
if command['command'] == 'executeScript' and command['value'] == 'accounts':
command['target'] = f"return {task}"
break
if os.name == 'nt':
filePath = filePath.replace("src\\Selenium_IDE\\", "")
filePath = filePath.replace("src\\X_Archive\\", "")
filePath = f'{CUSTOM_DIR}/{filePath}' if CUSTOM_DIR else f'ENV-{filePath}'
elif os.name == 'posix':
filePath = os.path.join("src", "Selenium_IDE", filePath.replace("src/Selenium_IDE/", ""))
filePath = os.path.join("src", "X_Archive", filePath.replace("src/X_Archive/", ""))
filePath = os.path.join(CUSTOM_DIR, filePath) if CUSTOM_DIR else f'ENV-{filePath}'
# Create a new file with the updated data
with open(filePath, 'w') as file:
json.dump(data, file, indent=2)
print(f"Created/Updated:\t{filePath}!")
if CUSTOM_DIR and len(sys.argv) != 2:
os.startfile(CUSTOM_DIR)
try:
directory = os.path.dirname(os.path.abspath(__file__))
is_windows = os.name == 'nt'
desktop_path = os.path.join(os.environ['USERPROFILE'], 'Desktop', 'RSA-QuickStart.bat') if is_windows else os.path.join(os.path.expanduser('~'), 'Desktop', 'RSA-QuickStart.sh')
source_path = os.path.join(directory, 'src', 'Helper_Scripts', 'RSA-QuickStart.bat') if is_windows else os.path.join(directory, 'src', 'Helper_Scripts', 'RSA-QuickStart.sh')
shutil.copyfile(source_path, desktop_path)
print(f"Created/Updated:\t{desktop_path}")
with open(desktop_path, 'r') as file:
content = file.read()
content = content.replace('set directory=', f'set directory={directory}') if is_windows else content.replace('export DIRECTORY=', f'export DIRECTORY={directory}')
with open(desktop_path, 'w') as file:
file.write(content)
except FileNotFoundError:
print(f'Encountered File Not Found Error: {traceback.format_exc()}\n')
return
except Exception as e:
print(f"An unexpected error occurred: {e}")
traceback.print_exc()
return
if __name__ == "__main__":
main()
print(f"""
=========================================================================================================
Script Execution Complete
---------------------------------------------------------------------------------------------------------
Free Public Version - Limited Features/Support
(C) Prem-ium
---------------------------------------------------------------------------------------------------------
Upgrading to Gold Sponsorship unlocks exclusive features, including:
- Faster, reliable Python/Selenium IDE scripts with consolidated brokerage automation.
- Seamless automation with automated limit prices and account retrieval.
- Exclusive setup and customization options via .env and command line arguments.
- Automated cash transfer/withdrawal tools for Fidelity, Chase, and more.
- WellsTrade & Robinhood automation support.
Join here: https://github.com/login?return_to=%2Fsponsors%2FPrem-ium%2Fsponsorships%3Ftier_id%3D308205
Thank you for your support!
=========================================================================================================""")