This commit is contained in:
dsyoon
2025-08-06 23:29:58 +09:00
parent 7135bf71f0
commit 177abfb908
3 changed files with 25 additions and 11 deletions

View File

@@ -12,8 +12,8 @@ def inserData(symbol, interval, data):
cursor = conn.cursor()
# 테이블/키 생성
cursor.execute("CREATE TABLE IF NOT EXISTS " + symbol + " (period text, CODE text, NAME text, ymdhms datetime, ymd text, hms text, close REAL, open REAL, high REAL, low REAL, volume REAL)")
cursor.execute("CREATE INDEX IF NOT EXISTS " + symbol + "_idx on " + symbol + "(CODE, ymdhms)")
cursor.execute("CREATE TABLE IF NOT EXISTS " + symbol + " (interval text, CODE text, NAME text, ymdhms datetime, ymd text, hms text, close REAL, open REAL, high REAL, low REAL, volume REAL)")
cursor.execute("CREATE INDEX IF NOT EXISTS " + symbol + "_idx on " + symbol + "(interval, CODE, ymdhms)")
for i in range(len(data)):
ymd = data.index[i].strftime('%Y%m%d')
@@ -28,9 +28,9 @@ def inserData(symbol, interval, data):
cursor.execute("SELECT * from " + symbol + " where CODE = ? and ymdhms = ? and interval = ?", (symbol, ymdhms, interval))
arr = cursor.fetchone()
if arr:
cursor.execute("UPDATE " + symbol + " SET close=?, open=?, high=?, low=?, volume=? where CODE=? and ymdhms=? and period=?", (close, open, high, low, volume, symbol, ymdhms, interval))
cursor.execute("UPDATE " + symbol + " SET close=?, open=?, high=?, low=?, volume=? where CODE=? and ymdhms=? and interval=?", (close, open, high, low, volume, symbol, ymdhms, interval))
else:
cursor.execute("INSERT INTO " + symbol + " (period, CODE, NAME, ymdhms, ymd, hms, close, open, high, low, volume) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", (interval, symbol, KR_COINS[symbol], ymdhms, ymd, hms, close, open, high, low, volume))
cursor.execute("INSERT INTO " + symbol + " (interval, CODE, NAME, ymdhms, ymd, hms, close, open, high, low, volume) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", (interval, symbol, KR_COINS[symbol], ymdhms, ymd, hms, close, open, high, low, volume))
conn.commit()
cursor.close()
@@ -39,6 +39,7 @@ def inserData(symbol, interval, data):
def download():
for symbol in KR_COINS:
print(symbol)
# 1시간
interval = 60