Ejemplo n.º 1
0
def update_fund_nav(prefix: str, mongo=None):
    if not mongo:
        mongo = Mongo()

    for code in mongo.get_list(prefix):
        ms = mongo.find_last(code)['_id']
        start = datetime.fromtimestamp(ms / 1000.0).strftime('%Y-%m-%d')
        print(code, start)
        df = JqData.fund_nav_daily(code.lstrip(prefix), start)
        if df.empty:
            print('empty')
            continue
        print(df)
        print()
        mongo.save(code, df)
Ejemplo n.º 2
0
def save_scales(prefix: str, codes=None, mongo=None):
    if not mongo:
        mongo = Mongo()
    result = []
    lst = codes if codes else mongo.get_list(prefix)
    for code in lst:
        code = code.lstrip(prefix)
        dic = {'_id': code}
        dic['period_end'], dic['total_tna'] = JqData.get_scale(code)
        result.append(dic)
    df = pd.DataFrame(result)
    df['_id'] = df['_id'].apply(lambda x: int(x))
    df['total_tna'] = df['total_tna'].apply(lambda x: round(float(x / 100000000), 2))
    df = df.sort_values('_id')
    print(df)
    mongo.save('funds_indicator', df)