forked from happineer/system_trading
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcollect_stock_data_kosdaq.py
More file actions
68 lines (57 loc) · 2.32 KB
/
Copy pathcollect_stock_data_kosdaq.py
File metadata and controls
68 lines (57 loc) · 2.32 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
import os
import pdb
import sys
import time
from pymongo import MongoClient
from config import config_manager
import datetime as datetime_m
from datetime import datetime, timedelta
from util.slack import Slack
def delay_min(t):
for curr_time in range(t)[::-1]:
print("delay(min) -> %s / %s" % (curr_time, t))
time.sleep(60)
def main(duration_list):
mongo = MongoClient()
db = mongo.TopTrader
today = datetime.today()
end_date = datetime(today.year, today.month, today.day, 16, 0, 0)
slack = Slack(config_manager.get_slack_token())
for duration in duration_list:
slack.send_message("[Automation] Start to collect stock data -> {}".format(duration))
while True:
cmd = "python collect_stock_data_time_unit_kosdaq.py {}".format(duration)
print(cmd)
os.system(cmd)
error_status = db.urgent2.find({'type': 'error'}).next()
ret = error_status['error_code']
print("ret_code:{} -> python collect_stock_data_time_unit_kosdaq.py {}".format(ret, duration))
if ret == -100: # kiwoom server check time (mon~sat)
delay = 20
print("Delay {} minutes due to Kiwoom server check time. Mon~Sat".format(delay))
print("Until : {}".format(datetime.today() + timedelta(minutes=delay)))
delay_min(delay)
elif ret == -101: # kiwoom server check time (mon~sat)
delay = 45
print("Delay {} minutes due to Kiwoom server check time. Sun".format(delay))
print("Until : {}".format(datetime.today() + timedelta(minutes=delay)))
delay_min(delay)
cur = db.time_series_temp2.find({'type': duration})
if cur.count() == 0: # exception case.. retry
continue
status = cur.next()
if status['last'] == (status['total']-1) and status['end_date'] == end_date:
print("Collecting & Storing Stock {} Data is completed!".format(duration))
break
slack.send_message("[Automation] Complete to collect stock data -> {}".format(duration))
if __name__ == "__main__":
main([
"min1",
# "min3",
# "min5",
# "min10",
# "min60",
# "day",
# "week",
# "month"
])