init
This commit is contained in:
@@ -10,21 +10,8 @@ class BuySellChecker():
|
||||
PATTERNS = None
|
||||
RESOURCE_PATH = None
|
||||
|
||||
def __init__(self, RESOURCE_PATH, ticker):
|
||||
def __init__(self, RESOURCE_PATH, s):
|
||||
self.RESOURCE_PATH = RESOURCE_PATH
|
||||
self.readBuyPattern(RESOURCE_PATH, ticker)
|
||||
return
|
||||
|
||||
def readBuyPattern(self, RESOURCE_PATH, ticker):
|
||||
with open(os.path.join(RESOURCE_PATH, "buy_pattern_data.json"), 'r') as f:
|
||||
PATTERNS = json.load(f)
|
||||
|
||||
self.PATTERNS = {'min_max': [], 'stndardization': []}
|
||||
for key in PATTERNS:
|
||||
for min_max in PATTERNS[key]['min_max']:
|
||||
self.PATTERNS['min_max'].append(min_max)
|
||||
for stndardization in PATTERNS[key]['stndardization']:
|
||||
self.PATTERNS['stndardization'].append(stndardization)
|
||||
return
|
||||
|
||||
def nearDisparity(self, data, i):
|
||||
|
||||
73
hts/HTS.py
73
hts/HTS.py
@@ -120,7 +120,7 @@ class HTS:
|
||||
# 현재가 정보 조회
|
||||
code = self.objStockMst.GetHeaderValue(0) # 종목코드
|
||||
name = self.objStockMst.GetHeaderValue(1) # 종목명
|
||||
time = self.objStockMst.GetHeaderValue(4) # 시간
|
||||
ymd = self.objStockMst.GetHeaderValue(4) # 시간
|
||||
cprice = self.objStockMst.GetHeaderValue(11) # 종가
|
||||
diff = self.objStockMst.GetHeaderValue(12) # 대비
|
||||
open = self.objStockMst.GetHeaderValue(13) # 시가
|
||||
@@ -150,7 +150,7 @@ class HTS:
|
||||
print("예상체결가 대비", exDiff)
|
||||
print("예상체결수량", exVol)
|
||||
"""
|
||||
result = {'code': code, 'name': name, 'time': time, 'close': cprice, 'diff': diff, 'open': open, 'high': high,
|
||||
result = {'code': code, 'name': name, 'ymd': ymd, 'close': cprice, 'diff': diff, 'open': open, 'high': high,
|
||||
'low': low, 'offer': offer, 'bid': bid, 'vol': vol, 'vol_value': vol_value,
|
||||
'exFlag': exFlag, 'exPrice': exPrice, 'exDiff': exDiff, 'exVol': exVol}
|
||||
|
||||
@@ -422,13 +422,13 @@ class HTS:
|
||||
outfp.write("%s,%s,%s,%s,%s,%s,%s\n" % ("날짜", "시간", "시가", "고가", "저가", "종가", "거래량"))
|
||||
for i in range(size - 1, -1, -1):
|
||||
day = objStockChart.GetDataValue(0, i)
|
||||
time = objStockChart.GetDataValue(1, i)
|
||||
ymd = objStockChart.GetDataValue(1, i)
|
||||
start = objStockChart.GetDataValue(2, i)
|
||||
high = objStockChart.GetDataValue(3, i)
|
||||
low = objStockChart.GetDataValue(4, i)
|
||||
close = objStockChart.GetDataValue(5, i)
|
||||
vol = objStockChart.GetDataValue(6, i)
|
||||
outfp.write("%d,%s,%d,%d,%d,%d,%d\n" % (day, str(time).zfill(4), start, high, low, close, vol))
|
||||
outfp.write("%d,%s,%d,%d,%d,%d,%d\n" % (day, str(ymd).zfill(4), start, high, low, close, vol))
|
||||
outfp.close()
|
||||
|
||||
return
|
||||
@@ -459,14 +459,14 @@ class HTS:
|
||||
data = []
|
||||
for i in range(size - 1, -1, -1):
|
||||
day = objStockChart.GetDataValue(0, i)
|
||||
time = objStockChart.GetDataValue(1, i)
|
||||
ymd = objStockChart.GetDataValue(1, i)
|
||||
start = objStockChart.GetDataValue(2, i)
|
||||
high = objStockChart.GetDataValue(3, i)
|
||||
low = objStockChart.GetDataValue(4, i)
|
||||
close = objStockChart.GetDataValue(5, i)
|
||||
vol = objStockChart.GetDataValue(6, i)
|
||||
|
||||
data.append([day, str(time).zfill(4), start, high, low, close, vol])
|
||||
data.append([day, str(ymd).zfill(4), start, high, low, close, vol])
|
||||
|
||||
return data
|
||||
|
||||
@@ -503,10 +503,10 @@ class HTS:
|
||||
|
||||
outFp = open(day+".csv", mode="w", encoding="UTF-8")
|
||||
outFp.write("날짜,시간,시가,고가,저가,종가,거래량\n")
|
||||
for i in range(len(result["time"])):
|
||||
for i in range(len(result["ymd"])):
|
||||
outFp.write("%s,%s,%s,%s,%s,%s,%s\n"%(
|
||||
result["time"][i].strftime('%Y%m%d'),
|
||||
result["time"][i].strftime('%H%M'),
|
||||
result["ymd"][i].strftime('%Y%m%d'),
|
||||
result["ymd"][i].strftime('%H%M'),
|
||||
result["open"][i],
|
||||
result["high"][i],
|
||||
result["low"][i],
|
||||
@@ -522,23 +522,23 @@ class HTS:
|
||||
|
||||
for rows in reader:
|
||||
days = rows[0] # hts.날짜
|
||||
time = rows[1] # hts.시간
|
||||
ymd = rows[1] # hts.시간
|
||||
open_v = rows[2] # hts.시가
|
||||
high = rows[3] # hts.고가
|
||||
low = rows[4] # hts.저가
|
||||
close = rows[5] # hts.종가
|
||||
vol = rows[6] # hts.거래량
|
||||
|
||||
temp = datetime.strptime(str(days) + " " + str(time).zfill(4) + "00", '%Y%m%d %H%M%S')
|
||||
temp = datetime.strptime(str(days) + " " + str(ymd).zfill(4) + "00", '%Y%m%d %H%M%S')
|
||||
#if temp < start_time:
|
||||
# continue
|
||||
|
||||
result["time"].append(temp)
|
||||
result["ymd"].append(temp)
|
||||
result["open"].append(int(open_v))
|
||||
result["close"].append(int(close))
|
||||
result["high"].append(int(high))
|
||||
result["low"].append(int(low))
|
||||
result["vol"].append(int(vol))
|
||||
result["volume"].append(int(volume))
|
||||
return
|
||||
|
||||
def updateLabel(self, stock_code, bsLine, data, ymd):
|
||||
@@ -590,7 +590,7 @@ class HTS:
|
||||
|
||||
def getDBData(self, stock_code, day, result):
|
||||
|
||||
self.cursor.execute('SELECT ymd, hms, open, high, low, close, volume, label FROM hts WHERE CODE=? and ymd=? order by ymd, hms', (stock_code, day,))
|
||||
self.cursor.execute('SELECT ymd, hms, open, high, low, close, volume, label FROM hts WHERE CODE=? and ymd=? order by ymd, hms', (stock_code, day, ))
|
||||
db_result = self.cursor.fetchall()
|
||||
for rows in db_result:
|
||||
ymd = rows[0] # hts.날짜
|
||||
@@ -599,17 +599,17 @@ class HTS:
|
||||
high = rows[3] # hts.고가
|
||||
low = rows[4] # hts.저가
|
||||
close = rows[5] # hts.종가
|
||||
vol = rows[6] # hts.거래량
|
||||
volume = rows[6] # hts.거래량
|
||||
label = 0 if rows[7] is None else rows[7] # hts.매매구분
|
||||
|
||||
temp = datetime.strptime(str(ymd) + " " + str(hms).zfill(4) + "00", '%Y%m%d %H%M%S')
|
||||
|
||||
result["time"].append(temp)
|
||||
result["ymd"].append(temp)
|
||||
result["open"].append(int(open))
|
||||
result["close"].append(int(close))
|
||||
result["high"].append(int(high))
|
||||
result["low"].append(int(low))
|
||||
result["vol"].append(int(vol))
|
||||
result["volume"].append(int(volume))
|
||||
result["label"].append(int(label))
|
||||
|
||||
return
|
||||
@@ -622,14 +622,14 @@ class HTS:
|
||||
return True
|
||||
return False
|
||||
|
||||
def getLastData(self, stock_code, today, n=3):
|
||||
def getLastData(self, stock_code, today, n=7):
|
||||
result = {"check": set(),
|
||||
"time": [],
|
||||
"ymd": [],
|
||||
"open": [],
|
||||
"close": [],
|
||||
"high": [],
|
||||
"low": [],
|
||||
"vol": [],
|
||||
"volume": [],
|
||||
"label": []}
|
||||
|
||||
days = []
|
||||
@@ -652,7 +652,7 @@ class HTS:
|
||||
if LAST_DATA is not None:
|
||||
result = copy.deepcopy(LAST_DATA)
|
||||
else:
|
||||
result = {"check": set(), "time": [], "open": [], "close": [], "high": [], "low": [], "vol": [], "label": []}
|
||||
result = {"check": set(), "ymd": [], "open": [], "close": [], "high": [], "low": [], "volume": [], "label": []}
|
||||
|
||||
#### real time에서 아직 저장된 것이 없기 때문에 result는 아무것도 채워지지 않는다.
|
||||
self.getDBData(stock_code, today, result)
|
||||
@@ -689,35 +689,35 @@ class HTS:
|
||||
|
||||
if int_day < int_given_day:
|
||||
continue
|
||||
time = datetime.strptime(str(int_day)+" "+str(int_time).zfill(4)+"00", '%Y%m%d %H%M%S')
|
||||
if time < start_time:
|
||||
ymd = datetime.strptime(str(int_day)+" "+str(int_time).zfill(4)+"00", '%Y%m%d %H%M%S')
|
||||
if ymd < start_time:
|
||||
continue
|
||||
|
||||
open = objStockChart.GetDataValue(2, i)
|
||||
close = objStockChart.GetDataValue(5, i)
|
||||
high = objStockChart.GetDataValue(3, i)
|
||||
low = objStockChart.GetDataValue(4, i)
|
||||
vol = objStockChart.GetDataValue(6, i)
|
||||
volume = objStockChart.GetDataValue(6, i)
|
||||
|
||||
if len(result["check"]) == 0:
|
||||
result["check"].add(start_time)
|
||||
result["time"].append(start_time)
|
||||
result["ymd"].append(start_time)
|
||||
result["open"].append(open)
|
||||
result["close"].append(open)
|
||||
result["high"].append(open)
|
||||
result["low"].append(open)
|
||||
result["vol"].append(0)
|
||||
result["volume"].append(0)
|
||||
result["label"].append(0)
|
||||
|
||||
if time not in result["check"]:
|
||||
result["check"].add(time)
|
||||
result["time"].append(time)
|
||||
if ymd not in result["check"]:
|
||||
result["check"].add(ymd)
|
||||
result["ymd"].append(ymd)
|
||||
|
||||
result["open"].append(open)
|
||||
result["close"].append(close)
|
||||
result["high"].append(high)
|
||||
result["low"].append(low)
|
||||
result["vol"].append(vol)
|
||||
result["volume"].append(volume)
|
||||
result["label"].append(0)
|
||||
|
||||
return result
|
||||
@@ -757,8 +757,8 @@ class HTS:
|
||||
int_day = objStockChart.GetDataValue(0, i)
|
||||
int_time = objStockChart.GetDataValue(1, i)
|
||||
# ymd: '2022.03.29'
|
||||
# time = datetime.strptime(str(int_day)+" "+str(int_time).zfill(4)+"00", '%Y%m%d %H%M%S')
|
||||
# time_str = time.strftime('%Y.%m.%d')
|
||||
# ymd = datetime.strptime(str(int_day)+" "+str(int_time).zfill(4)+"00", '%Y%m%d %H%M%S')
|
||||
# time_str = ymd.strftime('%Y.%m.%d')
|
||||
today_str = today[0:4] + "." + today[4:6] + "." + today[6:8]
|
||||
|
||||
if i == 0:
|
||||
@@ -823,7 +823,7 @@ class HTS:
|
||||
return
|
||||
|
||||
def getClosePrice_realtime(self, stock_code, today):
|
||||
result = {"open": [], "close": [], "high": [], "low": [], "vol": []}
|
||||
result = {'ymd': [], "open": [], "close": [], "high": [], "low": [], "volume": []}
|
||||
|
||||
int_given_day = int(today)
|
||||
objCpCybos = win32com.client.Dispatch("CpUtil.CpCybos")
|
||||
@@ -853,18 +853,19 @@ class HTS:
|
||||
int_day = objStockChart.GetDataValue(0, i)
|
||||
int_time = objStockChart.GetDataValue(1, i)
|
||||
|
||||
time = datetime.strptime(str(int_day)+" "+str(int_time).zfill(4)+"00", '%Y%m%d %H%M%S')
|
||||
ymd = datetime.strptime(str(int_day)+" "+str(int_time).zfill(4)+"00", '%Y%m%d %H%M%S')
|
||||
|
||||
open = objStockChart.GetDataValue(2, i)
|
||||
close = objStockChart.GetDataValue(5, i)
|
||||
high = objStockChart.GetDataValue(3, i)
|
||||
low = objStockChart.GetDataValue(4, i)
|
||||
vol = objStockChart.GetDataValue(6, i)
|
||||
volume = objStockChart.GetDataValue(6, i)
|
||||
|
||||
result["ymd"].append(open)
|
||||
result["open"].append(open)
|
||||
result["close"].append(close)
|
||||
result["high"].append(high)
|
||||
result["low"].append(low)
|
||||
result["vol"].append(vol)
|
||||
result["volume"].append(volume)
|
||||
|
||||
return result
|
||||
Reference in New Issue
Block a user