-
Notifications
You must be signed in to change notification settings - Fork 4
/
main.py
53 lines (42 loc) · 2.06 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
from cc import writeCcs
import time
from configuration import apiKey, apiRedirectUri, debugMarketOpen
from api import Api
import datetime
import alert
import support
api = Api(apiKey, apiRedirectUri)
try:
while True:
api.connect()
execWindow = api.getOptionExecutionWindow()
rollDate1Am = support.getDeltaDiffNowNextRollDate1Am()
tomorrow1Am = support.getDeltaDiffNowTomorrow1Am()
if rollDate1Am is not None and tomorrow1Am < rollDate1Am:
# we don't need to do anything, but we are making a call every day to make sure the refresh token stays valid
print('Token refreshed, waiting for roll date in %s' % rollDate1Am)
time.sleep(tomorrow1Am.total_seconds())
else:
if debugMarketOpen or execWindow['open']:
print('Market open, running the program now ...')
writeCcs(api)
nextRollDate = support.getDeltaDiffNowNextRollDate1Am()
print('All done. The next roll date is in %s' % nextRollDate)
# we are making a call every day to make sure the refresh token stays valid
time.sleep(tomorrow1Am.total_seconds())
else:
if execWindow['openDate']:
print('Waiting for execution window to open ...')
delta = execWindow['openDate'] - execWindow['nowDate']
if delta > datetime.timedelta(0):
print('Window open in: %s. waiting ...' % delta)
time.sleep(delta.total_seconds())
else:
# we are past open date, but the market is not open
print('Market closed already. Rechecking tomorrow (in %s)' % tomorrow1Am)
time.sleep(tomorrow1Am.total_seconds())
else:
print('The market is closed today, rechecking in 1 hour ...')
time.sleep(support.defaultWaitTime)
except Exception as e:
alert.botFailed(None, 'Uncaught exception: ' + str(e))