init
This commit is contained in:
59
HTS_etf.py
59
HTS_etf.py
@@ -128,20 +128,22 @@ class HTS_etf (HTS):
|
||||
return count
|
||||
|
||||
def getSlowK(self, stock_code):
|
||||
slow_k_week, slow_k_month = -1, -1
|
||||
slow_k_week, p_slow_k_week, slow_k_month, p_slow_k_month = -1, -1, -1, -1
|
||||
self.cursor_stock.execute('select stochastic_slow_k, max(ymd) from stock_analysis_weekly where code=? group by 1 order by ymd desc', (stock_code, ))
|
||||
items = self.cursor_stock.fetchone()
|
||||
if items is not None and len(items)>0:
|
||||
slow_k_week = items[0]
|
||||
if items is not None and len(items)>1:
|
||||
slow_k_week, p_slow_k_week = items[0], items[1]
|
||||
self.cursor_stock.execute('select stochastic_slow_k, max(ymd) from stock_analysis_monthly where code=? group by 1 order by ymd desc', (stock_code, ))
|
||||
items = self.cursor_stock.fetchone()
|
||||
if items is not None and len(items)>0:
|
||||
slow_k_month = items[0]
|
||||
if items is not None and len(items)>1:
|
||||
slow_k_month, p_slow_k_month = items[0], items[1]
|
||||
|
||||
if slow_k_week is None: slow_k_week = -1
|
||||
if slow_k_month is None: slow_k_month = -1
|
||||
if slow_k_week is None or p_slow_k_week is None:
|
||||
slow_k_week, p_slow_k_week = -1, -1
|
||||
if slow_k_month is None or p_slow_k_month is None:
|
||||
slow_k_month, p_slow_k_month = -1, -1
|
||||
|
||||
return slow_k_week, slow_k_month
|
||||
return slow_k_week, p_slow_k_week, slow_k_month, p_slow_k_month
|
||||
|
||||
def buyRealTime(self, today, stocks, analyzed_day=1000):
|
||||
|
||||
@@ -166,10 +168,6 @@ class HTS_etf (HTS):
|
||||
|
||||
print("%5d: %8s, %-50s"%(idx, stock['stock_code'], stock['stock_name']))
|
||||
|
||||
slow_k_week, slow_k_month = self.getSlowK(stock['stock_code'])
|
||||
if slow_k_week < 0 or 50 < slow_k_week or slow_k_month < 0 or 50 < slow_k_month:
|
||||
continue
|
||||
|
||||
try:
|
||||
# 데이터를 가지고 온다.
|
||||
result = self.getRealTime(stock['stock_code'], today, LAST_DATA[stock['stock_code']])
|
||||
@@ -199,28 +197,33 @@ class HTS_etf (HTS):
|
||||
bs_buy_weight = bsLine['buy_weight'][0]
|
||||
bs_sell_price = bsLine['sell'][0]
|
||||
|
||||
# 미체결 기록을 가져와서 10분 이상 된 매수 주문을 취소 한다.
|
||||
ORDER_LIST = self.requestOrderList()
|
||||
orderListToCancel = self.orderChecker.cancel(today, "A" + stock['stock_code'], ORDER_LIST, mins=10)
|
||||
if len(orderListToCancel) > 0:
|
||||
self.cancelOrderList(orderListToCancel)
|
||||
|
||||
if bs_buy_price > 1000:
|
||||
slow_k_week, p_slow_k_week, slow_k_month, p_slow_k_month = self.getSlowK(stock['stock_code'])
|
||||
if ((0 < slow_k_week < 50 and 0 < slow_k_month < 50) and
|
||||
not ((20 < slow_k_week and slow_k_week < p_slow_k_week) or (20 < slow_k_month and slow_k_month < p_slow_k_month))):
|
||||
|
||||
if not self.orderChecker.exist(today, "A" + stock['stock_code'], hours=9):
|
||||
buy_count = self.getCount(stock['stock_code'], bs_buy_price, data)
|
||||
# 미체결 기록을 가져와서 10분 이상 된 매수 주문을 취소 한다.
|
||||
ORDER_LIST = self.requestOrderList()
|
||||
orderListToCancel = self.orderChecker.cancel(today, "A" + stock['stock_code'], ORDER_LIST, mins=10)
|
||||
if len(orderListToCancel) > 0:
|
||||
self.cancelOrderList(orderListToCancel)
|
||||
|
||||
if buy_count > 0:
|
||||
if bs_buy_price > 1000:
|
||||
|
||||
# 매수를 주문한다.
|
||||
orderNum = self.requestOrder(OrderType.buy, stock['stock_code'], buy_count , bs_buy_price)
|
||||
self.orderChecker.buy(today, "A" + stock['stock_code'], buy_count, bs_buy_price, orderNum)
|
||||
if not self.orderChecker.exist(today, "A" + stock['stock_code'], hours=9):
|
||||
buy_count = self.getCount(stock['stock_code'], bs_buy_price, data)
|
||||
|
||||
# slackbot에 메시지를 보냄
|
||||
self.slackBot.post_to_slack(stock['stock_code'], stock['stock_name'], "BUY", bsLine['buy'][len(bsLine['buy']) - 1], buy_count)
|
||||
if buy_count > 0:
|
||||
|
||||
# 로그 출력
|
||||
print("BUY", THIS_TIME.strftime('%Y%m%d %H%M%S'), orderNum, stock['stock_code'], stock['stock_name'], bs_buy_price, buy_count)
|
||||
# 매수를 주문한다.
|
||||
orderNum = self.requestOrder(OrderType.buy, stock['stock_code'], buy_count , bs_buy_price)
|
||||
self.orderChecker.buy(today, "A" + stock['stock_code'], buy_count, bs_buy_price, orderNum)
|
||||
|
||||
# slackbot에 메시지를 보냄
|
||||
self.slackBot.post_to_slack(stock['stock_code'], stock['stock_name'], "BUY", bsLine['buy'][len(bsLine['buy']) - 1], buy_count)
|
||||
|
||||
# 로그 출력
|
||||
print("BUY", THIS_TIME.strftime('%Y%m%d %H%M%S'), orderNum, stock['stock_code'], stock['stock_name'], bs_buy_price, buy_count)
|
||||
|
||||
if bs_sell_price > 1000:
|
||||
self.sellStocks(stock['stock_code'], bs_sell_price)
|
||||
|
||||
Reference in New Issue
Block a user