init
This commit is contained in:
33
HTS_etf.py
33
HTS_etf.py
@@ -1,5 +1,6 @@
|
|||||||
import time
|
import time
|
||||||
import os
|
import os
|
||||||
|
import sqlite3
|
||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
|
|
||||||
from hts.HTS import HTS
|
from hts.HTS import HTS
|
||||||
@@ -35,6 +36,19 @@ class HTS_etf (HTS):
|
|||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
|
def connect2StockDB(self):
|
||||||
|
|
||||||
|
self.conn_stock = sqlite3.connect(os.path.join(self.RESOURCE_PATH, "stock.db"))
|
||||||
|
self.cursor_stock = self.conn_stock.cursor()
|
||||||
|
|
||||||
|
return
|
||||||
|
|
||||||
|
def disconnectStockDB(self):
|
||||||
|
|
||||||
|
self.cursor_stock.close()
|
||||||
|
self.conn_stock.close()
|
||||||
|
return
|
||||||
|
|
||||||
def sellStocks(self, stock_code=None, bs_sell_price=None):
|
def sellStocks(self, stock_code=None, bs_sell_price=None):
|
||||||
jangoDic = self.requstJango()
|
jangoDic = self.requstJango()
|
||||||
if jangoDic and len(jangoDic.keys()) > 0:
|
if jangoDic and len(jangoDic.keys()) > 0:
|
||||||
@@ -113,6 +127,19 @@ class HTS_etf (HTS):
|
|||||||
count = int(MAX_BUY_PRICE / price)
|
count = int(MAX_BUY_PRICE / price)
|
||||||
return count
|
return count
|
||||||
|
|
||||||
|
def getSlowK(self, stock_code):
|
||||||
|
slow_k_week, slow_k_month = -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 len(items)>0:
|
||||||
|
slow_k_week = items[0]
|
||||||
|
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 len(items)>0:
|
||||||
|
slow_k_month = items[0]
|
||||||
|
|
||||||
|
return slow_k_week, slow_k_month
|
||||||
|
|
||||||
def buyRealTime(self, today, stocks, analyzed_day=1000):
|
def buyRealTime(self, today, stocks, analyzed_day=1000):
|
||||||
|
|
||||||
print ("START...")
|
print ("START...")
|
||||||
@@ -134,6 +161,10 @@ class HTS_etf (HTS):
|
|||||||
|
|
||||||
time.sleep(0.1)
|
time.sleep(0.1)
|
||||||
|
|
||||||
|
slow_k_week, slow_k_month = self.getSlowK(stock['stock_code'])
|
||||||
|
if slow_k_week < 0 or 20 < slow_k_week or slow_k_month < 0 or 20 < slow_k_month:
|
||||||
|
continue
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# 데이터를 가지고 온다.
|
# 데이터를 가지고 온다.
|
||||||
result = self.getRealTime(stock['stock_code'], today, LAST_DATA[stock['stock_code']])
|
result = self.getRealTime(stock['stock_code'], today, LAST_DATA[stock['stock_code']])
|
||||||
@@ -297,6 +328,7 @@ if __name__ == "__main__":
|
|||||||
|
|
||||||
hts = HTS_etf(RESOURCE_PATH)
|
hts = HTS_etf(RESOURCE_PATH)
|
||||||
hts.connect2DB("hts.db")
|
hts.connect2DB("hts.db")
|
||||||
|
hts.connect2StockDB()
|
||||||
|
|
||||||
today_str = today.strftime('%Y%m%d')
|
today_str = today.strftime('%Y%m%d')
|
||||||
hts.buyRealTime(today_str, stocks, analyzed_day=1000)
|
hts.buyRealTime(today_str, stocks, analyzed_day=1000)
|
||||||
@@ -304,5 +336,6 @@ if __name__ == "__main__":
|
|||||||
db_filename = os.path.join(RESOURCE_PATH, "hts.db")
|
db_filename = os.path.join(RESOURCE_PATH, "hts.db")
|
||||||
hts.insertStockData(stocks, today)
|
hts.insertStockData(stocks, today)
|
||||||
|
|
||||||
|
hts.disconnectStockDB()
|
||||||
hts.disconnect()
|
hts.disconnect()
|
||||||
print ("done...")
|
print ("done...")
|
||||||
|
|||||||
@@ -46,6 +46,7 @@ class HTS_Stocks (HTS):
|
|||||||
|
|
||||||
self.conn_stock = sqlite3.connect(os.path.join(self.RESOURCE_PATH, "stock.db"))
|
self.conn_stock = sqlite3.connect(os.path.join(self.RESOURCE_PATH, "stock.db"))
|
||||||
self.cursor_stock = self.conn_stock.cursor()
|
self.cursor_stock = self.conn_stock.cursor()
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
def disconnectStockDB(self):
|
def disconnectStockDB(self):
|
||||||
@@ -115,8 +116,22 @@ class HTS_Stocks (HTS):
|
|||||||
|
|
||||||
return all_stocks, valid_company
|
return all_stocks, valid_company
|
||||||
|
|
||||||
|
def getSlowK(self, stock_code):
|
||||||
|
slow_k_week, slow_k_month = -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 len(items)>0:
|
||||||
|
slow_k_week = items[0]
|
||||||
|
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 len(items)>0:
|
||||||
|
slow_k_month = items[0]
|
||||||
|
|
||||||
|
return slow_k_week, slow_k_month
|
||||||
|
|
||||||
def buyRealTime(self, today, n = 200):
|
def buyRealTime(self, today, n = 200):
|
||||||
|
|
||||||
|
a,b = self.getSlowK("001430")
|
||||||
print ("START...")
|
print ("START...")
|
||||||
THIS_TIME = datetime.now()
|
THIS_TIME = datetime.now()
|
||||||
|
|
||||||
@@ -144,6 +159,10 @@ class HTS_Stocks (HTS):
|
|||||||
continue
|
continue
|
||||||
print(idx, stock_code, stock_name, ", CODE: ", stock_code, ", NAME: ", stock_name)
|
print(idx, stock_code, stock_name, ", CODE: ", stock_code, ", NAME: ", stock_name)
|
||||||
|
|
||||||
|
slow_k_week, slow_k_month = self.getSlowK(stock_code)
|
||||||
|
if slow_k_week < 0 or 20 < slow_k_week or slow_k_month < 0 or 20 < slow_k_month:
|
||||||
|
continue
|
||||||
|
|
||||||
stock = self.stockStatus.fetchLastData(self.cursor_stock, stock_code, n)
|
stock = self.stockStatus.fetchLastData(self.cursor_stock, stock_code, n)
|
||||||
try:
|
try:
|
||||||
self.getRealTime_DailyCheck(today, stock_code, stock)
|
self.getRealTime_DailyCheck(today, stock_code, stock)
|
||||||
|
|||||||
Reference in New Issue
Block a user