Files
DeepCoin/downloader.py
dsyoon ef962843a1 init
2025-08-09 17:04:17 +09:00

57 lines
2.0 KiB
Python

from HTS2 import HTS
import sqlite3
from monitor_coin import get_coin_more_data
from config import *
hts = HTS()
def inserData(symbol, interval, data):
conn = sqlite3.connect('coins.db')
cursor = conn.cursor()
# 테이블/키 생성
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')
hms = data.index[i].strftime('%H%M%S')
ymdhms = data.index[i].strftime('%Y-%m-%d %H:%M:%S')
Open = data.Open.iloc[i]
High = data.High.iloc[i]
Low = data.Low.iloc[i]
Close = data.Close.iloc[i]
Volume = data.Volume.iloc[i]
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 interval=?", (Close, Open, High, Low, Volume, symbol, ymdhms, interval))
else:
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()
conn.close()
return
def download():
for symbol in KR_COINS:
print(symbol)
# 1시간
interval = 60
data = get_coin_more_data(symbol, interval, bong_count=10000)
if data is not None and not data.empty:
try:
inserData(symbol, interval, data)
except Exception as e:
print(f"Error processing data for {symbol}: {str(e)}")
return
if __name__ == "__main__":
download()