This commit is contained in:
dsyoon
2023-02-12 00:28:13 +09:00
parent 4010d1cc78
commit 426ca43ff7
5 changed files with 81 additions and 22 deletions

View File

@@ -54,15 +54,24 @@ class HTS_Stocks (HTS):
self.conn_stock.close()
return
def sellStocks(self):
def sellStocks(self, stock_code=None, bs_sell_price=None):
jangoDic = self.requstJango()
if jangoDic and len(jangoDic.keys()) > 0:
for code in jangoDic:
if jangoDic[code]['매도가능'] > 0:
if 2 < jangoDic[code]['평가손익']:
currentStock = self.currentStock(code[1:])
self.requestOrder(OrderType.sell, code[1:], jangoDic[code]['매도가능'], currentStock['close'])
self.slackBot.post_to_slack(code, jangoDic[code]['종목명'], "SELL", currentStock['close'], jangoDic[code]['매도가능'])
if stock_code is not None:
if code == "A"+stock_code and bs_sell_price is not None:
if jangoDic[code]['매도가능'] > 0:
if 2 < jangoDic[code]['평가손익']:
self.requestOrder(OrderType.sell, code[1:], jangoDic[code]['매도가능'], bs_sell_price)
self.slackBot.post_to_slack(code, jangoDic[code]['종목명'], "SELL", bs_sell_price, jangoDic[code]['매도가능'])
else:
continue
else:
if jangoDic[code]['매도가능'] > 0:
if 2 < jangoDic[code]['평가손익']:
currentStock = self.currentStock(code[1:])
self.requestOrder(OrderType.sell, code[1:], jangoDic[code]['매도가능'], currentStock['close'])
self.slackBot.post_to_slack(code, jangoDic[code]['종목명'], "SELL", currentStock['close'], jangoDic[code]['매도가능'])
return
def getSellingPrice(self, log_time, stock_code, final_price, without_loss=False):
@@ -119,7 +128,7 @@ class HTS_Stocks (HTS):
if datetime.strptime(today + " 090000", '%Y%m%d %H%M%S') < THIS_TIME < datetime.strptime(today + " 151500", '%Y%m%d %H%M%S'):
# 매도를 체크한다.
self.sellStocks()
###self.sellStocks()
for idx, item in enumerate(all_stocks):
if THIS_TIME < datetime.strptime(today + " 090000", '%Y%m%d %H%M%S') or datetime.strptime(today + " 151500", '%Y%m%d %H%M%S') < THIS_TIME:
@@ -179,6 +188,17 @@ class HTS_Stocks (HTS):
# 로그 출력
print("BUY", THIS_TIME.strftime('%Y%m%d %H%M%S'), orderNum, stock_code, stock_name, bs_buy_price, buy_count)
# 다음 조건이면 매도한다.
if len(data) > 10 and max(bsLine['sell'][len(bsLine['sell']) - 1:]) > 1000:
bs_sell_price = bsLine['sell'][len(bsLine['sell']) - 1]
self.sellStocks(stock_code, bs_sell_price)
# slackbot에 메시지를 보냄
self.slackBot.post_to_slack(stock_code, stock_name, "SELL", bsLine['sell'][len(bsLine['sell']) - 1], 'ALL')
# 로그 출력
print("SELL", THIS_TIME.strftime('%Y%m%d %H%M%S'), stock_code, stock_name, bs_sell_price)
"""
elif datetime.strptime(today + " 151530", '%Y%m%d %H%M%S') < THIS_TIME < datetime.strptime(today + " 151600", '%Y%m%d %H%M%S'):
# 3시 15분 30초부터 3시 16분 사이는 잔량을 매도한다.
@@ -199,7 +219,7 @@ class HTS_Stocks (HTS):
orderNum, sell_time, jango, sell_price = self.getSellingPrice(THIS_TIME, stock_code, final_price=-1, without_loss=True)
# 로그 출력
print("SELL", sell_time, stock_code, stock_name, -1, str(orderNum), jango, sell_price)
"""
time.sleep(10)
THIS_TIME = datetime.now()