try except addition

This commit is contained in:
dsyoon
2021-10-25 12:55:14 +09:00
parent b23a9098db
commit d0290034a0

View File

@@ -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')]: 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) self.getRealTime(stock_code, GIVEN_DAY, result)
except:
time.sleep(0.9)
continue
# 분석을 통해서 볼린저밴드 상/하단을 계산한다. # 분석을 통해서 볼린저밴드 상/하단을 계산한다.
data = self.buySellChecker.analyze(result) data = self.buySellChecker.analyze(result)
@@ -584,18 +588,27 @@ class HTS_252670:
BUY_COUNT = int(BASE_COUNT * 1) BUY_COUNT = int(BASE_COUNT * 1)
# 매수를 주문한다. # 매수를 주문한다.
try:
orderNum = self.requestOrder(OrderType.buy, stock_code, BUY_COUNT , bs_buy_price) orderNum = self.requestOrder(OrderType.buy, stock_code, BUY_COUNT , bs_buy_price)
except:
time.sleep(0.9)
continue
# 미체결 기록을 가져온다. # 미체결 기록을 가져온다.
try:
ORDER_LIST = self.requestOrderList() 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) 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)) 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: if bs_sell_price > 0:
try:
# 미체결 기록을 가져온다. # 미체결 기록을 가져온다.
ORDER_LIST = self.requestOrderList() ORDER_LIST = self.requestOrderList()
# 매도 주문을 기록을 가져온다. # 매도 주문을 기록을 가져온다.
@@ -612,6 +625,9 @@ class HTS_252670:
# 로그 출력 # 로그 출력
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]) print("TIMECHECK", THIS_TIME, final_price, data["low"][data_size-1], data["slow_k"][data_size-1], data["slow_d"][data_size-1])
@@ -621,7 +637,7 @@ class HTS_252670:
#### ####
# 손해 보지 않는 가격에 매도한다. # 손해 보지 않는 가격에 매도한다.
#### ####
try:
# 주문 리스트를 가져온다. # 주문 리스트를 가져온다.
orderList = self.requestOrderList() orderList = self.requestOrderList()
# 15:10:00 이후라면 모든 미체결 취소한다. # 15:10:00 이후라면 모든 미체결 취소한다.
@@ -636,6 +652,9 @@ class HTS_252670:
print("SELL", THIS_TIME, selling_count, selling_price) print("SELL", THIS_TIME, selling_count, selling_price)
break break
except:
time.sleep(0.9)
continue
time.sleep(0.9) time.sleep(0.9)
THIS_TIME = datetime.now() THIS_TIME = datetime.now()
@@ -653,7 +672,7 @@ if __name__ == "__main__":
stock_codes = ["252670"] stock_codes = ["252670"]
given_day = datetime.today().strftime('%Y%m%d') given_day = datetime.today().strftime('%Y%m%d')
hts.writeStockData(stock_codes, "20211022") #hts.writeStockData(stock_codes, "20211022")
#hts.buyRealTime(stock_codes[0], given_day) hts.buyRealTime(stock_codes[0], given_day)
print ("done...") print ("done...")