diff --git a/hts/HTS_252670.py b/hts/HTS_252670.py index d2abf2d..d197575 100644 --- a/hts/HTS_252670.py +++ b/hts/HTS_252670.py @@ -569,7 +569,11 @@ class HTS_252670: 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) + try: + self.getRealTime(stock_code, GIVEN_DAY, result) + except: + time.sleep(0.9) + continue # 분석을 통해서 볼린저밴드 상/하단을 계산한다. data = self.buySellChecker.analyze(result) @@ -584,34 +588,46 @@ class HTS_252670: BUY_COUNT = int(BASE_COUNT * 1) # 매수를 주문한다. - orderNum = self.requestOrder(OrderType.buy, stock_code, BUY_COUNT , bs_buy_price) + try: + orderNum = self.requestOrder(OrderType.buy, stock_code, BUY_COUNT , bs_buy_price) + except: + time.sleep(0.9) + continue # 미체결 기록을 가져온다. - ORDER_LIST = self.requestOrderList() - # 매수 주문을 기록한다. - orderListToCancel = orderChecker.add(stock_code, OrderType.buy, orderNum, BUY_COUNT, bs_buy_price, ORDER_LIST) - # 두 시간 이전 미체결을 모두 취소한다. - self.cancelOrderList(orderListToCancel) + try: + ORDER_LIST = self.requestOrderList() + # 매수 주문을 기록한다. + orderListToCancel = orderChecker.add(stock_code, OrderType.buy, orderNum, BUY_COUNT, bs_buy_price, ORDER_LIST) + # 두 시간 이전 미체결을 모두 취소한다. + self.cancelOrderList(orderListToCancel) + except: + time.sleep(0.9) + continue # 로그 출력 print("BUY", THIS_TIME.strftime('%Y%m%d %H%M%S'), BUY_COUNT, bs_buy_price, len(orderListToCancel), len(ORDER_LIST)) if bs_sell_price > 0: - # 미체결 기록을 가져온다. - ORDER_LIST = self.requestOrderList() - # 매도 주문을 기록을 가져온다. - orderListToCancel = orderChecker.remove(stock_code, OrderType.sell, ORDER_LIST) - # 매도 미체결을 모두 취소한다. - self.cancelOrderList(orderListToCancel) + try: + # 미체결 기록을 가져온다. + ORDER_LIST = self.requestOrderList() + # 매도 주문을 기록을 가져온다. + orderListToCancel = orderChecker.remove(stock_code, OrderType.sell, ORDER_LIST) + # 매도 미체결을 모두 취소한다. + self.cancelOrderList(orderListToCancel) - # 매도 가격을 가져온다. - 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, selling_price) + # 매도 가격을 가져온다. + 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, selling_price) - # 로그 출력 - print("SELL", THIS_TIME.strftime('%Y%m%d %H%M%S'), selling_count, selling_price, len(orderListToCancel), len(ORDER_LIST)) + # 로그 출력 + print("SELL", THIS_TIME.strftime('%Y%m%d %H%M%S'), selling_count, selling_price, len(orderListToCancel), len(ORDER_LIST)) + except: + time.sleep(0.9) + continue # 로그 출력 print("TIMECHECK", THIS_TIME, final_price, data["low"][data_size-1], data["slow_k"][data_size-1], data["slow_d"][data_size-1]) @@ -621,21 +637,24 @@ class HTS_252670: #### # 손해 보지 않는 가격에 매도한다. #### + try: + # 주문 리스트를 가져온다. + orderList = self.requestOrderList() + # 15:10:00 이후라면 모든 미체결 취소한다. + self.cancelOrderList(orderList) - # 주문 리스트를 가져온다. - orderList = self.requestOrderList() - # 15:10:00 이후라면 모든 미체결 취소한다. - self.cancelOrderList(orderList) + # 매도 가격을 가져온다. + 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, selling_price) + # 로그 출력 + print("SELL", THIS_TIME, selling_count, selling_price) - # 매도 가격을 가져온다. - 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, selling_price) - # 로그 출력 - print("SELL", THIS_TIME, selling_count, selling_price) - - break + break + except: + time.sleep(0.9) + continue time.sleep(0.9) THIS_TIME = datetime.now() @@ -653,7 +672,7 @@ if __name__ == "__main__": stock_codes = ["252670"] given_day = datetime.today().strftime('%Y%m%d') - hts.writeStockData(stock_codes, "20211022") - #hts.buyRealTime(stock_codes[0], given_day) + #hts.writeStockData(stock_codes, "20211022") + hts.buyRealTime(stock_codes[0], given_day) print ("done...")