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

@@ -30,7 +30,7 @@ class HTS_122630 (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이면 장부가로 팔겠다는 의미임
@@ -38,14 +38,18 @@ class HTS_122630 (HTS):
if jangoDic and len(jangoDic.keys()) > 0:
for code in jangoDic:
if jangoDic[code]['매도가능'] > 0:
if diff == None:
max_price = max(jangoDic[code]['장부가'], final_price)
sell_price = (int(max_price) - int(max_price) % 5) + 10
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:
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)
max_price = max(jangoDic[code]['장부가'], final_price)
sell_price = (int(max_price) - int(max_price) % 5) + 5
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):
@@ -57,10 +61,18 @@ class HTS_122630 (HTS):
while datetime.strptime(today + " 070000", '%Y%m%d %H%M%S') < THIS_TIME < datetime.strptime(today + " 153100", '%Y%m%d %H%M%S'):
"""
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 ("09", "19", "29", "39", "49", "59"):
# 데이터를 가지고 온다.
result = self.getRealTime(self.stock_code, today, LAST_DATA)
final_price = result["close"][len(result["close"])-1]
# 10초마다 체크하여 체결된 내역이 있으면 50원 높게 매도를 주문한다.
self.getSellingPrice(THIS_TIME, self.stock_code, final_price, check=True)
if THIS_TIME.strftime('%S') == "05":
# 매분 5초마다 실행한다.
@@ -116,7 +128,7 @@ class HTS_122630 (HTS):
self.cancelOrderList(orderListToCancel)
# 매도 한다.
self.getSellingPrice(THIS_TIME, self.stock_code, final_price, diff=5)
self.getSellingPrice(THIS_TIME, self.stock_code, final_price)
# 로그 출력
@@ -142,10 +154,9 @@ class HTS_122630 (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
"""
time.sleep(10)
THIS_TIME = datetime.now()

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

View File

@@ -185,15 +185,15 @@ if __name__ == "__main__":
# to check bying
stock_codes = {
"252670": ['20220801', '20220802', '20220803', '20220804', '20220805',
'20220808', '20220809', '20220810', '20220811', '20220812',
'20220816', '20220817', '20220818', '20220819',
'20220822', '20220823', '20220824', '20220825', '20220826', '20220829'],
"122630": ['20220801', '20220802', '20220803', '20220804', '20220805',
'20220808', '20220809', '20220810', '20220811', '20220812',
'20220816', '20220817', '20220818', '20220819',
'20220822', '20220823', '20220824', '20220825', '20220826', '20220829']
"252670": ['20220905']
}
"""
"122630": ['20220801', '20220802', '20220803', '20220804', '20220805',
'20220808', '20220809', '20220810', '20220811', '20220812',
'20220816', '20220817', '20220818', '20220819',
'20220822', '20220823', '20220824', '20220825', '20220826', '20220829']
"""
method = "rule" # "rule", "ml", "answer"
for stock_code in stock_codes: