init
This commit is contained in:
51
HTS_etf.py
51
HTS_etf.py
@@ -132,7 +132,19 @@ class HTS_etf (HTS):
|
|||||||
return count
|
return count
|
||||||
|
|
||||||
def getSlowK(self, stock_code):
|
def getSlowK(self, stock_code):
|
||||||
slow_k_week, p_slow_k_week, slow_k_month, p_slow_k_month = -1, -1, -1, -1
|
slow_k, p_slow_k, slow_k_week, p_slow_k_week, slow_k_month, p_slow_k_month = -1, -1, -1, -1, -1, -1
|
||||||
|
|
||||||
|
self.cursor_stock.execute('select stochastic_slow_k, max(ymd) from stock_analysis where code=? group by 1 order by ymd desc',(stock_code,))
|
||||||
|
items = self.cursor_stock.fetchall()
|
||||||
|
if items is not None and len(items) > 1:
|
||||||
|
for i, item in enumerate(items):
|
||||||
|
if i == 0:
|
||||||
|
slow_k = item[0]
|
||||||
|
elif i == 1:
|
||||||
|
p_slow_k = item[0]
|
||||||
|
else:
|
||||||
|
break
|
||||||
|
|
||||||
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, ))
|
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.fetchall()
|
items = self.cursor_stock.fetchall()
|
||||||
if items is not None and len(items) > 1:
|
if items is not None and len(items) > 1:
|
||||||
@@ -143,31 +155,38 @@ class HTS_etf (HTS):
|
|||||||
p_slow_k_week = item[0]
|
p_slow_k_week = item[0]
|
||||||
else:
|
else:
|
||||||
break
|
break
|
||||||
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.fetchall()
|
|
||||||
if items is not None and len(items) > 1:
|
|
||||||
for i, item in enumerate(items):
|
|
||||||
if i == 0:
|
|
||||||
slow_k_month = item[0]
|
|
||||||
elif i == 1:
|
|
||||||
p_slow_k_month = item[0]
|
|
||||||
else:
|
|
||||||
break
|
|
||||||
|
|
||||||
|
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.fetchall()
|
||||||
|
if items is not None and len(items) > 1:
|
||||||
|
for i, item in enumerate(items):
|
||||||
|
if i == 0:
|
||||||
|
slow_k_month = item[0]
|
||||||
|
elif i == 1:
|
||||||
|
p_slow_k_month = item[0]
|
||||||
|
else:
|
||||||
|
break
|
||||||
|
|
||||||
|
if slow_k is None or p_slow_k is None:
|
||||||
|
slow_k , p_slow_k = -1, -1
|
||||||
if slow_k_week is None or p_slow_k_week is None:
|
if slow_k_week is None or p_slow_k_week is None:
|
||||||
slow_k_week, p_slow_k_week = -1, -1
|
slow_k_week, p_slow_k_week = -1, -1
|
||||||
if slow_k_month is None or p_slow_k_month is None:
|
if slow_k_month is None or p_slow_k_month is None:
|
||||||
slow_k_month, p_slow_k_month = -1, -1
|
slow_k_month, p_slow_k_month = -1, -1
|
||||||
|
|
||||||
return slow_k_week, p_slow_k_week, slow_k_month, p_slow_k_month
|
return slow_k, p_slow_k, slow_k_week, p_slow_k_week, slow_k_month, p_slow_k_month
|
||||||
|
|
||||||
def buyRealTime(self, today, stocks, analyzed_day=1000):
|
def buyRealTime(self, today, stocks, analyzed_day=1000):
|
||||||
|
|
||||||
print ("START...")
|
print ("START...")
|
||||||
THIS_TIME = datetime.now()
|
THIS_TIME = datetime.now()
|
||||||
final_sell_check = False
|
|
||||||
|
slow_k_kospi, p_slow_k_kospi, slow_k_week_kospi, p_slow_k_week_kospi, slow_k_month_kospi, p_slow_k_month_kospi = self.getSlowK("^KS11")
|
||||||
|
if (50 < slow_k_kospi or 50 < p_slow_k_kospi or (slow_k_kospi < 50 and p_slow_k_kospi < 50 and slow_k_kospi < p_slow_k_kospi)):
|
||||||
|
return
|
||||||
|
if ((0 < slow_k_week_kospi < 50 and 0 < slow_k_month_kospi < 50) and
|
||||||
|
not ((20 < slow_k_week_kospi and slow_k_week_kospi < p_slow_k_week_kospi) or (20 < slow_k_month_kospi and slow_k_month_kospi < p_slow_k_month_kospi))):
|
||||||
|
return
|
||||||
|
|
||||||
LAST_DATA = {}
|
LAST_DATA = {}
|
||||||
for stock in stocks:
|
for stock in stocks:
|
||||||
@@ -218,7 +237,7 @@ class HTS_etf (HTS):
|
|||||||
bs_sell_price = bsLine['sell'][0]
|
bs_sell_price = bsLine['sell'][0]
|
||||||
|
|
||||||
|
|
||||||
slow_k_week, p_slow_k_week, slow_k_month, p_slow_k_month = self.getSlowK(stock['stock_code'])
|
slow_k, p_slow_k, 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
|
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))):
|
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))):
|
||||||
|
|
||||||
|
|||||||
@@ -121,7 +121,19 @@ class HTS_Stocks (HTS):
|
|||||||
return all_stocks, valid_company
|
return all_stocks, valid_company
|
||||||
|
|
||||||
def getSlowK(self, stock_code):
|
def getSlowK(self, stock_code):
|
||||||
slow_k_week, p_slow_k_week, slow_k_month, p_slow_k_month = -1, -1, -1, -1
|
slow_k, p_slow_k, slow_k_week, p_slow_k_week, slow_k_month, p_slow_k_month = -1, -1, -1, -1, -1, -1
|
||||||
|
|
||||||
|
self.cursor_stock.execute('select stochastic_slow_k, max(ymd) from stock_analysis where code=? group by 1 order by ymd desc', (stock_code,))
|
||||||
|
items = self.cursor_stock.fetchall()
|
||||||
|
if items is not None and len(items) > 1:
|
||||||
|
for i, item in enumerate(items):
|
||||||
|
if i == 0:
|
||||||
|
slow_k = item[0]
|
||||||
|
elif i == 1:
|
||||||
|
p_slow_k = item[0]
|
||||||
|
else:
|
||||||
|
break
|
||||||
|
|
||||||
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, ))
|
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.fetchall()
|
items = self.cursor_stock.fetchall()
|
||||||
if items is not None and len(items)>1:
|
if items is not None and len(items)>1:
|
||||||
@@ -132,23 +144,26 @@ class HTS_Stocks (HTS):
|
|||||||
p_slow_k_week = item[0]
|
p_slow_k_week = item[0]
|
||||||
else:
|
else:
|
||||||
break
|
break
|
||||||
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.fetchall()
|
|
||||||
if items is not None and len(items)>1:
|
|
||||||
for i, item in enumerate(items):
|
|
||||||
if i == 0:
|
|
||||||
slow_k_month = item[0]
|
|
||||||
elif i == 1:
|
|
||||||
p_slow_k_month = item[0]
|
|
||||||
else:
|
|
||||||
break
|
|
||||||
|
|
||||||
if slow_k_week is None or p_slow_k_week is None:
|
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, ))
|
||||||
slow_k_week, p_slow_k_week = -1, -1
|
items = self.cursor_stock.fetchall()
|
||||||
if slow_k_month is None or p_slow_k_month is None:
|
if items is not None and len(items)>1:
|
||||||
slow_k_month, p_slow_k_month = -1, -1
|
for i, item in enumerate(items):
|
||||||
|
if i == 0:
|
||||||
|
slow_k_month = item[0]
|
||||||
|
elif i == 1:
|
||||||
|
p_slow_k_month = item[0]
|
||||||
|
else:
|
||||||
|
break
|
||||||
|
|
||||||
return slow_k_week, p_slow_k_week, slow_k_month, p_slow_k_month
|
if slow_k is None or p_slow_k is None:
|
||||||
|
slow_k, p_slow_k = -1, -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, p_slow_k, slow_k_week, p_slow_k_week, slow_k_month, p_slow_k_month
|
||||||
|
|
||||||
def getMaxPrice(self, code, valid_company):
|
def getMaxPrice(self, code, valid_company):
|
||||||
max_price = 100000
|
max_price = 100000
|
||||||
@@ -170,6 +185,13 @@ class HTS_Stocks (HTS):
|
|||||||
print ("START...")
|
print ("START...")
|
||||||
THIS_TIME = datetime.now()
|
THIS_TIME = datetime.now()
|
||||||
|
|
||||||
|
slow_k_kospi, p_slow_k_kospi, slow_k_week_kospi, p_slow_k_week_kospi, slow_k_month_kospi, p_slow_k_month_kospi = self.getSlowK("^KS11")
|
||||||
|
if (50 < slow_k_kospi or 50 < p_slow_k_kospi or (slow_k_kospi < 50 and p_slow_k_kospi < 50 and slow_k_kospi < p_slow_k_kospi)):
|
||||||
|
return
|
||||||
|
if ((0 < slow_k_week_kospi < 50 and 0 < slow_k_month_kospi < 50) and
|
||||||
|
not ((20 < slow_k_week_kospi and slow_k_week_kospi < p_slow_k_week_kospi) or (20 < slow_k_month_kospi and slow_k_month_kospi < p_slow_k_month_kospi))):
|
||||||
|
return
|
||||||
|
|
||||||
all_stocks, valid_company = self.getCompanyInfo()
|
all_stocks, valid_company = self.getCompanyInfo()
|
||||||
|
|
||||||
while datetime.strptime(today + " 070000", '%Y%m%d %H%M%S') < THIS_TIME < datetime.strptime(today + " 153100", '%Y%m%d %H%M%S'):
|
while datetime.strptime(today + " 070000", '%Y%m%d %H%M%S') < THIS_TIME < datetime.strptime(today + " 153100", '%Y%m%d %H%M%S'):
|
||||||
@@ -208,9 +230,9 @@ class HTS_Stocks (HTS):
|
|||||||
data.drop(data.index[:len(data) - self.analyzed_day], inplace=True)
|
data.drop(data.index[:len(data) - self.analyzed_day], inplace=True)
|
||||||
bsLine, data = self.buySellChecker.checkTransactionWithEnvelope(data, stock_code, self.analyzed_day, isRealTime=False)
|
bsLine, data = self.buySellChecker.checkTransactionWithEnvelope(data, stock_code, self.analyzed_day, isRealTime=False)
|
||||||
|
|
||||||
slow_k_week, p_slow_k_week, slow_k_month, p_slow_k_month = self.getSlowK(stock_code)
|
slow_k, p_slow_k, 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
|
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))):
|
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))):
|
||||||
|
|
||||||
# 미체결 기록을 가져와서 10분 이상 된 매수 주문을 취소 한다.
|
# 미체결 기록을 가져와서 10분 이상 된 매수 주문을 취소 한다.
|
||||||
ORDER_LIST = self.requestOrderList()
|
ORDER_LIST = self.requestOrderList()
|
||||||
|
|||||||
Reference in New Issue
Block a user