Esempio n. 1
0
def request_kline(symbol, freq , **kwargs):
    query = kline.KlineQuery(symbol)
    log.debug('begin to request [%s]' % symbol)
    if query.isEmpty(freq):
        ## TODO request all
        info = composite.get_basic().info(symbol)
        if info is None:
            raise ValueError('%s not exist'% symbol)

        born = info['timeToMarket']
        return request_kline_core(symbol, start_date=trade_calendar.create_v2(born, freq), end_date = trade_calendar.last_trade_date(freq), freq = freq, **kwargs)
    else:
        db_start, db_end = query.duration(freq)
        if db_start is None and db_end is None:
            log.error('duration in db is error')
            raise RuntimeError('[%s] isn\'t exist, but duration ???' % symbol)

        last_date = trade_calendar.last_trade_date(freq)

        if trade_calendar.compare_v2(db_end, last_date, freq) == 0:
            ## TODO check suspend stock
            log.info('%s needn\'t update' % symbol)
            return 1
        elif trade_calendar.compare_v2(db_end, last_date, freq) < 0:
            db_end.shift(count = 1)
            return request_kline_core(symbol, db_end, last_date, freq, **kwargs)
        else:
            raise RuntimeError("????")
Esempio n. 2
0
def request_stock_basic(saveDB = True, **kwargs):
    basic = composite.get_basic()

    if basic.newest():
        log.info('stocks list needn\'t update')
        return basic

    if day_sync_time('request_stock_basic'):
        log.info('request stock basic')
        df = request.request_stock_basic()
        composite.update_stocks(df)
        return basic
    else:
        return None
Esempio n. 3
0
def test_stock_basic():
    basic = composite.get_basic()
    basic.clear()

    date1 = basic.date()
    assert date1 is None

    df1 = pd.read_csv('./debug/get_stock_basic_action.csv')
    date2 = trade_calendar.last_trade_date(util.FREQ_DAY)
    df1 = df1[df1['timeToMarket'] != 0]
    df1['timeToMarket'] = pd.to_datetime(df1['timeToMarket'].astype(str),
                                         format='%Y%m%d').astype(str)
    basic.save(df1)
    print(date2)
    print(basic.date())
    assert date2 == basic.date()
    assert basic.count() == 3499
    assert basic.info('000002')['name'] == '万 科A'
    assert basic.info('000002')['timeToMarket'] == '1991-01-29'
Esempio n. 4
0
def get_stock_list():
    return composite.get_basic().df().index.values
Esempio n. 5
0
def get_basic():
    return composite.get_basic()