Beispiel #1
0
def _synch(symbols):
    if not symbols:
        return ()

    print('stocks history synch:',
          lib.tty.bold + str(len(symbols)) + lib.tty.reset)

    failed = []

    progress = lib.util.progress.Progress(len(symbols))
    handler = lib.synch.handler.History()
    for symbol in symbols:
        if not handler.synch(symbol):
            failed.append(symbol)

        progress.update()

    if failed:
        lib.tty.error('failed symbols',
                      lib.tty.bold + ' '.join(failed) + lib.tty.reset)
Beispiel #2
0
Datei: meta.py Projekt: skhal/sat
def _synch(collection, meta):
    print(meta, 'meta synch:',
          lib.tty.bold + str(len(collection)) + lib.tty.reset)

    children = []
    failed = []

    progress = lib.util.progress.Progress(len(collection))
    handler = lib.synch.handler.Meta()
    for symbol in collection:
        if not handler.synch(symbol):
            failed.append(symbol)
        else:
            children.extend(handler.children)

        progress.update()

    if failed:
        lib.tty.error('failed symbols',
                      lib.tty.bold + ' '.join(failed) + lib.tty.reset)

    return children
Beispiel #3
0
def main(args):
    favorites = lib.favorite.util.load()

    # set indicators
    indicators = []
    if args.indicator:
        registered_indicators = lib.analysis.indicator.Registry.help()
        for label in args.indicator:
            label, *params = label.split(':', 1)
            pattern = lib.util.symbol.expand(label)
            ids = sorted(x for x in registered_indicators if pattern.match(x))
            if not ids:
                lib.tty.error("didn't understand the indicator label",
                              lib.tty.makebold(label))
                continue

            for id in ids:
                indicators.append("{0}:{1}".format(id, params[0])
                                  if params else id)

        if not indicators:
            return
    elif favorites and 'indicators' in favorites:
        indicators = favorites['indicators']
        print('using favorite indicators')
    else:
        lib.tty.error("indicators are not set... favorite indicators do not exist")
        return

    # set stocks
    if args.stock:
        symbols = args.stock
    elif favorites and 'stocks' in favorites:
        symbols = favorites['stocks']

        print('using favorite stocks')
    else:
        lib.tty.error('stocks are not set... favorite stocks do not exist')
        return

    # create pool of indicators
    toplevelindicators = []
    for label in indicators:
        try:
            indicator = lib.analysis.indicator.create(label)
            toplevelindicators.append(indicator)
        except ValueError as error:
            lib.tty.error(error)

    if not toplevelindicators:
        lib.tty.warning('no valid indicators were set')
        return

    print('symbols:', lib.tty.makebold(' '.join(symbols)))
    print()

    failed = []
    progress = lib.util.progress.Progress(len(symbols))
    for symbol in symbols:
        for indicator in toplevelindicators:
            indicator.reset()

        try:
            with lib.process.handler.HistoricData(
                        symbol, toplevelindicators) as data:
                data.process() 
                data.synch()

                '''
                data.process.verbose()
                print(lib.tty.makebold(symbol), data.process)
                print()
                print(lib.tty.makebold('pool'), data.pool.process)
                print()
                print(lib.tty.makebold('save'), data.save)
                print()
                print(lib.tty.makebold('synch'), data.synch)
                '''

        except RuntimeError as error:
            if args.debug:
                lib.tty.error(error)

            failed.append(symbol)

        progress.update()

    if failed:
        lib.tty.error("failed symbols:", lib.tty.makebold(' '.join(failed)))