Ejemplo n.º 1
0
def bundle(symbol, action, market, output, extension):
    '''
    批量下载行情数据
    :return:
    '''
    client = Quotes.factory(market=market)
    symbol = symbol.replace(',', ',').strip(',').split(',')

    for code in symbol:
        try:
            if action == 'daily':
                frequency = 9
            elif action == 'minute':
                frequency = 8
            elif action == 'fzline':
                frequency = 0
            else:
                frequency = 9

            feed = getattr(client, 'bars')(symbol=code, frequency=frequency)
            to_file(feed, os.path.join(output, '{}.{}'.format(
                code, extension))) if output else None
            print('下载完成 {}'.format(code))
        except Exception as e:
            raise e

    print('[√] 下载文件到 "{}"'.format(os.path.realpath(output)))
Ejemplo n.º 2
0
def reader(symbol, action, market, tdxdir, output):
    client = Reader.factory(market=market, tdxdir=tdxdir)

    try:
        feed = getattr(client, action)(symbol=symbol)
        to_file(feed, output) if output else None
        print(feed)
    except Exception as e:
        raise e
Ejemplo n.º 3
0
def affair(parse, files, fetch, downdir, output, verbose):
    if verbose:
        logging.basicConfig(level=logging.DEBUG)

    result = Affair.files()

    if not fetch and not parse:
        t = PrettyTable(["filename", "filesize", "hash"])
        t.align["filename"] = "l"
        t.align["filesize"] = "l"
        t.align["hash"] = "l"
        t.padding_width = 0

        for x in result:
            t.add_row([x['filename'], x['filesize'], x['hash']])

        print(t)

    if fetch:
        if fetch == 'all':
            feed = Affair.fetch(downdir=downdir)
            to_file(feed, output) if output else None
        else:
            Affair.fetch(downdir=downdir,
                         filename=fetch.strip('.zip') + '.zip')

    if parse:
        files = [x['filename'] for x in result]

        if parse in files:
            if not os.path.exists(os.path.join(downdir, parse)):
                Affair.fetch(downdir=downdir,
                             filename=parse.strip('.zip') + '.zip')

            feed = Affair.parse(downdir=downdir,
                                filename=parse.strip('.zip') + '.zip')

            if output:
                to_file(feed, output)
            else:
                print(feed)
        else:
            logger.erro('cannot find file.')
Ejemplo n.º 4
0
def quotes(symbol, action, market, output):
    client = Quotes.factory(market=market, multithread=True, heartbeat=True)

    try:
        action = 'bars' if 'daily' else action
        if action == 'daily':
            frequency = 9
        elif action == 'minute':
            frequency = 8
        elif action == 'fzline':
            frequency = 0
        else:
            frequency = 9

        feed = getattr(client, 'bars')(symbol=symbol, frequency=frequency)
        to_file(feed, output) if output else None
        print(feed)
    except Exception as e:
        raise e