mirror of
https://gitee.com/fasiondog/hikyuu.git
synced 2024-11-30 02:48:57 +08:00
get current finance (continue)
This commit is contained in:
parent
a63b35fbc0
commit
f06130ca4f
166
hikyuu/data/pytdx_finance_to_sqlite.py
Normal file
166
hikyuu/data/pytdx_finance_to_sqlite.py
Normal file
@ -0,0 +1,166 @@
|
||||
# coding:utf-8
|
||||
#
|
||||
# The MIT License (MIT)
|
||||
#
|
||||
# Copyright (c) 2010-2019 fasiondog/hikyuu
|
||||
#
|
||||
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
# of this software and associated documentation files (the "Software"), to deal
|
||||
# in the Software without restriction, including without limitation the rights
|
||||
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
# copies of the Software, and to permit persons to whom the Software is
|
||||
# furnished to do so, subject to the following conditions:
|
||||
#
|
||||
# The above copyright notice and this permission notice shall be included in all
|
||||
# copies or substantial portions of the Software.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
# SOFTWARE.
|
||||
|
||||
from hikyuu.data.common import MARKETID, STOCKTYPE
|
||||
from hikyuu.data.common_sqlite3 import get_marketid
|
||||
|
||||
|
||||
def pytdx_import_finance(db_connect, pytdx_connect, market):
|
||||
"""导入公司财务信息"""
|
||||
marketid = get_marketid(db_connect, market)
|
||||
sql = "select stockid, marketid, code, valid, type from stock where marketid={} and type = {} and valid=1"\
|
||||
.format(marketid, STOCKTYPE.A)
|
||||
|
||||
cur = db_connect.cursor()
|
||||
all_list = cur.execute(sql).fetchall()
|
||||
connect.commit()
|
||||
|
||||
records = []
|
||||
for stk in all_list:
|
||||
x = pytdx_connect.get_finance_info(1 if stk[1] == MARKETID.SH else 0, stk[2])
|
||||
#print(stk[2], x['code'])
|
||||
if x is not None and x['code'] == stk[2]:
|
||||
cur.execute("select updated_date from stkfinance where stockid={} and updated_date={}".format(stk[0], x['updated_date']))
|
||||
a = cur.fetchall()
|
||||
a = [x[0] for x in a]
|
||||
if a:
|
||||
print(a)
|
||||
continue
|
||||
else:
|
||||
print(market, stk[2])
|
||||
records.append((stk[0],
|
||||
x['updated_date'],
|
||||
x['ipo_date'],
|
||||
x['province'],
|
||||
x['industry'],
|
||||
x['zongguben'],
|
||||
x['liutongguben'],
|
||||
x['guojiagu'],
|
||||
x['faqirenfarengu'],
|
||||
x['farengu'],
|
||||
x['bgu'],
|
||||
x['hgu'],
|
||||
x['zhigonggu'],
|
||||
x['zongzichan'],
|
||||
x['liudongzichan'],
|
||||
x['gudingzichan'],
|
||||
x['wuxingzichan'],
|
||||
x['gudongrenshu'],
|
||||
x['liudongfuzhai'],
|
||||
x['changqifuzhai'],
|
||||
x['zibengongjijin'],
|
||||
x['jingzichan'],
|
||||
x['zhuyingshouru'],
|
||||
x['zhuyinglirun'],
|
||||
x['yingshouzhangkuan'],
|
||||
x['yingyelirun'],
|
||||
x['touzishouyu'],
|
||||
x['jingyingxianjinliu'],
|
||||
x['zongxianjinliu'],
|
||||
x['cunhuo'],
|
||||
x['lirunzonghe'],
|
||||
x['shuihoulirun'],
|
||||
x['jinglirun'],
|
||||
x['weifenpeilirun'],
|
||||
x['meigujingzichan'],
|
||||
x['baoliu2']
|
||||
))
|
||||
pass
|
||||
|
||||
if records:
|
||||
cur.executemany("INSERT INTO stkfinance(stockid, \
|
||||
updated_date, \
|
||||
ipo_date, \
|
||||
province, \
|
||||
industry, \
|
||||
zongguben, \
|
||||
liutongguben, \
|
||||
guojiagu, \
|
||||
faqirenfarengu, \
|
||||
farengu, \
|
||||
bgu, \
|
||||
hgu, \
|
||||
zhigonggu, \
|
||||
zongzichan, \
|
||||
liudongzichan, \
|
||||
gudingzichan, \
|
||||
wuxingzichan, \
|
||||
gudongrenshu, \
|
||||
liudongfuzhai, \
|
||||
changqifuzhai, \
|
||||
zibengongjijin, \
|
||||
jingzichan, \
|
||||
zhuyingshouru, \
|
||||
zhuyinglirun, \
|
||||
yingshouzhangkuan, \
|
||||
yingyelirun, \
|
||||
touzishouru, \
|
||||
jingyingxianjinliu, \
|
||||
zongxianjinliu, \
|
||||
cunhuo, \
|
||||
lirunzonghe, \
|
||||
shuihoulirun, \
|
||||
jinglirun, \
|
||||
weifenpeilirun, \
|
||||
meigujingzichan, \
|
||||
baoliu2) \
|
||||
VALUES (?,?,?,?,?,?,?,?,?,?, \
|
||||
?,?,?,?,?,?,?,?,?,?, \
|
||||
?,?,?,?,?,?,?,?,?,?, \
|
||||
?,?,?,?,?,?)",
|
||||
records)
|
||||
connect.commit()
|
||||
|
||||
cur.close()
|
||||
return len(records)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
import os
|
||||
import time
|
||||
import sqlite3
|
||||
|
||||
starttime = time.time()
|
||||
|
||||
dest_dir = "d:\\stock"
|
||||
tdx_server = '119.147.212.81'
|
||||
tdx_port = 7709
|
||||
|
||||
connect = sqlite3.connect(dest_dir + "\\stock.db")
|
||||
#create_database(connect)
|
||||
|
||||
from pytdx.hq import TdxHq_API, TDXParams
|
||||
api = TdxHq_API()
|
||||
api.connect(tdx_server, tdx_port)
|
||||
|
||||
x = pytdx_import_finance(connect, api, "SH")
|
||||
print(x)
|
||||
|
||||
api.disconnect()
|
||||
connect.close()
|
||||
|
||||
endtime = time.time()
|
||||
print("\nTotal time:")
|
||||
print("%.2fs" % (endtime - starttime))
|
||||
print("%.2fm" % ((endtime - starttime) / 60))
|
@ -548,7 +548,6 @@ if __name__ == '__main__':
|
||||
add_count = qianlong_import_weight(connect, dest_dir + '/weight', 'SH')
|
||||
add_count += qianlong_import_weight(connect, dest_dir + '/weight', 'SZ')
|
||||
print("导入数量:", add_count)
|
||||
"""
|
||||
|
||||
print("\n导入上证分笔数据")
|
||||
#add_count = import_trans(connect, 'SH', quotations, api, dest_dir, max_days=2, progress=ProgressBar)
|
||||
@ -558,7 +557,7 @@ if __name__ == '__main__':
|
||||
print("\n导入上证分时数据")
|
||||
add_count = import_time(connect, 'SZ', quotations, api, dest_dir, max_days=3, progress=ProgressBar)
|
||||
print("\n导入数量:", add_count)
|
||||
|
||||
"""
|
||||
|
||||
api.disconnect()
|
||||
connect.close()
|
||||
|
43
hikyuu/data/sqlite_upgrade/0002.sql
Normal file
43
hikyuu/data/sqlite_upgrade/0002.sql
Normal file
@ -0,0 +1,43 @@
|
||||
CREATE TABLE `stkfinance` (
|
||||
id INTEGER NOT NULL,
|
||||
stockid INTEGER,
|
||||
`updated_date` INTEGER,
|
||||
`ipo_date` INTEGER,
|
||||
`province` INTEGER,
|
||||
`industry` INTEGER,
|
||||
`zongguben` NUMERIC,
|
||||
`liutongguben` NUMERIC,
|
||||
`guojiagu` NUMERIC,
|
||||
`faqirenfarengu` NUMERIC,
|
||||
`farengu` NUMERIC,
|
||||
`bgu` NUMERIC,
|
||||
`hgu` NUMERIC,
|
||||
`zhigonggu` NUMERIC,
|
||||
`zongzichan` NUMERIC,
|
||||
`liudongzichan` NUMERIC,
|
||||
`gudingzichan` NUMERIC,
|
||||
`wuxingzichan` NUMERIC,
|
||||
`gudongrenshu` NUMERIC,
|
||||
`liudongfuzhai` NUMERIC,
|
||||
`changqifuzhai` NUMERIC,
|
||||
`zibengongjijin` NUMERIC,
|
||||
`jingzichan` NUMERIC,
|
||||
`zhuyingshouru` NUMERIC,
|
||||
`zhuyinglirun` NUMERIC,
|
||||
`yingshouzhangkuan` NUMERIC,
|
||||
`yingyelirun` NUMERIC,
|
||||
`touzishouru` NUMERIC,
|
||||
`jingyingxianjinliu` NUMERIC,
|
||||
`zongxianjinliu` NUMERIC,
|
||||
`cunhuo` NUMERIC,
|
||||
`lirunzonghe` NUMERIC,
|
||||
`shuihoulirun` NUMERIC,
|
||||
`jinglirun` NUMERIC,
|
||||
`weifenpeilirun` NUMERIC,
|
||||
`meigujingzichan` NUMERIC,
|
||||
`baoliu2` NUMERIC,
|
||||
PRIMARY KEY (id),
|
||||
FOREIGN KEY(stockid) REFERENCES "Stock" (stockid)
|
||||
);
|
||||
|
||||
UPDATE `version` set `version` = 2;
|
Loading…
Reference in New Issue
Block a user