This commit is contained in:
dsyoon
2023-01-12 12:40:51 +09:00
parent 34e57f2285
commit 9f9c7e290e
3 changed files with 86 additions and 3 deletions

View File

@@ -62,7 +62,7 @@ class HTS_252670_DAILY (HTS):
print ("START...")
THIS_TIME = datetime.now()
final_sell_check = False
LAST_DATA = self.dailyStatus.getLastData(self.stock_code, today)
LAST_DATA = self.dailyStatus.getLastData_realtime(self.stock_code, today)
while datetime.strptime(today + " 070000", '%Y%m%d %H%M%S') < THIS_TIME < datetime.strptime(today + " 153100", '%Y%m%d %H%M%S'):
@@ -72,7 +72,7 @@ class HTS_252670_DAILY (HTS):
if THIS_TIME < datetime.strptime(today + " 145000", '%Y%m%d %H%M%S'):
if THIS_TIME.strftime('%S') in ("06", "16", "26", "36", "46", "56"):
# 데이터를 가지고 온다.
result = self.getRealTime(self.stock_code, today, LAST_DATA)
result = self.getClosePrice_realtime(self.stock_code, today)
final_price = result["close"][len(result["close"])-1]
# 10초마다 체크하여 체결된 내역이 있으면 50원 높게 매도를 주문한다.

View File

@@ -67,7 +67,43 @@ class DailyStatus:
return True
return False
def getLastData(self, stock_code, today, n=10):
def getLastData(self, stock_code, today, n=100):
result = {
"ymd": [],
"open": [],
"close": [],
"high": [],
"low": [],
"envelope_upper": [],
"envelope_lower": [],
"envelope_middle": [],
"rsi": [],
"rsis": [],
"macd": [],
"macds": [],
"slow_k": [],
"slow_d": []
}
days = []
for i in range(1, n):
last_day = (datetime.strptime(today, '%Y%m%d') - timedelta(i)).strftime('%Y.%m.%d')
isValid = self.isValidYMD(stock_code, last_day)
if isValid:
days.append(last_day)
days = sorted(days)
for day in days:
self.getDBData(stock_code, day, result)
data = pd.DataFrame(result)
df_final_time = pd.DatetimeIndex(result['ymd'])
data.index = df_final_time
return data
def getLastData_realtime(self, stock_code, today, n=100):
result = {
"ymd": [],
"open": [],

View File

@@ -748,3 +748,50 @@ class HTS:
result["label"].append(0)
return result
def getClosePrice_realtime(self, stock_code, today):
result = {"open": [], "close": [], "high": [], "low": [], "vol": []}
int_given_day = int(today)
objCpCybos = win32com.client.Dispatch("CpUtil.CpCybos")
bConnect = objCpCybos.IsConnect
if (bConnect == 0):
print("PLUS가 정상적으로 연결되지 않음. ")
exit()
# 차트 객체 구하기
objStockChart = win32com.client.Dispatch("CpSysDib.StockChart")
objStockChart.SetInputValue(0, 'A'+stock_code) # 종목 코드
objStockChart.SetInputValue(1, ord('1')) # 1: 기간으로 조회, 2: 개수로 조회
objStockChart.SetInputValue(2, today) # 기간 조회 시, 시작일
objStockChart.SetInputValue(3, today) # 기간 조회 시, 종료일
objStockChart.SetInputValue(4, 10) # 조회 시 가져오는 Line 개수
objStockChart.SetInputValue(5, [0, 1, 2, 3, 4, 5, 8]) # 날짜,시간,시가,고가,저가,종가,거래량
objStockChart.SetInputValue(6, ord('m')) # '차트 주가 - 월(M), 주(W), 일(D), 시(H), 분(m), 초(S) 차트 요청
objStockChart.SetInputValue(7, 1)
objStockChart.SetInputValue(9, ord('1')) # 수정주가 사용
objStockChart.BlockRequest()
size = objStockChart.GetHeaderValue(3)
#print("날짜", "시간", "시가", "고가", "저가", "종가", "거래량")
i = size-1
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')
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)
result["open"].append(open)
result["close"].append(close)
result["high"].append(high)
result["low"].append(low)
result["vol"].append(vol)
return result