补充基金列表导入

This commit is contained in:
fasiondog 2022-08-20 01:05:20 +08:00
parent 6bc2f8acb9
commit e1c798e8f1
4 changed files with 42 additions and 13 deletions

View File

@ -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)

View File

@ -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):

View File

@ -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']

View File

@ -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']