init
This commit is contained in:
62
hts/HTS.py
62
hts/HTS.py
@@ -262,7 +262,8 @@ class HTS:
|
||||
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")
|
||||
bConnect = objCpCybos.IsConnect
|
||||
if (bConnect == 0):
|
||||
@@ -274,8 +275,8 @@ class HTS:
|
||||
|
||||
objStockChart.SetInputValue(0, 'A'+stock_code) # 종목 코드
|
||||
objStockChart.SetInputValue(1, ord('2')) # 1: 기간으로 조회, 2: 개수로 조회
|
||||
objStockChart.SetInputValue(2, day) # 기간 조회 시, 시작일
|
||||
objStockChart.SetInputValue(3, day) # 기간 조회 시, 종료일
|
||||
objStockChart.SetInputValue(2, given_day) # 기간 조회 시, 시작일
|
||||
objStockChart.SetInputValue(3, given_day) # 기간 조회 시, 종료일
|
||||
objStockChart.SetInputValue(4, 400) # 조회 시 가져오는 Line 개수
|
||||
objStockChart.SetInputValue(5, [0, 1, 2, 3, 4, 5, 8]) # 날짜,시간,시가,고가,저가,종가,거래량
|
||||
objStockChart.SetInputValue(6, ord('S')) # '차트 주가 - 월(M), 주(W), 일(D), 시(H), 분(m), 초(S) 차트 요청
|
||||
@@ -287,7 +288,10 @@ class HTS:
|
||||
|
||||
#print("날짜", "시간", "시가", "고가", "저가", "종가", "거래량")
|
||||
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')
|
||||
if time < start_time:
|
||||
continue
|
||||
@@ -405,7 +409,7 @@ class HTS:
|
||||
|
||||
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['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.update_layout(title=day + "_2x")
|
||||
fig.update_layout(title=given_day + "_2x")
|
||||
fig.show()
|
||||
return
|
||||
|
||||
def simulate(self, stock_code, day):
|
||||
def simulate(self, stock_code, given_day):
|
||||
result = {"check": set(),
|
||||
"time": [],
|
||||
"open": [],
|
||||
@@ -451,16 +455,16 @@ class HTS:
|
||||
"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)
|
||||
|
||||
# 그래프를 그린다.
|
||||
self.draw(data, upper, lower, buy_line, sell_line)
|
||||
self.draw(given_day, data, upper, lower, buy_line, sell_line)
|
||||
|
||||
return
|
||||
|
||||
@@ -495,33 +499,33 @@ if __name__ == "__main__":
|
||||
RESOURCE_DIR = PROJECT_HOME + "/resources/analysis/"+today.strftime("%Y%m%d")
|
||||
|
||||
stock_code = "252670"
|
||||
day = datetime.today().strftime("%Y%m%d")
|
||||
given_day = datetime.today().strftime("%Y%m%d")
|
||||
|
||||
hts = HTS()
|
||||
#hts.all_stocks()
|
||||
#hts.getChartData(stock_code)
|
||||
#hts.currentStock(stock_code)
|
||||
#hts.printStockData(stock_code, day)
|
||||
#hts.printStockData(stock_code, given_day)
|
||||
|
||||
"""
|
||||
day = '20210909'
|
||||
hts.simulate(stock_code, day)
|
||||
day = '20210910'
|
||||
hts.simulate(stock_code, day)
|
||||
day = '20210913'
|
||||
hts.simulate(stock_code, day)
|
||||
day = '20210914'
|
||||
hts.simulate(stock_code, day)
|
||||
day = '20210915'
|
||||
hts.simulate(stock_code, day)
|
||||
day = '20210916'
|
||||
hts.simulate(stock_code, day)
|
||||
day = '20210917'
|
||||
hts.simulate(stock_code, day)
|
||||
given_day = '20210909'
|
||||
hts.simulate(stock_code, given_day)
|
||||
given_day = '20210910'
|
||||
hts.simulate(stock_code, given_day)
|
||||
given_day = '20210913'
|
||||
hts.simulate(stock_code, given_day)
|
||||
given_day = '20210914'
|
||||
hts.simulate(stock_code, given_day)
|
||||
given_day = '20210915'
|
||||
hts.simulate(stock_code, given_day)
|
||||
given_day = '20210916'
|
||||
hts.simulate(stock_code, given_day)
|
||||
given_day = '20210917'
|
||||
hts.simulate(stock_code, given_day)
|
||||
"""
|
||||
|
||||
day = '20210917'
|
||||
hts.simulate(stock_code, day)
|
||||
hts.buyRealTime(stock_code, day)
|
||||
given_day = '20210917'
|
||||
hts.simulate(stock_code, given_day)
|
||||
#hts.buyRealTime(stock_code, given_day)
|
||||
|
||||
print ("done...")
|
||||
|
||||
Reference in New Issue
Block a user