init
This commit is contained in:
@@ -1,6 +1,4 @@
|
|||||||
from HTS2 import HTS
|
from HTS2 import HTS
|
||||||
from dateutil.relativedelta import relativedelta
|
|
||||||
from datetime import datetime
|
|
||||||
import sqlite3
|
import sqlite3
|
||||||
from stock_monitor import get_coin_more_data
|
from stock_monitor import get_coin_more_data
|
||||||
from config import *
|
from config import *
|
||||||
@@ -12,25 +10,25 @@ def inserData(symbol, interval, data):
|
|||||||
cursor = conn.cursor()
|
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 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)")
|
cursor.execute("CREATE INDEX IF NOT EXISTS " + symbol + "_idx on " + symbol + "(interval, CODE, ymdhms)")
|
||||||
|
|
||||||
for i in range(len(data)):
|
for i in range(len(data)):
|
||||||
ymd = data.index[i].strftime('%Y%m%d')
|
ymd = data.index[i].strftime('%Y%m%d')
|
||||||
hms = data.index[i].strftime('%H%M%S')
|
hms = data.index[i].strftime('%H%M%S')
|
||||||
ymdhms = data.index[i].strftime('%Y-%m-%d %H:%M:%S')
|
ymdhms = data.index[i].strftime('%Y-%m-%d %H:%M:%S')
|
||||||
open = data.Open.iloc[i]
|
Open = data.Open.iloc[i]
|
||||||
high = data.High.iloc[i]
|
High = data.High.iloc[i]
|
||||||
low = data.Low.iloc[i]
|
Low = data.Low.iloc[i]
|
||||||
close = data.Close.iloc[i]
|
Close = data.Close.iloc[i]
|
||||||
volume = data.Volume.iloc[i]
|
Volume = data.Volume.iloc[i]
|
||||||
|
|
||||||
cursor.execute("SELECT * from " + symbol + " where CODE = ? and ymdhms = ? and interval = ?", (symbol, ymdhms, interval))
|
cursor.execute("SELECT * from " + symbol + " where CODE = ? and ymdhms = ? and interval = ?", (symbol, ymdhms, interval))
|
||||||
arr = cursor.fetchone()
|
arr = cursor.fetchone()
|
||||||
if arr:
|
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))
|
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:
|
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))
|
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()
|
conn.commit()
|
||||||
cursor.close()
|
cursor.close()
|
||||||
|
|||||||
Reference in New Issue
Block a user