-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
72 lines (64 loc) · 2.02 KB
/
main.py
File metadata and controls
72 lines (64 loc) · 2.02 KB
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
# main.py
from colorama import Fore, Style, init as colorama_init
from dotenv import load_dotenv
import os
from funcs import (
init_db, PaperAccount, analyze_market, HELP,
get_db_path,show,info
)
load_dotenv()
def main():
colorama_init(autoreset=False) # good practice on Windows
acc_id = init_db(starting_cash=1_000_000.0, account_name="Main")
acct = PaperAccount(acc_id)
print(
f"{Fore.RED}{Style.BRIGHT}ProfitPlug: {Style.RESET_ALL}"
f"Your data is stored here -> "
f"{Fore.BLACK}{Style.DIM}{get_db_path()}{Style.RESET_ALL}"
)
acct.portfolio()
print(HELP)
while True:
try:
raw = input("> ").strip()
except (EOFError, KeyboardInterrupt):
print("\nSaving & exiting...")
acct.snapshot_on_exit()
break
if not raw:
continue
parts = raw.split()
cmd = parts[0].lower()
if cmd == "buy" and len(parts) == 3:
acct.buy(parts[1], int(parts[2]))
elif cmd == "sell" and len(parts) == 3:
acct.sell(parts[1], int(parts[2]))
elif cmd == "portfolio":
acct.portfolio()
elif cmd == "history":
acct.history()
elif cmd == "analyze":
analyze_market()
elif cmd == "show" and len(parts) == 2:
show(parts[1])
elif cmd == "reset":
acct.reset()
elif cmd == "info":
if len(parts) == 1:
info("list")
else:
info(" ".join(parts[1:]))
print("Tip: info rsi | info 'moving average' | info macro | info all")
elif cmd == "clear":
os.system('cls' if os.name == 'nt' else 'clear')
print(HELP)
elif cmd in ("quit", "exit"):
print("Saving & exiting...")
acct.snapshot_on_exit()
break
elif cmd == "help":
print(HELP)
else:
print("Unknown command. Type 'help'.")
if __name__ == "__main__":
main()