Example #1
0
    def run(self):
        logger.info("starting ATS")

        self.app_context.start()
        self.strategy.start(self.app_context)

        logger.info("ATS started, presss Ctrl-C to stop")
Example #2
0
 def on_bar(self, bar):
     if self.buy_order is None and self.sma_fast.now('value') > self.sma_slow.now('value'):
         self.buy_order = self.market_order(inst_id=bar.inst_id, action=Buy, qty=self.qty)
         logger.info("%s,B,%s,%s,%.2f,%.2f,%.2f" % (
             bar.timestamp, self.buy_order.cl_id, self.buy_order.cl_ord_id, bar.close, self.sma_fast.now('value'),
             self.sma_slow.now('value')))
     elif self.buy_order is not None and self.sma_fast.now('value') < self.sma_slow.now('value'):
         sell_order = self.market_order(inst_id=bar.inst_id, action=Sell, qty=self.qty)
         logger.info("%s,S,%s,%s,%.2f,%.2f,%.2f" % (
             bar.timestamp, sell_order.cl_id, sell_order.cl_ord_id, bar.close, self.sma_fast.now('value'),
             self.sma_slow.now('value')))
         self.buy_order = None
Example #3
0
def import_inst_from_ib(broker,
                        symbol,
                        sec_type='STK',
                        exchange=None,
                        currency=None):
    try:
        result = AsyncResult()
        logger.info("importing symbol %s" % symbol)
        broker.reqContractDetails(symbol=symbol,
                                  sec_type=sec_type,
                                  exchange=exchange,
                                  currency=currency,
                                  callback=result)
        # broker.reqScannerSubscription(inst_type='STK', location_code='STK.US', scan_code='TOP_PERC_GAIN', above_vol=1000000, callback=callback)

        logger.info("done %s %s" % (symbol, result.get(timeout=3)))
    except Exception as e:
        logger.error("faile to import %s", symbol, e)
    def on_bar(self, bar):
        ratio = self.vix_close.now('value') / self.vxv_close.now('close')
        # what is order is not filled and there is signal again?
        if self.order is None:
            # long XIV at the close when VIX index closed below the VXV index
            # long XIV when ratio < 0.92
            if ratio < self.threshold[0]:
                logger.info("%s,B,%.2f" % (bar.timestamp, bar.close))
                if bar.inst_id == self.xiv.id():
                    self.order = self.market_order(inst_id=bar.inst_id,
                                                   action=Buy,
                                                   qty=self.qty)

            # long VXX when ratio > 1.08
            elif ratio > self.threshold[1]:
                logger.info("%s,B,%.2f" % (bar.timestamp, bar.close))
                if bar.inst_id == self.vxx.id():
                    self.order = self.market_order(inst_id=bar.inst_id,
                                                   action=Buy,
                                                   qty=self.qty)
    def run(self):
        logger.info("starting BackTest")

        self.app_context.start()
        self.portfolio = self.app_context.portf_mgr.get_or_new_portfolio(
            self.config.get_app_config("portfolioId"),
            self.config.get_app_config("portfolioInitialcash"))
        self.strategy = self.app_context.stg_mgr.get_or_new_stg(
            self.config.get_app_config("stgId"),
            self.config.get_app_config("stgCls"))

        self.initial_result = self.portfolio.get_result()
        self.app_context.add_startable(self.portfolio)
        self.portfolio.start(self.app_context)
        self.strategy.start(self.app_context)

        result = self.portfolio.get_result()
        print("Initial:", self.initial_result)
        print("Final:", result)
        if self.is_plot:
            self.plot()
    def run(self):
        logger.info("importing data")
        self.app_context.start()
        config = self.app_context.config

        feed = self.app_context.provider_mgr.get(
            config.get_app_config("feedId"))
        feed.start(self.app_context)
        instruments = self.app_context.ref_data_mgr.get_insts_by_ids(
            config.get_app_config("instrumentIds"))

        for sub_req in build_subscription_requests(
                feed.id(), instruments,
                config.get_app_config("subscriptionTypes"),
                config.get_app_config("fromDate"),
                config.get_app_config("toDate")):
            feed.subscribe_mktdata(sub_req)

        logger.info("ATS started, presss Ctrl-C to stop")
        for i in range(1, 1000):
            time.sleep(1)
            logger.info(".")
Example #7
0
 def save(self, obj):
     logger.info("[%s] saving %s" % (self.__class__.__name__, obj))
     id = get_model_id(obj)
     packed_data = protobuf_to_dict(obj)
     t = type(obj)
     self.db_map[t].update({'_id': id}, packed_data, upsert=True)
Example #8
0
 def log(self, item) -> None:
     logger.info(model_to_str(item))
     self.count[type(item)] += 1
     self.last_item[type(item)] = item
Example #9
0
 def on_new_ord_req(self, order):
     logger.info("[%s] %s" % (self.__class__.__name__, order))
     return order
Example #10
0
 def _start(self, app_context: Context) -> None:
     self.__server = zerorpc.Server(self)
     self.__server.bind(self.__address)
     logger.info("starting OMS")
     self.__server.run()