init
This commit is contained in:
53
hts/HTS.py
53
hts/HTS.py
@@ -1,10 +1,12 @@
|
||||
import os.path
|
||||
|
||||
import win32com.client
|
||||
import copy
|
||||
import platform
|
||||
if platform.system().lower().find("window") >= 0:
|
||||
import win32com.client
|
||||
import csv
|
||||
import time
|
||||
import sqlite3
|
||||
from datetime import datetime
|
||||
from datetime import datetime, timedelta
|
||||
from hts.OrderItem import OrderItem
|
||||
|
||||
class HTS:
|
||||
@@ -546,12 +548,12 @@ class HTS:
|
||||
result["vol"].append(int(vol))
|
||||
return
|
||||
|
||||
def getDBData(self, stock_code, lastday, result):
|
||||
def getDBData(self, stock_code, day, result):
|
||||
tableName = 'hts'
|
||||
conn = sqlite3.connect(os.path.join(self.RESOURCE_PATH, "hts.db"))
|
||||
cursor = conn.cursor()
|
||||
|
||||
cursor.execute('SELECT ymd, hms, open, high, low, close, volume FROM ' + tableName + ' WHERE CODE=? and ymd=? order by ymd, hms', (stock_code, lastday,))
|
||||
cursor.execute('SELECT ymd, hms, open, high, low, close, volume FROM ' + tableName + ' WHERE CODE=? and ymd=? order by ymd, hms', (stock_code, day,))
|
||||
db_result = cursor.fetchall()
|
||||
for rows in db_result:
|
||||
ymd = rows[0] # hts.날짜
|
||||
@@ -570,10 +572,21 @@ class HTS:
|
||||
result["high"].append(int(high))
|
||||
result["low"].append(int(low))
|
||||
result["vol"].append(int(vol))
|
||||
|
||||
return
|
||||
|
||||
# 주식 현재가 조회
|
||||
def getRealTime(self, stock_code, lastday, today):
|
||||
def isValidYMD(self, stock_code, day):
|
||||
tableName = 'hts'
|
||||
conn = sqlite3.connect(os.path.join(self.RESOURCE_PATH, "hts.db"))
|
||||
cursor = conn.cursor()
|
||||
|
||||
cursor.execute('SELECT ymd, count(*) as cnt FROM ' + tableName + ' WHERE CODE=? and ymd=?', (stock_code, day,))
|
||||
db_result = cursor.fetchone()
|
||||
if db_result[1] > 0:
|
||||
return True
|
||||
return False
|
||||
|
||||
def getLastData(self, stock_code, today, n=3):
|
||||
result = {"check": set(),
|
||||
"time": [],
|
||||
"open": [],
|
||||
@@ -582,9 +595,29 @@ class HTS:
|
||||
"low": [],
|
||||
"vol": []}
|
||||
|
||||
#last_stock_filename = os.path.join(self.RESOURCE_PATH, "hts", stock_code + "_" + lastday + ".csv")
|
||||
#self.getCSV(last_stock_filename, result)
|
||||
self.getDBData(stock_code, lastday, result)
|
||||
days = []
|
||||
for i in range(1, 10):
|
||||
last_day = (datetime.strptime(today, '%Y%m%d') - timedelta(i)).strftime('%Y%m%d')
|
||||
isValid = self.isValidYMD(stock_code, last_day)
|
||||
if isValid:
|
||||
days.append(last_day)
|
||||
if len(days) >= 3:
|
||||
break
|
||||
|
||||
days.sort()
|
||||
for day in days:
|
||||
self.getDBData(stock_code, day, result)
|
||||
|
||||
return result
|
||||
|
||||
# 주식 현재가 조회
|
||||
def getRealTime(self, stock_code, today, LAST_DATA=None):
|
||||
if LAST_DATA is not None:
|
||||
result = copy.deepcopy(LAST_DATA)
|
||||
else:
|
||||
result = {"check": set(), "time": [], "open": [], "close": [], "high": [], "low": [], "vol": []}
|
||||
|
||||
self.getDBData(stock_code, today, result)
|
||||
|
||||
int_given_day = int(today)
|
||||
objCpCybos = win32com.client.Dispatch("CpUtil.CpCybos")
|
||||
|
||||
Reference in New Issue
Block a user