-
Notifications
You must be signed in to change notification settings - Fork 5
/
funds.txt
118 lines (103 loc) · 3.63 KB
/
funds.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
"""
scheduler.add_job(
sync_fund_net_value,
"cron",
hour=4,
minute=15,
name="sync_fund_net_value",
)
scheduler.add_job(
sync_funds,
"cron",
hour=4,
minute=0,
name="sync_funds",
)
scheduler.add_job(
sync_fund_share_daily,
"cron",
hour=4,
minute=5,
name="sync_fund_share_daily",
)
scheduler.add_job(
sync_fund_portfolio_stock,
"cron",
hour=4,
minute=10,
name="sync_fund_portfolio_stock",
)
"""
class AbstractQuotesFetcher(QuotesFetcher):
@classmethod
async def get_fund_list(
cls, code: Union[str, List[str]] = None, fields: List[str] = None
) -> Union[None, np.ndarray]:
funds = await cls.get_instance().get_fund_list(code)
if len(funds) == 0:
logger.warning(f"failed to update funds. {funds} is returned")
return funds
await Funds.save(funds)
if not fields:
return funds
if isinstance(fields, str):
fields = [fields]
mapping = dict(funds.dtype.descr)
fields = [(name, mapping[name]) for name in fields]
return rfn.require_fields(funds, fields)
@classmethod
async def get_fund_net_value(
cls, code: Union[str, List[str]] = None, day=None, fields: List[str] = None
) -> Union[None, np.ndarray]:
fund_net_values = await cls.get_instance().get_fund_net_value(code, day)
if len(fund_net_values) == 0:
logger.warning(f"failed to update funds. {fund_net_values} is returned")
return fund_net_values
await FundNetValue.save(fund_net_values, day=day)
if not fields:
return fund_net_values
if isinstance(fields, str):
fields = [fields]
mapping = dict(fund_net_values.dtype.descr)
fields = [(name, mapping[name]) for name in fields]
return rfn.require_fields(fund_net_values, fields)
@classmethod
async def get_fund_share_daily(
cls,
code: Union[str, List[str]] = None,
day: Union[str, datetime.date] = None,
fields: List[str] = None,
) -> Union[None, np.ndarray]:
fund_net_values = await cls.get_instance().get_fund_share_daily(code, day)
if len(fund_net_values) == 0:
logger.warning(f"failed to update funds. {fund_net_values} is returned")
return fund_net_values
await FundShareDaily.save(fund_net_values)
if not fields:
return fund_net_values
if isinstance(fields, str):
fields = [fields]
mapping = dict(fund_net_values.dtype.descr)
fields = [(name, mapping[name]) for name in fields]
return rfn.require_fields(fund_net_values, fields)
@classmethod
async def get_fund_portfolio_stock(
cls,
code: Union[str, List[str]] = None,
pub_date: Union[str, datetime.date] = None,
fields: List[str] = None,
) -> Union[None, np.ndarray]:
fund_net_values = await cls.get_instance().get_fund_portfolio_stock(
code, pub_date
)
if len(fund_net_values) == 0:
logger.warning(f"failed to update funds. {fund_net_values} is returned")
return fund_net_values
await FundPortfolioStock.save(fund_net_values)
if not fields:
return fund_net_values
if isinstance(fields, str):
fields = [fields]
mapping = dict(fund_net_values.dtype.descr)
fields = [(name, mapping[name]) for name in fields]
return rfn.require_fields(fund_net_values, fields)