This commit is contained in:
dosangyoon
2021-09-23 02:59:27 +09:00
parent 47b1676606
commit 87f132830b

View File

@@ -186,7 +186,8 @@ class HTS:
# 주식 매도 주문
acc = objTrade.AccountNumber[0] # 계좌번호
accFlag = objTrade.GoodsList(acc, 1) # 주식상품 구분
print(acc, accFlag[0])
# acc = "782446178"
# accFlag[0] = "01"
objStockOrder = win32com.client.Dispatch("CpTrade.CpTd0311")
objStockOrder.SetInputValue(0, "1") # 1: 매도
objStockOrder.SetInputValue(1, acc) # 계좌번호
@@ -293,11 +294,10 @@ class HTS:
for i in range(size-1, -1, -1):
int_day = objStockChart.GetDataValue(0, i)
int_time = objStockChart.GetDataValue(1, i)
print (int_day, int_time)
if int_day < int_given_day:
continue
time = datetime.strptime(str(int_day)+" "+str(objStockChart.GetDataValue(1, i)).zfill(4)+"00", '%Y%m%d %H%M%S')
time = datetime.strptime(str(int_day)+" "+str(int_time).zfill(4)+"00", '%Y%m%d %H%M%S')
if time < start_time:
continue
@@ -462,8 +462,8 @@ class HTS:
return buy_line, sell_line
def simulate(self, stock_code, given_day):
timecheckList = pd.read_csv("timecheck.csv").values.tolist()
timecheck = {datetime.strptime(given_day + " " + str(second).zfill(6), '%Y%m%d %H%M%S'): False for second, check in timecheckList}
#timecheckList = pd.read_csv("timecheck.csv").values.tolist()
#timecheck = {datetime.strptime(given_day + " " + str(second).zfill(6), '%Y%m%d %H%M%S'): False for second, check in timecheckList}
result = {"check": set(),
"time": [],
@@ -476,9 +476,6 @@ class HTS:
# 데이터를 가지고 온다.
self.getCSV(given_day+".csv", given_day, result)
# 가져온 만큼 데이터를 누적해서 파일로 작성한다.
self.write(given_day, result)
# 분석을 통해서 볼린저밴드 상/하단을 계산한다.
data, upper, lower = self.analyze(result)
@@ -488,6 +485,9 @@ class HTS:
# 그래프를 그린다.
self.draw(given_day, data, upper, lower, buy_line, sell_line)
# 가져온 만큼 데이터를 누적해서 파일로 작성한다.
self.write(given_day, result)
return
def buyRealTime(self, stock_code, given_day):
@@ -506,15 +506,13 @@ class HTS:
while datetime.strptime(given_day + " 085900", '%Y%m%d %H%M%S') < datetime.now() < datetime.strptime(given_day + " 151500", '%Y%m%d %H%M%S'):
second = datetime.now().strftime('%Y%m%d %H%M%S')
print(second)
if second in timecheck and not timecheck[second]:
# 데이터를 가지고 온다.
self.getRealTime(stock_code, given_day, result)
# 가져온 만큼 데이터를 누적해서 파일로 작성한다.
self.write(given_day, result)
# 분석을 통해서 볼린저밴드 상/하단을 계산한다.
data, upper, lower = self.analyze(result)
@@ -532,9 +530,10 @@ class HTS:
self.orderToBuy(stock_code, count, price)
self.orderToSell(stock_code, count, price + 5)
timecheck[second] = True
# 가져온 만큼 데이터를 누적해서 파일로 작성한다.
self.write(given_day, result)
# self.draw(given_day, data, upper, lower, buy_line, sell_line)
timecheck[second] = True
time.sleep(0.5)