This commit is contained in:
dosangyoon
2021-09-22 21:42:01 +09:00
parent b3e1f4cf9c
commit 4c0ab75765

View File

@@ -262,7 +262,8 @@ class HTS:
return return
# 주식 현재가 조회 # 주식 현재가 조회
def getRealTime(self, stock_code, day, result): def getRealTime(self, stock_code, given_day, result):
int_given_day = int(given_day)
objCpCybos = win32com.client.Dispatch("CpUtil.CpCybos") objCpCybos = win32com.client.Dispatch("CpUtil.CpCybos")
bConnect = objCpCybos.IsConnect bConnect = objCpCybos.IsConnect
if (bConnect == 0): if (bConnect == 0):
@@ -274,8 +275,8 @@ class HTS:
objStockChart.SetInputValue(0, 'A'+stock_code) # 종목 코드 objStockChart.SetInputValue(0, 'A'+stock_code) # 종목 코드
objStockChart.SetInputValue(1, ord('2')) # 1: 기간으로 조회, 2: 개수로 조회 objStockChart.SetInputValue(1, ord('2')) # 1: 기간으로 조회, 2: 개수로 조회
objStockChart.SetInputValue(2, day) # 기간 조회 시, 시작일 objStockChart.SetInputValue(2, given_day) # 기간 조회 시, 시작일
objStockChart.SetInputValue(3, day) # 기간 조회 시, 종료일 objStockChart.SetInputValue(3, given_day) # 기간 조회 시, 종료일
objStockChart.SetInputValue(4, 400) # 조회 시 가져오는 Line 개수 objStockChart.SetInputValue(4, 400) # 조회 시 가져오는 Line 개수
objStockChart.SetInputValue(5, [0, 1, 2, 3, 4, 5, 8]) # 날짜,시간,시가,고가,저가,종가,거래량 objStockChart.SetInputValue(5, [0, 1, 2, 3, 4, 5, 8]) # 날짜,시간,시가,고가,저가,종가,거래량
objStockChart.SetInputValue(6, ord('S')) # '차트 주가 - 월(M), 주(W), 일(D), 시(H), 분(m), 초(S) 차트 요청 objStockChart.SetInputValue(6, ord('S')) # '차트 주가 - 월(M), 주(W), 일(D), 시(H), 분(m), 초(S) 차트 요청
@@ -287,7 +288,10 @@ class HTS:
#print("날짜", "시간", "시가", "고가", "저가", "종가", "거래량") #print("날짜", "시간", "시가", "고가", "저가", "종가", "거래량")
start_time = datetime.strptime(day + " 090000", '%Y%m%d %H%M%S') start_time = datetime.strptime(day + " 090000", '%Y%m%d %H%M%S')
for i in range(size): for i in range(size-1, -1, -1):
day = objStockChart.GetDataValue(0, i)
if day < int_given_day:
continue
time = datetime.strptime(day+" "+str(objStockChart.GetDataValue(1, i)), '%Y%m%d %H%M%S') time = datetime.strptime(day+" "+str(objStockChart.GetDataValue(1, i)), '%Y%m%d %H%M%S')
if time < start_time: if time < start_time:
continue continue
@@ -405,7 +409,7 @@ class HTS:
return data, upper_temp, lower_temp, buy_line, sell_line return data, upper_temp, lower_temp, buy_line, sell_line
def draw(self, data, upper, lower, buy_line, sell_line): def draw(self, given_day, data, upper, lower, buy_line, sell_line):
# 그래프 설정을 위한 변수를 생성한다. # 그래프 설정을 위한 변수를 생성한다.
data['Open'] = pd.to_numeric(data['Open']) data['Open'] = pd.to_numeric(data['Open'])
data['High'] = pd.to_numeric(data['High']) data['High'] = pd.to_numeric(data['High'])
@@ -437,11 +441,11 @@ class HTS:
# 그래프를 그린다. # 그래프를 그린다.
fig = go.Figure(data=[candle_stick, bolinger_upper, bolinger_lower, buy_check, sell_check]) fig = go.Figure(data=[candle_stick, bolinger_upper, bolinger_lower, buy_check, sell_check])
fig.update_layout(title=day + "_2x") fig.update_layout(title=given_day + "_2x")
fig.show() fig.show()
return return
def simulate(self, stock_code, day): def simulate(self, stock_code, given_day):
result = {"check": set(), result = {"check": set(),
"time": [], "time": [],
"open": [], "open": [],
@@ -451,16 +455,16 @@ class HTS:
"vol": []} "vol": []}
# 데이터를 가지고 온다. # 데이터를 가지고 온다.
self.getCSV(day+".csv", day, result) self.getCSV(given_day+".csv", given_day, result)
# 가져온 만큼 데이터를 누적해서 파일로 작성한다. # 가져온 만큼 데이터를 누적해서 파일로 작성한다.
self.write(day, result) self.write(given_day, result)
# 분석을 통해서 볼린저밴드 상/하단을 계산한다. # 분석을 통해서 볼린저밴드 상/하단을 계산한다.
data, upper, lower, buy_line, sell_line = self.analyze(result) data, upper, lower, buy_line, sell_line = self.analyze(result)
# 그래프를 그린다. # 그래프를 그린다.
self.draw(data, upper, lower, buy_line, sell_line) self.draw(given_day, data, upper, lower, buy_line, sell_line)
return return
@@ -495,33 +499,33 @@ if __name__ == "__main__":
RESOURCE_DIR = PROJECT_HOME + "/resources/analysis/"+today.strftime("%Y%m%d") RESOURCE_DIR = PROJECT_HOME + "/resources/analysis/"+today.strftime("%Y%m%d")
stock_code = "252670" stock_code = "252670"
day = datetime.today().strftime("%Y%m%d") given_day = datetime.today().strftime("%Y%m%d")
hts = HTS() hts = HTS()
#hts.all_stocks() #hts.all_stocks()
#hts.getChartData(stock_code) #hts.getChartData(stock_code)
#hts.currentStock(stock_code) #hts.currentStock(stock_code)
#hts.printStockData(stock_code, day) #hts.printStockData(stock_code, given_day)
""" """
day = '20210909' given_day = '20210909'
hts.simulate(stock_code, day) hts.simulate(stock_code, given_day)
day = '20210910' given_day = '20210910'
hts.simulate(stock_code, day) hts.simulate(stock_code, given_day)
day = '20210913' given_day = '20210913'
hts.simulate(stock_code, day) hts.simulate(stock_code, given_day)
day = '20210914' given_day = '20210914'
hts.simulate(stock_code, day) hts.simulate(stock_code, given_day)
day = '20210915' given_day = '20210915'
hts.simulate(stock_code, day) hts.simulate(stock_code, given_day)
day = '20210916' given_day = '20210916'
hts.simulate(stock_code, day) hts.simulate(stock_code, given_day)
day = '20210917' given_day = '20210917'
hts.simulate(stock_code, day) hts.simulate(stock_code, given_day)
""" """
day = '20210917' given_day = '20210917'
hts.simulate(stock_code, day) hts.simulate(stock_code, given_day)
hts.buyRealTime(stock_code, day) #hts.buyRealTime(stock_code, given_day)
print ("done...") print ("done...")