def fetch_by_date(to_date: str = date_utils.get_current_dt()):
    to_date = trade_date_service.get_next_trade_date(to_date)
    from_date = fetch_from_date()
    trade_date_service.refresh_cache(trade_date_service.get_previous_trade_date(from_date), to_date)
    return fetch.common_fetch_report(TsExpress, 'fetch_express',
                                     TsExpress.ts_code, TsExpress.mq_ann_date,
                                     from_date=from_date, to_date=to_date)
def run(to_date: str = date_utils.get_current_dt()):
    dt_code_map = {}

    # 股票基础信息
    init_ts_basic.init()
    # 交易日历
    fetch_trade_cal.fetch(to_date)

    trade_date_service.refresh_cache(fetch_data_start_date,
                                     date_utils.format_delta(to_date, 30))

    to_fetch_list = [
        # 同花顺指数
        fetch_ths_index.run,
        # 券商金股
        fetch_broker_recommend.fetch,
        # 分红记录
        fetch_dividend.update_dividend_to,
        # 每日指标
        fetch_daily_basic.fetch_by_date,
        # 每日交易
        fetch_daily_bar.fetch_by_date,
        # 复权因子
        fetch_adj_factor.fetch_by_date,
        # 涨跌停价格
        fetch_stk_limit.fetch_by_date,
        # 利润表
        fetch_income.fetch_by_period,
        # 资产负债表
        fetch_balance_sheet.fetch_by_period,
        # 现金流量表
        fetch_cash_flow.fetch_by_period,
        # 预报
        fetch_forecast.fetch_by_period,
        # 快报
        fetch_express.fetch_by_period,
        # 财务指标
        fetch_fina_indicator.fetch_by_period
    ]

    if env_utils.parallel():
        fl = []
        for func in to_fetch_list:
            fl.append(threadpool.submit(func, to_date=to_date))
        for f in fl:
            m = f.result()
            if m is not None:
                fetch.merge_from_map(dt_code_map, m)
    else:
        for func in to_fetch_list:
            m = func(to_date=to_date)
            if m is not None:
                fetch.merge_from_map(dt_code_map, m)

    return dt_code_map
Exemple #3
0
                                     from_date=from_date,
                                     to_date=to_date)


def fetch_from_period():
    s: Session = db_client.get_session()
    result = s.query(func.max(TsCashFlow.end_date)) \
        .all()
    s.close()
    from_date = fetch_data_start_period
    if len(result) > 0 and not result[0][0] is None:
        from_date = date_utils.period_delta(result[0][0], -4)
    return from_date


def fetch_by_period(to_date: str = date_utils.get_current_dt()):
    to_period = date_utils.next_period(to_date)
    from_period = fetch_from_period()
    return fetch.common_fetch_report_by_period(TsCashFlow,
                                               'fetch_cash_flow',
                                               TsCashFlow.end_date,
                                               from_period=from_period,
                                               to_period=to_period)


if __name__ == '__main__':
    trade_date_service.refresh_cache(
        fetch_data_start_date,
        date_utils.format_delta(date_utils.get_current_dt(), 30))
    print(fetch_by_date())