コード例 #1
0
ファイル: track_favorites.py プロジェクト: stjordanis/scidb-1
def run_query(symlist):
    '''Run interesting iquery...'''
    # Extra credit: figure out a way to do a single query for entire symlist.
    for sym in symlist:
        sym_id = sym_to_id(sym)
        query = '''aggregate(
                     apply(
                       slice({0}, symbolId, {1}),
                       fprice, price/pow(10,scale),
                       trade, 1),
                     min(symbol) as Symbol,
                     min(fprice) as Low,
                     max(fprice) as High,
                     sum(trade)  as NumTrades,
                     sum(volume) as Volume)'''.format(DEFAULT_ARRAY, sym_id)
        os.system('iquery -aq "%s"' % query)
コード例 #2
0
ファイル: track_favorites.py プロジェクト: Goon83/scidb
def run_query(symlist):
    '''Run interesting iquery...'''
    # Extra credit: figure out a way to do a single query for entire symlist.
    for sym in symlist:
        sym_id = sym_to_id(sym)
        query = '''aggregate(
                     apply(
                       slice({0}, symbolId, {1}),
                       fprice, price/pow(10,scale),
                       trade, 1),
                     min(symbol) as Symbol,
                     min(fprice) as Low,
                     max(fprice) as High,
                     sum(trade)  as NumTrades,
                     sum(volume) as Volume)'''.format(
            DEFAULT_ARRAY,
            sym_id)
        os.system('iquery -aq "%s"' % query)
コード例 #3
0
ファイル: nyse_feeder.py プロジェクト: jonghunDB/SciDB
def feed_file(F):
    '''Emit trade data at a rate linearly scaled to the actual data rate.

    When the --scale=S option is specified, an n-millisecond interval
    between trades becomes an (S*n)-millisecond interval.
    '''
    SENDTIME = None         # Row index of SendTime field
    MSM_0 = None            # "Millis since midnight" of first trade
    START_TIME = None       # Actual program start time in millis
    prev_msm = None         # MSM of previous trade
    lineno = 0

    # First line provides field names, not data.
    for i, field_name in enumerate(F.readline().strip().split('|')):
        index_of[field_name] = i
    SENDTIME = index_of['SendTime']
    debug("# SendTime in column", SENDTIME)

    # Delay data lines appropriately based on scaling factor.
    for line in F:

        lineno += 1
        if (_args.max_trades > 0 and lineno > _args.max_trades):
            return

        # We need to split the pipe-delimited input to get the
        # inter-transaction delays.
        row = line.strip().split('|')

        # We decorate the row with a computed symbol_id, since (for
        # now) SciDB does not allow string-valued dimensions, and we'd
        # like to have a "by stock" dimension.
        row.append(str(sym_to_id(row[index_of['Symbol']])))

        # We replace SendTime with strictly increasing "microseconds
        # since midnight", see above.
        msm = int(row[SENDTIME])
        row[SENDTIME] = str(usecs_since_midnite(prev_msm, msm))
        prev_msm = msm

        # First trade: set time baseline values and print immediately.
        if START_TIME is None:
            START_TIME = now_millis()
            MSM_0 = msm
            prt(row)
            continue

        if _args.no_delay:
            prt(row)
        else:
            # How many logical msecs along in the trading day is this trade?
            logical_time = msm - MSM_0

            # Scaling that, how long would that be since actual program start?
            ready_time = (logical_time * _args.scale) + START_TIME

            # Wait 'til then if we need to, then print the line.
            now = now_millis()
            if ready_time > now:
                # It's a float, so sleeping at millisecond resolution.
                snooze_secs = float(ready_time - now) / 1000
                debug("# sleep({0})".format(snooze_secs))
                time.sleep(snooze_secs)
            prt(row)
コード例 #4
0
ファイル: nyse_feeder.py プロジェクト: Goon83/scidb
def feed_file(F):
    '''Emit trade data at a rate linearly scaled to the actual data rate.

    When the --scale=S option is specified, an n-millisecond interval
    between trades becomes an (S*n)-millisecond interval.
    '''
    SENDTIME = None         # Row index of SendTime field
    MSM_0 = None            # "Millis since midnight" of first trade
    START_TIME = None       # Actual program start time in millis
    prev_msm = None         # MSM of previous trade
    lineno = 0

    # First line provides field names, not data.
    for i, field_name in enumerate(F.readline().strip().split('|')):
        index_of[field_name] = i
    SENDTIME = index_of['SendTime']
    debug("# SendTime in column", SENDTIME)

    # Delay data lines appropriately based on scaling factor.
    for line in F:

        lineno += 1
        if (_args.max_trades > 0 and lineno > _args.max_trades):
            return

        # We need to split the pipe-delimited input to get the
        # inter-transaction delays.
        row = line.strip().split('|')

        # We decorate the row with a computed symbol_id, since (for
        # now) SciDB does not allow string-valued dimensions, and we'd
        # like to have a "by stock" dimension.
        row.append(str(sym_to_id(row[index_of['Symbol']])))

        # We replace SendTime with strictly increasing "microseconds
        # since midnight", see above.
        msm = int(row[SENDTIME])
        row[SENDTIME] = str(usecs_since_midnite(prev_msm, msm))
        prev_msm = msm

        # First trade: set time baseline values and print immediately.
        if START_TIME is None:
            START_TIME = now_millis()
            MSM_0 = msm
            prt(row)
            continue

        if _args.no_delay:
            prt(row)
        else:
            # How many logical msecs along in the trading day is this trade?
            logical_time = msm - MSM_0

            # Scaling that, how long would that be since actual program start?
            ready_time = (logical_time * _args.scale) + START_TIME

            # Wait 'til then if we need to, then print the line.
            now = now_millis()
            if ready_time > now:
                # It's a float, so sleeping at millisecond resolution.
                snooze_secs = float(ready_time - now) / 1000
                debug("# sleep({0})".format(snooze_secs))
                time.sleep(snooze_secs)
            prt(row)