This commit is contained in:
dosangyoon
2022-08-03 14:59:44 +09:00
parent e3595ea4d0
commit b8e94a6eb0
4 changed files with 120 additions and 34 deletions

View File

@@ -456,13 +456,13 @@ class HTS:
return data
def insertStockData(self, inFileName, stock_code, stock_name, today):
def insertStockData(self, db_filename, stock_code, stock_name, today):
tableName = 'hts'
conn = sqlite3.connect(inFileName)
conn = sqlite3.connect(db_filename)
cursor = conn.cursor()
# 테이블 생성
cursor.execute("CREATE TABLE IF NOT EXISTS " + tableName + " (CODE text, NAME text, ymd text, hms text, close REAL, open REAL, high REAL, low REAL, volume REAL)")
cursor.execute("CREATE TABLE IF NOT EXISTS " + tableName + " (CODE text, NAME text, ymd text, hms text, close REAL, open REAL, high REAL, low REAL, volume REAL, label INTEGER DEFAULT 0)")
# 키 생성
create_key = "CREATE INDEX IF NOT EXISTS " + tableName + "_idx on " + tableName + " (CODE, ymd, hms) "
@@ -474,7 +474,7 @@ class HTS:
items = self.getStockInfo(stock_code, today)
conn = sqlite3.connect(inFileName)
conn = sqlite3.connect(db_filename)
cursor = conn.cursor()
idx = 0
for item in items:
@@ -548,6 +548,46 @@ class HTS:
result["vol"].append(int(vol))
return
def updateLabel(self, db_filename, stock_code, bsLine, data, ymd):
tableName = 'hts'
conn = sqlite3.connect(db_filename)
cursor = conn.cursor()
cursor.execute('Update ' + tableName + ' set label=? WHERE CODE=? and ymd=?', (0, stock_code, ymd,))
for i in range(len(bsLine["buy"])):
if bsLine["buy"][i] > 0:
ymd = data['date'][i].strftime('%Y%m%d')
hms = data['date'][i].strftime('%H%M')
cursor.execute('Update ' + tableName + ' set label=? WHERE CODE=? and ymd=? and hms=?', (2, stock_code, ymd, hms))
for i in range(len(bsLine["sell"])):
if bsLine["sell"][i] > 0:
ymd = data['date'][i].strftime('%Y%m%d')
hms = data['date'][i].strftime('%H%M')
cursor.execute('Update ' + tableName + ' set label=? WHERE CODE=? and ymd=? and hms=?', (1, stock_code, ymd, hms))
conn.commit()
cursor.close()
conn.close()
print("insert...", stock_code, ymd)
return
def getYMD(self, stock_code):
tableName = 'hts'
conn = sqlite3.connect(os.path.join(self.RESOURCE_PATH, "hts.db"))
cursor = conn.cursor()
result = []
cursor.execute('SELECT distinct ymd FROM ' + tableName + ' WHERE CODE=? order by ymd', (stock_code,))
db_result = cursor.fetchall()
for rows in db_result:
ymd = rows[0] # hts.날짜
result.append(ymd)
return result
def getDBData(self, stock_code, day, result):
tableName = 'hts'
conn = sqlite3.connect(os.path.join(self.RESOURCE_PATH, "hts.db"))