init
This commit is contained in:
49
HTS_etf.py
49
HTS_etf.py
@@ -6,7 +6,6 @@ from hts.HTS import HTS
|
||||
from hts.OrderType import OrderType
|
||||
|
||||
from hts.OrderChecker import OrderChecker
|
||||
from stock.util.LabelChecker import LabelChecker
|
||||
from stock.util.TelegramBot import TelegramBot
|
||||
from stock.analysis.StockStatus import StockStatus
|
||||
|
||||
@@ -46,7 +45,6 @@ class HTS_etf(HTS):
|
||||
self.stock_code = stock_code
|
||||
self.stock_name = stock_name
|
||||
self.orderChecker = OrderChecker(self.RESOURCE_PATH, self.stock_code)
|
||||
self.labelChecker = LabelChecker(RESOURCE_PATH)
|
||||
self.bot = TelegramBot()
|
||||
self.stockStatus = StockStatus(RESOURCE_PATH)
|
||||
|
||||
@@ -56,12 +54,18 @@ class HTS_etf(HTS):
|
||||
self.macd = MACD()
|
||||
self.ichimokuCloud = IchimokuCloud()
|
||||
|
||||
self.buySellChecker = BuySellChecker()
|
||||
self.buySellChecker = BuySellChecker(self.RESOURCE_PATH, self.stock_code)
|
||||
|
||||
return
|
||||
|
||||
def getBallance(self):
|
||||
return
|
||||
def getBallance(self, stock_code):
|
||||
jangoDic = self.requstJango()
|
||||
if jangoDic and len(jangoDic.keys()) > 0:
|
||||
for code in jangoDic:
|
||||
if stock_code is not None:
|
||||
if code == "A" + stock_code:
|
||||
return jangoDic[code]['장부가']
|
||||
return 0
|
||||
|
||||
def sellStocks(self, stock_code=None, bs_sell_price=None):
|
||||
check = False
|
||||
@@ -119,7 +123,7 @@ class HTS_etf(HTS):
|
||||
close = result["close"]
|
||||
high = result["high"]
|
||||
low = result["low"]
|
||||
volume = result["vol"]
|
||||
volume = result["volume"]
|
||||
|
||||
if "volume_down" in result:
|
||||
volume_down = result["volume_down"]
|
||||
@@ -208,7 +212,7 @@ class HTS_etf(HTS):
|
||||
upper.append(upper_df.values[i][0])
|
||||
lower.append(lower_df.values[i][0])
|
||||
|
||||
point_temp = result["time"]
|
||||
point_temp = result["ymd"]
|
||||
STOCK = []
|
||||
if "volume_up" in result and "volume_updown_diff" in result:
|
||||
for i in range(len(open)):
|
||||
@@ -297,23 +301,23 @@ class HTS_etf(HTS):
|
||||
|
||||
def makeTickData(self, data, mins=30):
|
||||
result = {"check": set(),
|
||||
"time": [],
|
||||
"ymd": [],
|
||||
"open": [],
|
||||
"close": [],
|
||||
"high": [],
|
||||
"low": [],
|
||||
"vol": [],
|
||||
"volume": [],
|
||||
"label": []}
|
||||
|
||||
for i in range(mins, len(data['time']) + 1):
|
||||
result["check"].add(data['time'][i - 1])
|
||||
result["time"].append(data['time'][i - 1])
|
||||
for i in range(mins, len(data['ymd']) + 1):
|
||||
result["check"].add(data['ymd'][i - 1])
|
||||
result["ymd"].append(data['ymd'][i - 1])
|
||||
|
||||
result["open"].append(data['open'][i - mins])
|
||||
result["close"].append(data['close'][i - 1])
|
||||
result["high"].append(max(data['high'][i - mins: i]))
|
||||
result["low"].append(min(data['low'][i - mins: i]))
|
||||
result["vol"].append(sum(data['vol'][i - mins: i]))
|
||||
result["volume"].append(sum(data['volume'][i - mins: i]))
|
||||
|
||||
return result
|
||||
|
||||
@@ -380,11 +384,11 @@ class HTS_etf(HTS):
|
||||
|
||||
LAST_DATA = self.getLastData(self.stock_code, today)
|
||||
|
||||
while datetime.strptime(today + " 063000", '%Y%m%d %H%M%S') < THIS_TIME < datetime.strptime(today + " 153100",'%Y%m%d %H%M%S'):
|
||||
if datetime.strptime(today + " 090000", '%Y%m%d %H%M%S') < THIS_TIME < datetime.strptime(today + " 090100", '%Y%m%d %H%M%S'):
|
||||
while datetime.strptime(today + " 000000", '%Y%m%d %H%M%S') < THIS_TIME < datetime.strptime(today + " 153100",'%Y%m%d %H%M%S'):
|
||||
if datetime.strptime(today + " 000000", '%Y%m%d %H%M%S') < THIS_TIME < datetime.strptime(today + " 090100", '%Y%m%d %H%M%S'):
|
||||
self.bot.sendMsg("START... {} ({}) SLOW_K: {}".format(self.stock_code, self.stock_name, MAX_PRICE))
|
||||
|
||||
if datetime.strptime(today + " 090000", '%Y%m%d %H%M%S') < THIS_TIME < datetime.strptime(today + " 151500", '%Y%m%d %H%M%S'):
|
||||
if datetime.strptime(today + " 000000", '%Y%m%d %H%M%S') < THIS_TIME < datetime.strptime(today + " 151500", '%Y%m%d %H%M%S'):
|
||||
|
||||
# 매도를 체크한다.
|
||||
check = self.sellStocks(self.stock_code)
|
||||
@@ -405,9 +409,9 @@ class HTS_etf(HTS):
|
||||
continue
|
||||
|
||||
result_tic_m1 = self.makeTickData1(result_m1, mins=1)
|
||||
data = self.buySellChecker.analyze(result_tic_m1)
|
||||
data = self.analyze(result_tic_m1)
|
||||
result_tic_m30 = self.makeTickData2(result_tic_m1, mins=30)
|
||||
data_signal = self.buySellChecker.analyze(result_tic_m30)
|
||||
data_signal = self.analyze(result_tic_m30)
|
||||
|
||||
#data.drop(data.index[:len(data) - analyzed_day], inplace=True)
|
||||
|
||||
@@ -447,14 +451,9 @@ class HTS_etf(HTS):
|
||||
|
||||
|
||||
if (int(THIS_TIME.strftime("%M")) % 50 == 0 or int(THIS_TIME.strftime("%M")) % 20 == 0):
|
||||
self.bot.alarm_live(self.stock_code, self.stock_name, data["close"][len(data["close"])-1], data["macd"][len(data["macd"])-1])
|
||||
self.bot.alarm_live(self.stock_code, self.stock_name)
|
||||
|
||||
time.sleep(60)
|
||||
THIS_TIME = datetime.now()
|
||||
|
||||
return True
|
||||
|
||||
def updteTodayStock(self, stock_code, today_str):
|
||||
bsLine, data = self.labelChecker.makeCandidate(stock_code, today_str)
|
||||
self.labelChecker.updateLabel(stock_code, bsLine, data, today_str)
|
||||
return
|
||||
return True
|
||||
@@ -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
|
||||
@@ -25,9 +25,6 @@ from stock.analysis.MACD import MACD
|
||||
from stock.analysis.Envelope import Envelope
|
||||
from stock.analysis.MovingAverage import MovingAverage
|
||||
|
||||
from hts.BuySellChecker import BuySellChecker
|
||||
|
||||
|
||||
class AnalyzerSqlite:
|
||||
stochastic = None
|
||||
bolingerBand = None
|
||||
@@ -45,8 +42,6 @@ class AnalyzerSqlite:
|
||||
|
||||
moving_avg = None
|
||||
|
||||
buySellChecker = None
|
||||
|
||||
def __init__(self, stockFileName=None):
|
||||
self.common = Common()
|
||||
|
||||
@@ -57,8 +52,6 @@ class AnalyzerSqlite:
|
||||
self.macd = MACD()
|
||||
self.envelope = Envelope()
|
||||
|
||||
self.buySellChecker = BuySellChecker()
|
||||
|
||||
if stockFileName is not None:
|
||||
self.stockFileName = stockFileName
|
||||
self.topCompany = self.getTopCompany(stockFileName, 2000)
|
||||
|
||||
@@ -12,7 +12,6 @@ from sklearn.linear_model import LinearRegression
|
||||
from sklearn.preprocessing import StandardScaler, MinMaxScaler
|
||||
|
||||
from hts.HTS import HTS
|
||||
from hts.BuySellChecker import BuySellChecker
|
||||
from stock.analysis.AnalyzerSqlite import AnalyzerSqlite
|
||||
|
||||
class StockStatus (HTS):
|
||||
@@ -29,7 +28,6 @@ class StockStatus (HTS):
|
||||
self.dbFileName = "stock.db"
|
||||
|
||||
self.analyzerSqlite = AnalyzerSqlite(os.path.join(self.RESOURCE_PATH, self.dbFileName))
|
||||
self.buySellChecker = BuySellChecker()
|
||||
|
||||
return
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ class LabelChecker (HTS):
|
||||
|
||||
def __init__(self, RESOURCE_PATH):
|
||||
super().__init__(RESOURCE_PATH)
|
||||
self.buySellChecker = BuySellChecker()
|
||||
self.buySellChecker = BuySellChecker(RESOURCE_PATH)
|
||||
self.stock2Vector = Stock2Vector(RESOURCE_PATH)
|
||||
return
|
||||
|
||||
|
||||
Reference in New Issue
Block a user