-
Notifications
You must be signed in to change notification settings - Fork 0
/
pymon.py
84 lines (64 loc) · 2.38 KB
/
pymon.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
import sys
from PyQt5.QtWidgets import *
import kiwoom
import time
import datetime
from pandas import DataFrame
MARKET_KOSPI = 0
MARKET_KOSDAQ = 10
class PyMon:
def __init__(self):
self.kiwoom = kiwoom.Kiwoom()
self.kiwoom.comm_connect()
self.get_code_list()
#코스피 코스닥
def get_code_list(self):
self.kospi_codes = self.kiwoom.get_code_list_by_market(MARKET_KOSPI)
self.kosdaq_codes = self.kiwoom.get_code_list_by_market(MARKET_KOSDAQ)
def get_ohlcv(self, code, start):
self.kiwoom.ohlcv = {'date': [], 'open': [], 'high': [], 'low': [], 'close': [], 'volume': []}
self.kiwoom.set_input_value("종목코드", code)
self.kiwoom.set_input_value("기준일자", start)
self.kiwoom.set_input_value("수정주가구분", 1)
self.kiwoom.comm_rq_data("opt10081_req", "opt10081", 0, "0101")
time.sleep(0.2)
df = DataFrame(self.kiwoom.ohlcv, columns=['open', 'high', 'low', 'close', 'volume'],
index=self.kiwoom.ohlcv['date'])
return df
def run(self):
buy_list = []
num = len(self.kosdaq_codes)
for i, code in enumerate(self.kosdaq_codes):
print(i, '/', num)
if self.check_speedy_rising_volume(code):
buy_list.append(code)
self.update_buy_list(buy_list)
#급등주 체크- 과거 20일간 거래량(현재 거래량 제외)보다 현재 거래량이 10배 이상일때 급등주 체킹
def check_speedy_rising_volume(self, code):
today = datetime.datetime.today().strftime("%Y%m%d")
df = self.get_ohlcv(code, today)
volumes = df['volume']
if len(volumes) < 21:
return False
sum_vol20 = 0
today_vol = 0
for i, vol in enumerate(volumes):
if i == 0:
today_vol = vol
elif 1 <= i <= 20:
sum_vol20 += vol
else:
break
avg_vol20 = sum_vol20 / 20
if today_vol > avg_vol20 * 10:
return True
#급등주를 매수 리스트에 추가
def update_buy_list(self, buy_list):
f = open("buy_list.txt", "wt")
for code in buy_list:
f.writelines("매수;%s;시장가;10;0;매수전\n" % (code))
f.close()
if __name__ == "__main__":
app = QApplication(sys.argv)
pymon = PyMon()
pymon.run()