Merge pull request #140 from fasiondog/feature/tools

Feature/tools 更新板块信息; 创建默认配置,以便用于无GUI环境
This commit is contained in:
fasiondog 2023-12-19 01:56:22 +08:00 committed by GitHub
commit 61245ffe1c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 126007 additions and 38131 deletions

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -1,55 +0,0 @@
[港澳中线]
[港澳点评]
1,000933
1,000557
1,000613
1,000529
1,000030
1,000031
1,000050
1,000406
1,000416
1,000530
1,000681
1,000881
0,600238
0,600586
0,600165
0,600221
0,600173
0,600215
0,600462
0,600122
1,000683
0,600660
0,600567
0,600291
0,600794
0,600386
0,600088
0,600630
0,600884
0,600054
0,600078
0,600115
0,600859
1,000562
1,000430
0,600350
0,600020
0,600087
1,000995
1,001896
0,600728
0,600706
0,600577
1,000150
0,600721
1,000498
0,600005
0,600028
0,600657
0,600850
0,600352
1,000828
1,000429

File diff suppressed because it is too large Load Diff

View File

@ -144,3 +144,123 @@ usr = {usr}
pwd = {pwd}
"""
import_config_template = """
[quotation]
stock = True
fund = True
future = False
[ktype]
day = True
min = True
min5 = True
trans = True
time = True
day_start_date = 1990-12-19
min_start_date = 2023-09-19
min5_start_date = 2023-09-19
trans_start_date = 2023-12-11
time_start_date = 2023-12-11
[weight]
enable = True
[tdx]
enable = False
;dir = d:\TdxW_HuaTai
[pytdx]
enable = False
use_tdx_number = 10
[hdf5]
enable = True
dir = {dir}
[mysql]
enable = False
;tmpdir = D:/stock
;host = 127.0.0.1
;port = 3306
;usr = root
;pwd =
[sched]
time = 18:00:00
[collect]
quotation_server = ipc:///tmp/hikyuu_real.ipc
interval = 305
source = qq
use_zhima_proxy = False
phase1_start = 00:00:00
phase1_end = 11:35:00
phase2_start = 12:00:00
phase2_end = 15:05:00
[preload]
day = True
week = True
month = True
quarter = False
halfyear = False
year = False
min = False
min5 = False
min15 = False
min30 = False
min60 = False
hour2 = False
day_max = 100000
week_max = 100000
month_max = 100000
quarter_max = 100000
halfyear_max = 100000
year_max = 100000
min_max = 5120
min5_max = 5120
min15_max = 5120
min30_max = 5120
min60_max = 5120
hour2_max = 5120
"""
def generate_default_config():
import os
import sys
import shutil
from hikyuu.data.hku_config_template import hdf5_template
user_dir = os.path.expanduser('~')
data_dir = "c:\\stock" if sys.platform == 'win32' else f"{user_dir}/stock"
hdf5_config = hdf5_template.format(dir=data_dir, quotation_server='ipc:///tmp/hikyuu_real.ipc',
day=True, week=False,
month=False, quarter=False, halfyear=False, year=False,
min1=False, min5=False, min15=False, min30=False,
min60=False, hour2=False, day_max=100000, week_max=100000,
month_max=100000, quarter_max=100000, halfyear_max=100000,
year_max=100000, min1_max=5120, min5_max=5120, min15_max=5120,
min30_max=5120, min60_max=5120, hour2_max=5120)
config_dir = f"{user_dir}/.hikyuu"
if not os.path.lexists(config_dir):
os.makedirs(config_dir)
filename = f"{config_dir}/hikyuu.ini"
if not os.path.exists(filename):
with open(filename, 'w', encoding='utf-8') as f:
f.write(hdf5_config)
if not os.path.lexists(data_dir):
os.makedirs(data_dir)
filename = f"{config_dir}/importdata-gui.ini"
if not os.path.exists(filename):
with open(filename, 'w', encoding='utf-8') as f:
f.write(import_config_template.format(dir=data_dir))
if not os.path.lexists(data_dir + '/block'):
current_dir = os.path.dirname(os.path.abspath(__file__))
dirname, _ = os.path.split(current_dir)
dirname = os.path.join(dirname, 'config/block')
shutil.copytree(dirname, data_dir + '/block')
os.remove(data_dir + '/block/__init__.py')

View File

@ -24,6 +24,7 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
from hikyuu.data.hku_config_template import generate_default_config
from .draw import *
__copyright__ = """
MIT License
@ -54,6 +55,7 @@ import sys
import os
import configparser
from hikyuu.data.hku_config_template import generate_default_config
from hikyuu import *
# 重定向C++ stdout/stderr输出至python
@ -74,22 +76,11 @@ if sys.platform == 'win32':
# 读取配置信息,并初始化
#
# ==============================================================================
# config_file = './test_data/hikyuu_win.ini'
config_file = os.path.expanduser('~') + "/.hikyuu/hikyuu.ini"
if not os.path.exists(config_file):
# 检查老版本配置是否存在,如果存在可继续使用,否则异常终止
data_config_file = os.path.expanduser('~') + "/.hikyuu/data_dir.ini"
if not os.path.exists(data_config_file):
raise Exception("未找到配置文件,请先使用数据导入工具导入数据(将自动生成配置文件)!!!")
data_config = configparser.ConfigParser()
data_config.read(data_config_file)
data_dir = data_config['data_dir']['data_dir']
if sys.platform == 'win32':
config_file = data_dir + "\\hikyuu_win.ini"
else:
config_file = data_dir + "/hikyuu_linux.ini"
if not os.path.exists(config_file):
raise Exception("未找到配置文件,请先使用数据导入工具导入数据(将自动生成配置文件)!!!")
# 创建默认配置
hku_info("创建默认配置文件")
generate_default_config()
ini = configparser.ConfigParser()
ini.read(config_file, encoding='utf-8')
@ -184,7 +175,7 @@ zsbk_zxb = blockzxb
zsbk_sz50 = sm.get_block("指数板块", "上证50")
zsbk_sz180 = sm.get_block("指数板块", "上证180")
zsbk_hs300 = sm.get_block("指数板块", "沪深300")
zsbk_zz100 = sm.get_block("指数板块", "沪深300")
zsbk_zz100 = sm.get_block("指数板块", "中证100")
def set_global_context(stk, query):

View File

@ -0,0 +1,168 @@
#!/usr/bin/python
# -*- coding: utf8 -*-
#
# Create on: 2023-12-18
# Author: fasiondog
import requests
import akshare as ak
from hikyuu.interactive import *
def get_code_market_dict():
ret = {}
for s in sm:
if s.type in (constant.STOCKTYPE_A, constant.STOCKTYPE_B, constant.STOCKTYPE_GEM, constant.STOCKTYPE_START):
ret[s.code] = "0" if s.market == 'SH' else "1"
return ret
def get_all_hybk_info():
code_market = get_code_market_dict()
blk_names = ak.stock_board_industry_name_em()['']
ret = {}
for blk_name in blk_names:
print(blk_name)
ret[blk_name] = []
stk_codes = ak.stock_board_industry_cons_em(blk_name)
stk_codes = stk_codes[''].to_list()
for stk_code in stk_codes:
try:
ret[blk_name].append(f"{code_market[stk_code]},{stk_code}")
except:
print(stk_code)
return ret
def get_all_gnbk_info():
code_market = get_code_market_dict()
blk_names = ak.stock_board_concept_name_em()['']
ret = {}
for blk_name in blk_names:
print(blk_name)
ret[blk_name] = []
stk_codes = ak.stock_board_concept_cons_em(blk_name)
stk_codes = stk_codes[''].to_list()
for stk_code in stk_codes:
try:
ret[blk_name].append(f"{code_market[stk_code]},{stk_code}")
except:
print(stk_code)
return ret
def get_all_dybk_info():
url = "http://13.push2.eastmoney.com/api/qt/clist/get"
params = {
"pn": "1",
"pz": "50000",
"po": "1",
"np": "1",
"ut": "bd1d9ddb04089700cf9c27f6f7426281",
"fltt": "2",
"invt": "2",
"fid": "f3",
"fs": "m:90+t:1+f:!50",
"fields": "f12,f14",
# "fields": "f1,f2,f3,f4,f5,f6,f7,f8,f9,f10,f12,f13,f14,f15,f16,f17,f18,f20,f21,f23,f24,f25,f22,f11,f62,f128,"
# "f136,f115,f152",
"_": "1623833739532",
}
r = requests.get(url, params=params)
data_json = r.json()
data_json = data_json["data"]["diff"]
params = {
"pn": "1",
"pz": "2000",
"po": "1",
"np": "1",
"ut": "bd1d9ddb04089700cf9c27f6f7426281",
"fltt": "2",
"invt": "2",
"fid": "f3",
# "fs": f"b:{stock_board_code} f:!50",
"fields": "f12",
"_": "1626081702127",
}
ret = {}
code_market = get_code_market_dict()
for v in data_json:
# print(v)
blk_code = v["f12"]
blk_name = v["f14"]
print(blk_name)
ret[blk_name] = []
params["fs"] = f"b:{blk_code} f:!50"
r = requests.get(url, params=params)
stk_json = r.json()
stk_json = stk_json["data"]["diff"]
for item in stk_json:
stk_code = item["f12"]
try:
ret[blk_name].append(f"{code_market[stk_code]},{stk_code}")
except:
print(stk_code)
return ret
def get_all_zsbk_info():
code_market = get_code_market_dict()
blk_info = ak.index_stock_info()
blk_codes = blk_info["index_code"]
blk_names = blk_info["display_name"]
ret = {}
total = len(blk_codes)
# for blk_name in blk_names:
for i in range(total):
blk_name = blk_names[i]
blk_code = blk_codes[i]
print(i, blk_name)
# 沪深指数有重复,避免深指覆盖
if blk_name in ret:
continue
try:
ret[blk_name] = []
stk_codes = ak.index_stock_cons_csindex(symbol=blk_code)
stk_codes = stk_codes[''].to_list()
for stk_code in stk_codes:
try:
ret[blk_name].append(f"{code_market[stk_code]},{stk_code}")
except:
print(stk_code)
except KeyboardInterrupt:
exit(-1)
except:
print("Failed!", blk_code, blk_name)
return ret
def write_blk_file(blk_info, filename):
with open(filename, 'w', encoding='utf-8') as f:
for k in blk_info:
print(k)
if blk_info[k]:
f.write(f"[{k}]\n")
for code in blk_info[k]:
f.write(f'{code}\n')
if __name__ == "__main__":
# 更新行业板块
x = get_all_hybk_info()
write_blk_file(x, 'hikyuu/config/block/hybk.ini')
# 更新概念板块
x = get_all_gnbk_info()
write_blk_file(x, 'hikyuu/config/block/gnbk.ini')
# 更新地域板块
x = get_all_dybk_info()
write_blk_file(x, 'hikyuu/config/block/dybk.ini')
# 更新指数成分
x = get_all_zsbk_info()
write_blk_file(x, 'hikyuu/config/block/zsbk.ini')
# print(x)