Beispiel #1
0
def process_stock_download(ts_code,
                           start_date,
                           end_date,
                           asset='E',
                           freq='D',
                           sys_event_list=['MARK_CP']):
    exec_date = date.today()
    evt_status = get_event_status('HIST_DOWNLOAD', exec_date)

    if ts_code is None:
        if evt_status == 0:
            print("previous downloading is still ongoing")
        elif evt_status == 1:
            print("history has been downloaded today")
        else:  # event not exist, can run today
            if ts_code is None:
                init_eventlog('HIST_DOWNLOAD', exec_date=exec_date, freq=freq)
            handle_hist_download(ts_code, start_date, end_date, asset, freq,
                                 sys_event_list)
            if ts_code is None:
                set_event_completed('HIST_DOWNLOAD',
                                    exec_date=exec_date,
                                    freq=freq)
            print("history has been downloaded successfully")
    else:
        handle_hist_download(ts_code, start_date, end_date, asset, freq,
                             sys_event_list)
Beispiel #2
0
def handle_daily_basic(ts_code, start_date, end_date, freq='D'):
    exec_date = date.today()
    if ts_code is None:
        if is_hist_downloaded():
            init_eventlog('DAILY_BASIC', exec_date=exec_date, freq=freq)
            basic_download(
                ts_code,
                start_date,
                end_date,
                freq,
            )
            set_event_completed('DAILY_BASIC', exec_date=exec_date, freq=freq)
    else:
        basic_download(
            ts_code,
            start_date,
            end_date,
            freq,
        )
def pre_handle_jx(ts_code,
                  freq='D',
                  ma_freq='25',
                  version='v1',
                  slope_offset=2):
    exec_date = date.today()

    if ts_code is None:
        if ready2proceed('junxian' + ma_freq + '_bs', freq):
            init_eventlog('MARK_CP',
                          exec_date,
                          'junxian' + ma_freq + '_bs',
                          freq=freq)
            process_junxian_cp(ts_code, freq, ma_freq, version, slope_offset)
            set_event_completed('MARK_CP',
                                exec_date,
                                'junxian' + ma_freq + '_bs',
                                freq=freq)
    else:
        process_junxian_cp(ts_code, freq, ma_freq, version, slope_offset)
Beispiel #4
0
def basic_download(ts_code, start_date, end_date, freq='D'):
    exec_date = date.today()
    evt_status = get_event_status('DAILY_BASIC', exec_date)

    if ts_code is None:
        if evt_status == 0:
            print("previous downloading is still ongoing")
        elif evt_status == 1:
            print("history has been downloaded today")
        else:  # event not exist, can run today
            if ts_code is None:
                init_eventlog('DAILY_BASIC', exec_date=exec_date, freq=freq)
            process_basic_download(ts_code, start_date, end_date, freq)
            if ts_code is None:
                set_event_completed('DAILY_BASIC',
                                    exec_date=exec_date,
                                    freq=freq)
            print("history has been downloaded successfully")
    else:
        process_basic_download(ts_code, start_date, end_date, freq)
def handle_jiuzhuan_cp(ts_code, freq='D'):
    exec_date = date.today()
    if ts_code is None:
        if ready2proceed('jiuzhuan_bs'):
            init_eventlog('MARK_CP',
                          exec_date=exec_date,
                          strategy_code='jiuzhuan_bs',
                          freq=freq)
            process_jiuzhuan_cp(
                ts_code,
                freq,
            )
            set_event_completed('MARK_CP',
                                exec_date=exec_date,
                                strategy_code='jiuzhuan_bs',
                                freq=freq)
    else:
        process_jiuzhuan_cp(
            ts_code,
            freq,
        )
Beispiel #6
0
def handle_stocks_pick(freq='D', force_run='0'):
    '''
    运行一遍下载,标记过程?
    '''
    try:
        exec_date = date.today()
        if exec_date.weekday() == 5:  # 周日推2天
            exec_date = exec_date - timedelta(days=1)
        elif exec_date.weekday == 6:
            exec_date = exec_date - timedelta(days=2)

        strategy_list = ['jiuzhuan_bs', 'dingdi', 'tupo_yali_b', 'diepo_zhicheng_s',
                         'wm_dingdi_bs', 'junxian25_bs', 'junxian60_bs', 'junxian200_bs']
        strategy_cp_list = {'jiuzhuan_bs': {'jiuzhuan_count_b', 'jiuzhuan_count_s'}, 'dingdi': {'dingbu_s', 'dibu_b'},
                            'tupo_yali_b': {'tupo_b'}, 'diepo_zhicheng_s': {'diepo_s'},  'wm_dingdi_bs': {'m_ding', 'w_di'},
                            'junxian25_bs': {'ma25_zhicheng', 'ma25_diepo', 'ma25_yali', 'ma25_tupo'},
                            'junxian60_bs': {'ma60_zhicheng', 'ma60_diepo', 'ma60_yali', 'ma60_tupo'},
                            'junxian200_bs': {'ma200_zhicheng', 'ma200_diepo', 'ma200_yali', 'ma200_tupo', }}

        evt_status = get_event_status('HIST_DOWNLOAD', exec_date)

        if evt_status == 1:  # 系统历史数据已经下载
            closest_trade_date = get_closest_trade_cal(exec_date)
            for strategy_code in strategy_list:
                evt_mk_status = get_event_status(
                    'MARK_CP', exec_date=exec_date, strategy_code=strategy_code, freq=freq)
                if evt_mk_status == 1:  # mark cp已经结束
                    evt_pk_status = get_event_status(
                        'PICK_STOCKS', strategy_code=strategy_code, exec_date=exec_date)
                    if evt_pk_status == 1:  # pick stock已经结束
                        print("pick stock is done already")
                    elif evt_pk_status == 0:  # pick stock 进行中
                        print("pick stock is still ongoing")
                    else:
                        init_eventlog('PICK_STOCKS',  exec_date=exec_date,
                                      strategy_code=strategy_code, freq=freq)
                        feed_marked_stock(strategy_code,
                                          strategy_cp_list[strategy_code], closest_trade_date, freq=freq)
                        set_event_completed('PICK_STOCKS', exec_date=exec_date,
                                            strategy_code=strategy_code, freq=freq)
                else:
                    print("previous marking is still ongoing or not run")
        else:
            if force_run == '1':
                closest_trade_date = get_closest_trade_cal(exec_date)

                for strategy_code in strategy_list:
                    print("picking stock started for " + strategy_code)
                    evt_mk_status = get_event_status(
                        'MARK_CP', exec_date=date.today(), strategy_code=strategy_code, freq=freq)
                    if evt_mk_status == 1:  # mark cp已经结束
                        init_eventlog('PICK_STOCKS',  exec_date=exec_date,
                                    strategy_code=strategy_code, freq=freq)
                        feed_marked_stock(strategy_code,
                                        strategy_cp_list[strategy_code], closest_trade_date, freq=freq)
                        set_event_completed('PICK_STOCKS', exec_date=exec_date,
                                            strategy_code=strategy_code, freq=freq)
                        print("picking stock finished for " + strategy_code)
            else:
                print("history has not yet downloade or still downloading")
    except Exception as e:
        print(e)
        set_event_exception('PICK_STOCKS', exec_date=exec_date,
                            strategy_code=strategy_code, freq=freq)