pymonitor.py
import sys
from PyQt5.QtWidgets import *
import time
import datetime
from pandas import DataFrame
import Kiwoom
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.5)
df = DataFrame(self.kiwoom.ohlcv, columns=['open', 'high', 'low', 'close', 'volume'],
index=self.kiwoom.ohlcv['date'])
return df
# 거래량 급등 종목 포착
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 run(self):
# kospi/kosdaq conde 4개 출력
# print(self.kospi_codes[0:4])
# print(self.kosdaq_codes[0:4])
# 봉데이터 가져오기
# df = self.get_ohlcv("001550", "20220318")
# print(df)
# 급등주 포착
num = len(self.kosdaq_codes)
for i, code in enumerate(self.kosdaq_codes):
print(i, '/', num)
if self.check_speedy_rising_volume(code):
print("급등주: ", code, ' / ', self.kiwoom.get_master_code_name(code))
if __name__ == "__main__":
app = QApplication(sys.argv)
pymon = PyMon()
pymon.run()
'python 기본개념' 카테고리의 다른 글
네이버 증권 크롤링 (0) | 2022.03.18 |
---|---|
보유종목현황 (0) | 2022.03.17 |
주문창 구현 (0) | 2022.03.17 |
pyinstaller로 만든 실행파일(exe) 에러처리 (0) | 2022.03.15 |
pycharm 실행파일 만들기 (0) | 2022.03.15 |
댓글