diff --git a/hts/HTS_122630.py b/hts/HTS_122630.py index 4b943f9..1534625 100644 --- a/hts/HTS_122630.py +++ b/hts/HTS_122630.py @@ -547,10 +547,10 @@ class HTS_122630: def buyRealTime(self, stock_code, GIVEN_DAY): orderChecker = OrderChecker(stock_code) - BASE_COUNT = 100 + BASE_COUNT = 150 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": [], @@ -561,12 +561,15 @@ class HTS_122630: "vol": []} final_price = 0 - print ("START...") + print("START...") 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'): + 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'): - if datetime.strptime(GIVEN_DAY + " 090100", '%Y%m%d %H%M%S') < THIS_TIME < datetime.strptime(GIVEN_DAY + " 151500", '%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')]: + if datetime.strptime(GIVEN_DAY + " 090100", '%Y%m%d %H%M%S') < THIS_TIME < datetime.strptime( + GIVEN_DAY + " 151500", '%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) @@ -576,19 +579,21 @@ class HTS_122630: # 사야 할 시점/가격과 팔아야 할 시점/가격을 체크한다. bs_buy_price, bs_weight, bs_sell_price = self.checkTransaction(data) data_size = len(data["Close"]) - final_price = data["Close"][data_size-1] + final_price = data["Close"][data_size - 1] if bs_buy_price > 0: # 기본 100 주에 가중치를 추가해서 매수한다. - BUY_COUNT = int(BASE_COUNT * bs_weight) + # BUY_COUNT = int(BASE_COUNT * bs_weight) + BUY_COUNT = int(BASE_COUNT * 1) # 매수를 주문한다. - orderNum = self.requestOrder(OrderType.buy, stock_code, BUY_COUNT , bs_buy_price) + orderNum = self.requestOrder(OrderType.buy, stock_code, BUY_COUNT, bs_buy_price) # 미체결 기록을 가져온다. ORDER_LIST = self.requestOrderList() # 매수 주문을 기록한다. - orderListToCancel = orderChecker.add(stock_code, OrderType.buy, orderNum, BUY_COUNT, bs_buy_price, ORDER_LIST) + orderListToCancel = orderChecker.add(stock_code, OrderType.buy, orderNum, BUY_COUNT, + bs_buy_price, ORDER_LIST) # 두 시간 이전 미체결을 모두 취소한다. self.cancelOrderList(orderListToCancel) # 로그 출력 @@ -613,31 +618,25 @@ class HTS_122630: print("SELL", THIS_TIME, selling_count, selling_price) # 로그 출력 - print("TIMECHECK", THIS_TIME, final_price, data["Low"][data_size-1], data["slow_k"][data_size-1], data["slow_d"][data_size-1]) + 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 + " 151500", '%Y%m%d %H%M%S') < THIS_TIME: + if datetime.strptime(GIVEN_DAY + " 151530", '%Y%m%d %H%M%S') < THIS_TIME: #### - # 종가에 그냥 매도한다. + # 손해 보지 않는 가격에 매도한다. #### + # 주문 리스트를 가져온다. orderList = self.requestOrderList() - # 15:15:00 이후라면 모든 미체결 취소한다. + # 15:10:00 이후라면 모든 미체결 취소한다. self.cancelOrderList(orderList) - # 데이터를 가지고 온다. - self.getRealTime(stock_code, GIVEN_DAY, result) - - # 분석을 통해서 볼린저밴드 상/하단을 계산한다. - data = self.buySellChecker.analyze(result) - data_size = len(data["Close"]) - final_price = data["Close"][data_size - 1] - # 매도 가격을 가져온다. selling_count, selling_price = self.getSellingPrice(final_price) # 분석되 가격으로 매도 요청한다. if selling_count != 0 and selling_price != 0: - orderNum = self.requestOrder(OrderType.sell, stock_code, selling_count, final_price) + orderNum = self.requestOrder(OrderType.sell, stock_code, selling_count, selling_price) # 로그 출력 print("SELL", THIS_TIME, selling_count, selling_price)