Пример #1
0
def update_optional_data():
    """每天8点更新自选基金历史净值"""

    yesterday = dt.yesterday()

    records = FundHistoryNetWorth.objects.aggregate(
        {'$match': {
            'is_delete': 0
        }}, {"$group": {
            "_id": "$code",
            'date': {
                '$max': '$date'
            }
        }})

    for rec in records:
        code = rec['_id']
        last_day = rec['date']
        days = (yesterday - last_day).days
        if days <= 0:
            continue
        net_worth_list = FundData.sync_get_section_net_worth(
            code,
            last_day.strftime("%Y-%m-%d"),
            yesterday.strftime("%Y-%m-%d"),
            raw=True)
        fund_name = FundData.sync_get_fund_name(code)
        for entry in net_worth_list:
            FundHistoryNetWorth.create(code, fund_name,
                                       float(entry[1]) * 1000, entry[0],
                                       float(entry[3][:-1]))
Пример #2
0
 def sync_get_last_month_net_worth(cls, code):
     """同步方法, 获取近一个月的净值, 包含非交易日"""
     yesterday = dt.yesterday()
     last_month = yesterday - datetime.timedelta(days=30)
     url = cls.FUND_NET_WORTH_URL_BY_DATE % (
         code, 1, 10, last_month.strftime("%Y-%m-%d"),
         yesterday.strftime("%Y-%m-%d"))
     response = requests.get(url)
     lines = cls.data_re.findall(response.text)
     res = list()
     for i in range(1, len(lines)):
         match = cls.line_re.match(lines[i])
         if match:
             entry = match.groups()
             res.append(entry)
     return res
Пример #3
0
 async def get_yesterday_net_worth(cls, code, raw=False):
     """获取昨日净值"""
     yesterday = dt.yesterday()
     if yesterday.weekday() in {5, 6}:
         pass
     return await cls.get_date_net_worth(code, dt.yesterday_str(), raw)