mirror of
https://gitee.com/fasiondog/hikyuu.git
synced 2024-12-02 03:48:19 +08:00
补充基金列表导入
This commit is contained in:
parent
6bc2f8acb9
commit
e1c798e8f1
@ -26,6 +26,7 @@ import requests
|
||||
import re
|
||||
import akshare as ak
|
||||
import pandas as pd
|
||||
import datetime
|
||||
from hikyuu.util import *
|
||||
|
||||
|
||||
@ -131,14 +132,36 @@ def get_index_code_name_list() -> list:
|
||||
return [{'market_code': df.loc[i]['代码'].upper(), 'name': df.loc[i]['名称']} for i in range(len(df))]
|
||||
|
||||
|
||||
def get_fund_code_name_list():
|
||||
g_fund_code_name_list = {}
|
||||
for market in g_market_list:
|
||||
g_fund_code_name_list[market] = []
|
||||
g_last_get_fund_code_name_list_date = datetime.date(1990, 12, 9)
|
||||
|
||||
|
||||
@hku_catch(ret=[], trace=True)
|
||||
def get_fund_code_name_list(market: str) -> list:
|
||||
"""
|
||||
获取基金代码名称列表 (来源: sina)
|
||||
"""
|
||||
# 保证一天只获取一次基金股票代码表,防止对 sina 的频繁访问
|
||||
global g_last_get_fund_code_name_list_date
|
||||
now = datetime.date.today()
|
||||
if now <= g_last_get_fund_code_name_list_date:
|
||||
return g_fund_code_name_list[market]
|
||||
|
||||
ind_list = "封闭式基金", "ETF基金", "LOF基金"
|
||||
df = None
|
||||
for ind in ind_list:
|
||||
df = ak.fund_etf_category_sina(ind)
|
||||
for i in range(len(df)):
|
||||
loc = df.loc[i]
|
||||
try:
|
||||
code, name = str(loc['代码']), str(loc['名称'])
|
||||
g_fund_code_name_list[code[:2].upper()].append(dict(code=code[2:], name=name))
|
||||
except Exception as e:
|
||||
hku_error("{}! {}", str(e), loc)
|
||||
hku_info("获取基金列表数量: {}", len(g_fund_code_name_list[market]))
|
||||
g_last_get_fund_code_name_list_date = now
|
||||
return g_fund_code_name_list[market]
|
||||
|
||||
|
||||
@hku_catch(ret=[], trace=True)
|
||||
|
@ -25,18 +25,20 @@
|
||||
import time
|
||||
from concurrent import futures
|
||||
from pytdx.hq import TdxHq_API
|
||||
#from pytdx.config.hosts import hq_hosts
|
||||
from pytdx.config.hosts import hq_hosts
|
||||
|
||||
hq_hosts = [
|
||||
('上海双线主站1', '47.103.48.45', 7709),
|
||||
('上海双线主站2', '47.103.86.229', 7709),
|
||||
('上海双线主站3', '47.103.88.146', 7709),
|
||||
('深圳双线主站1', '120.79.60.82', 7709),
|
||||
('深圳双线主站2', '47.112.129.66', 7709),
|
||||
('北京双线主站1', '39.98.234.173', 7709),
|
||||
('北京双线主站2', '39.98.198.249', 7709),
|
||||
('北京双线主站3', '39.100.68.59', 7709),
|
||||
]
|
||||
hq_hosts.extend(
|
||||
[
|
||||
('上海双线主站1', '47.103.48.45', 7709),
|
||||
('上海双线主站2', '47.103.86.229', 7709),
|
||||
('上海双线主站3', '47.103.88.146', 7709),
|
||||
('深圳双线主站1', '120.79.60.82', 7709),
|
||||
('深圳双线主站2', '47.112.129.66', 7709),
|
||||
('北京双线主站1', '39.98.234.173', 7709),
|
||||
('北京双线主站2', '39.98.198.249', 7709),
|
||||
('北京双线主站3', '39.100.68.59', 7709),
|
||||
]
|
||||
)
|
||||
|
||||
|
||||
def to_pytdx_market(market):
|
||||
|
@ -99,6 +99,8 @@ def import_stock_name(connect, api, market, quotations=None):
|
||||
|
||||
newStockDict = {}
|
||||
stk_list = get_stk_code_name_list(market)
|
||||
if not quotations or 'fund' in [v.lower() for v in quotations]:
|
||||
stk_list.extend(get_fund_code_name_list(market))
|
||||
for stock in stk_list:
|
||||
newStockDict[str(stock['code'])] = stock['name']
|
||||
|
||||
|
@ -96,6 +96,8 @@ def import_stock_name(connect, api, market, quotations=None):
|
||||
|
||||
newStockDict = {}
|
||||
stk_list = get_stk_code_name_list(market)
|
||||
if not quotations or 'fund' in [v.lower() for v in quotations]:
|
||||
stk_list.extend(get_fund_code_name_list(market))
|
||||
for stock in stk_list:
|
||||
newStockDict[str(stock['code'])] = stock['name']
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user