This commit is contained in:
dosangyoon
2021-10-16 19:40:55 +09:00
parent b464987eba
commit 476e828226
3 changed files with 65 additions and 43 deletions

View File

@@ -545,12 +545,12 @@ class HTS:
return 0, 0
def buyRealTime(self, stock_code, given_day):
def buyRealTime(self, stock_code, GIVEN_DAY):
orderChecker = OrderChecker()
BASE_COUNT = 100
timecheckList = pd.read_csv("timecheck.csv").values.tolist()
timecheck = {given_day + " " + str(second).zfill(6):False for second, check in timecheckList}
timecheck = {GIVEN_DAY + " " + str(second).zfill(6):False for second, check in timecheckList}
result = {"check": set(),
"time": [],
@@ -562,15 +562,14 @@ class HTS:
final_price = 0
print ("START...")
while datetime.strptime(given_day + " 070000", '%Y%m%d %H%M%S') < datetime.now() < datetime.strptime(given_day + " 15200", '%Y%m%d %H%M%S'):
THIS_TIME = datetime.now()
while datetime.strptime(GIVEN_DAY + " 070000", '%Y%m%d %H%M%S') < THIS_TIME < datetime.strptime(GIVEN_DAY + " 15200", '%Y%m%d %H%M%S'):
second = datetime.now().strftime('%Y%m%d %H%M%S')
if datetime.strptime(given_day + " 090100", '%Y%m%d %H%M%S') < datetime.now() < datetime.strptime(given_day + " 151000", '%Y%m%d %H%M%S'):
if second in timecheck and not timecheck[second]:
if datetime.strptime(GIVEN_DAY + " 090100", '%Y%m%d %H%M%S') < THIS_TIME < datetime.strptime(GIVEN_DAY + " 151000", '%Y%m%d %H%M%S'):
if THIS_TIME.strftime('%Y%m%d %H%M%S') in timecheck and not timecheck[THIS_TIME.strftime('%Y%m%d %H%M%S')]:
# 데이터를 가지고 온다.
self.getRealTime(stock_code, given_day, result)
self.getRealTime(stock_code, GIVEN_DAY, result)
# 분석을 통해서 볼린저밴드 상/하단을 계산한다.
data = self.buySellChecker.analyze(result)
@@ -592,7 +591,7 @@ class HTS:
# 두 시간 이전 미체결을 취소한다.
self.cancelOrderList(orderListToCancel)
# 로그 출력
print("BUY", second, BUY_COUNT, bs_buy_price)
print("BUY", THIS_TIME, BUY_COUNT, bs_buy_price)
if bs_sell_price > 0:
# 매도 가격을 가져온다.
@@ -607,13 +606,13 @@ class HTS:
# 두 시간 이전 미체결을 취소한다.
self.cancelOrderList(orderListToCancel)
# 로그 출력
print("SELL", second, selling_count, selling_price)
print("SELL", THIS_TIME, selling_count, selling_price)
# 로그 출력
print("TIMECHECK", second, final_price, data["Low"][data_size-1], data["slow_k"][data_size-1], data["slow_d"][data_size-1])
timecheck[second] = True
print("TIMECHECK", THIS_TIME, final_price, data["Low"][data_size-1], data["slow_k"][data_size-1], data["slow_d"][data_size-1])
timecheck[THIS_TIME] = True
if datetime.strptime(given_day + " 151000", '%Y%m%d %H%M%S') < datetime.now():
if datetime.strptime(GIVEN_DAY + " 151000", '%Y%m%d %H%M%S') < THIS_TIME:
# 주문 리스트를 가져온다.
orderList = self.requestOrderList()
# 15:10:00 이후라면 모든 미체결 취소한다.
@@ -624,10 +623,11 @@ class HTS:
if selling_count != 0 and selling_price !=0:
orderNum = self.requestOrder(OrderType.sell, stock_code, selling_count, selling_price)
# 로그 출력
print("SELL", second, selling_count, selling_price)
print("SELL", THIS_TIME, selling_count, selling_price)
break
time.sleep(0.9)
THIS_TIME = datetime.now()
return