-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinvestmentStrategy.py
59 lines (51 loc) · 1.59 KB
/
investmentStrategy.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
# import robin_stocks.robinhood as r
import pyotp
import signal
import sqlite3
import random
import time
from random import choices
from robinhoodDB import *
from loginInformation import *
from setup import *
from sell import *
from buy import *
from updateStocks import *
from datetime import date, datetime, timedelta, timezone
import dateutil
# Logs user in
def login_to_robinhood():
totp = pyotp.TOTP(getTOTPCode()).now()
login = r.login(getUsername(), getPassword(), mfa_code=totp)
def handler(signum, frame):
print("Forever is over!")
raise Exception("end of time")
#Buy and Sell commands to be run daily
def daily_run(conn):
market_hours = r.get_market_today_hours('XNYS')
general_market_open = True
if(market_hours.get('is_open')==False):
general_market_open = False
else:
curr_time = dateutil.parser.parse(datetime.now(timezone.utc).isoformat())
open_time =dateutil.parser.parse( market_hours.get("opens_at"))
close_time = dateutil.parser.parse(market_hours.get("closes_at"))
if(curr_time>=open_time and curr_time<=close_time):
general_market_open = True
else:
general_market_open = False
check_to_sell(conn, general_market_open)
check_to_sell_crypto(conn)
total_cash = float(r.load_account_profile("crypto_buying_power"))-200
if(total_cash>10):
buy_new_stocks(conn, total_cash, general_market_open)
def main():
login_to_robinhood()
print('yo')
conn = create_connection(database)
if(conn is not None):
daily_run(conn)
conn.close()
else:
print("Error! cannot create the database connection.")
main()