def repackage_ask(bbo): return {'type': 'tickPrice', 'symbol': bbo['symbol'], 'field': 2, 'price': bbo['ask_px'], 'ts': bbo['ts']} if __name__ == '__main__': parser = argparse.ArgumentParser(description='backtest') parser.add_argument('--config', type=argparse.FileType('r')) parser.add_argument('--bbos') parser.add_argument('--trds') args = parser.parse_args() config = json.load(args.config) log = Logger('backtest') log.operation({'config': config}) watch_threshold = config['watch_threshold'] watch_duration = config['watch_duration'] slowdown_threshold = config['slowdown_threshold'] slowdown_duration = config['slowdown_duration'] strategy = Strategy(watch_threshold, watch_duration, slowdown_threshold, slowdown_duration) with io.TextIOWrapper(gzip.open(args.bbos, 'r')) as fh: fh.readline() # skip header bbos = collections.deque((process_bbo(line) for line in fh)) with io.TextIOWrapper(gzip.open(args.trds, 'r')) as fh: fh.readline() # skip header
host = "54.197.15.42" port = 7496 connection.eConnect(host, port, 1) subscription = ScannerSubscription() subscription.numberOfRows(100) subscription.instrument('STK') subscription.locationCode('STK.US') subscription.scanCode('TOP_PERC_GAIN') subscription.abovePrice(1.0) subscription.aboveVolume(1) subscription.marketCapBelow(1000000000.0) ticker_id = 10 log.operation('Requesting subscription') connection.reqScannerSubscription(ticker_id, subscription) while True: msg = msgs.get() if msg['type'] == 'scannerDataEnd': log.operation('Received end scanner data end signal') break elif msg['type'] == 'scannerData': log.data(msg) else: log.misc(msg) log.operation('Disconnecting') connection.cancelScannerSubscription(ticker_id)