From b6ec663d630a8befc9e97e19bb14c2cadfb98ac1 Mon Sep 17 00:00:00 2001 From: dsyoon Date: Mon, 25 Oct 2021 13:01:33 +0900 Subject: [PATCH] try except deletion --- hts/HTS_252670.py | 87 ++++++++++++++++++----------------------------- 1 file changed, 34 insertions(+), 53 deletions(-) diff --git a/hts/HTS_252670.py b/hts/HTS_252670.py index d197575..b2269b3 100644 --- a/hts/HTS_252670.py +++ b/hts/HTS_252670.py @@ -569,11 +569,7 @@ 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')]: # 데이터를 가지고 온다. - try: - self.getRealTime(stock_code, GIVEN_DAY, result) - except: - time.sleep(0.9) - continue + self.getRealTime(stock_code, GIVEN_DAY, result) # 분석을 통해서 볼린저밴드 상/하단을 계산한다. data = self.buySellChecker.analyze(result) @@ -588,46 +584,34 @@ class HTS_252670: BUY_COUNT = int(BASE_COUNT * 1) # 매수를 주문한다. - try: - orderNum = self.requestOrder(OrderType.buy, stock_code, BUY_COUNT , bs_buy_price) - except: - time.sleep(0.9) - continue + orderNum = self.requestOrder(OrderType.buy, stock_code, BUY_COUNT , bs_buy_price) # 미체결 기록을 가져온다. - 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 + ORDER_LIST = self.requestOrderList() + # 매수 주문을 기록한다. + orderListToCancel = orderChecker.add(stock_code, OrderType.buy, orderNum, BUY_COUNT, bs_buy_price, ORDER_LIST) + # 두 시간 이전 미체결을 모두 취소한다. + self.cancelOrderList(orderListToCancel) # 로그 출력 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: - try: - # 미체결 기록을 가져온다. - ORDER_LIST = self.requestOrderList() - # 매도 주문을 기록을 가져온다. - orderListToCancel = orderChecker.remove(stock_code, OrderType.sell, ORDER_LIST) - # 매도 미체결을 모두 취소한다. - self.cancelOrderList(orderListToCancel) + # 미체결 기록을 가져온다. + 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)) - except: - time.sleep(0.9) - continue + # 로그 출력 + print("SELL", THIS_TIME.strftime('%Y%m%d %H%M%S'), selling_count, selling_price, len(orderListToCancel), len(ORDER_LIST)) # 로그 출력 print("TIMECHECK", THIS_TIME, final_price, data["low"][data_size-1], data["slow_k"][data_size-1], data["slow_d"][data_size-1]) @@ -637,24 +621,21 @@ class HTS_252670: #### # 손해 보지 않는 가격에 매도한다. #### - try: - # 주문 리스트를 가져온다. - 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) + # 주문 리스트를 가져온다. + orderList = self.requestOrderList() + # 15:10:00 이후라면 모든 미체결 취소한다. + self.cancelOrderList(orderList) - break - except: - time.sleep(0.9) - continue + # 매도 가격을 가져온다. + 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 time.sleep(0.9) THIS_TIME = datetime.now()