This commit is contained in:
dosangyoon
2022-09-05 20:46:02 +09:00
parent afdff4a43c
commit 8d13b54e92
3 changed files with 46 additions and 32 deletions

View File

@@ -31,23 +31,28 @@ class HTS_252670 (HTS):
self.labelChecker = LabelChecker(RESOURCE_PATH)
return
def getSellingPrice(self, log_time, stock_code, final_price, diff=None):
def getSellingPrice(self, log_time, stock_code, final_price, check=False):
# final_price와 diff를 받으면, 해당 가격으로 그냥 매도한다는 의미
# final_price와 diff가 None이면 장부가와 final 중 max로 팔겠다는 의미
# final_price가 0이고 diff가 None이면 장부가로 팔겠다는 의미임
sell_price = -1
jangoDic = self.requstJango()
if jangoDic and len(jangoDic.keys()) > 0:
for code in jangoDic:
if jangoDic[code]['매도가능'] > 0:
if diff is None:
if check:
if jangoDic[code]['장부가']*0.05 < jangoDic[code]['장부가'] - final_price:
sell_price = jangoDic[code]['장부가']
if code == "A" + stock_code:
orderNum = self.requestOrder(OrderType.sell, stock_code, jangoDic[code]['매도가능'], sell_price)
print("ORDER_SELL", stock_code, log_time.strftime('%Y%m%d %H%M%S'), jangoDic[code]['매도가능'], sell_price)
else:
max_price = max(jangoDic[code]['장부가'], final_price)
sell_price = (int(max_price) - int(max_price) % 5) + 5
else:
sell_price = (int(final_price) - int(final_price) % 5) + diff
if code == "A"+stock_code:
orderNum = self.requestOrder(OrderType.sell, stock_code, jangoDic[code]['매도가능'], sell_price)
print("ORDER_SELL", stock_code, log_time.strftime('%Y%m%d %H%M%S'), jangoDic[code]['매도가능'], sell_price)
if code == "A"+stock_code:
orderNum = self.requestOrder(OrderType.sell, stock_code, jangoDic[code]['매도가능'], sell_price)
print("ORDER_SELL", stock_code, log_time.strftime('%Y%m%d %H%M%S'), jangoDic[code]['매도가능'], sell_price)
return
def buyRealTime(self, today):
@@ -62,7 +67,6 @@ class HTS_252670 (HTS):
if datetime.strptime(today + " 090000", '%Y%m%d %H%M%S') < THIS_TIME < datetime.strptime(today + " 151500", '%Y%m%d %H%M%S'):
# 3시 까지만 매수를 시도한다.
"""
if THIS_TIME < datetime.strptime(today + " 145000", '%Y%m%d %H%M%S'):
if THIS_TIME.strftime('%S') in ("06", "16", "26", "36", "46", "56"):
# 데이터를 가지고 온다.
@@ -70,8 +74,7 @@ class HTS_252670 (HTS):
final_price = result["close"][len(result["close"])-1]
# 10초마다 체크하여 체결된 내역이 있으면 50원 높게 매도를 주문한다.
self.getSellingPrice(THIS_TIME, self.stock_code, final_price)
"""
self.getSellingPrice(THIS_TIME, self.stock_code, final_price, check=True)
if THIS_TIME.strftime('%S') == "03":
# 매분 3초마다 실행한다.
@@ -127,7 +130,7 @@ class HTS_252670 (HTS):
self.cancelOrderList(orderListToCancel)
# 매도한다.
self.getSellingPrice(THIS_TIME, self.stock_code, final_price, diff=5)
self.getSellingPrice(THIS_TIME, self.stock_code, final_price)
# 로그 출력
print("TIMECHECK: %s, price: %d, avg3: %.2f, avg5: %.2f, avg10: %.2f, slow_k: %.2f, open: %d, high: %d, low: %d" %
@@ -151,7 +154,7 @@ class HTS_252670 (HTS):
result = self.getRealTime(self.stock_code, today, LAST_DATA)
final_price = result["close"][len(result["close"]) - 1]
self.getSellingPrice(THIS_TIME, self.stock_code, final_price=5)
self.getSellingPrice(THIS_TIME, self.stock_code, final_price)
final_sell_check = True