Пример #1
0
 def setup_order_workers(self):
     self._cxt.orders = FieldSet()
     venue_names = self._cfg.get("venues", {}).keys()
     instr_names = self._cfg.get("instruments", {})
     self.logger.info("CosineAlgo - instruments:")
     venue_instruments = 0
     for k in venue_names:
         self._cxt.orders[k] = {}
         venue = self._venues[k]
         instr_defs = venue.get_instrument_defs(instr_names)
         for instr in instr_names:
             instr_def = find_instrument(instr_defs, term=instr)
             if not instr_def: continue
             self.logger.info(
                 f"CosineAlgo -     Loading instrument: [{instr}]")
             instrument = CosineInstrument.load(self.instr_cache,
                                                **instr_def)
             self._cxt.instruments[instrument.name] = instrument
             order_worker = CosineOrderWorker(self._cfg.orders.ActiveDepth,
                                              instrument,
                                              venue,
                                              logger=self.logger)
             self._cxt.orders[k][instrument.symbol] = order_worker
             venue_instruments += 1
     if venue_instruments == 0:
         raise LookupError(
             "No instruments loaded for any of the provided venues")
Пример #2
0
 def _init_pricing_cache(self):
     instruments = self.instruments
     for instr_name in instruments:
         instr_feed_data = instruments.get(instr_name)
         instrument = self._cxt.find_instrument(term=instr_name)
         if not instrument: continue
         if instr_feed_data:
             instrument.symbology.attrs[self._feed_name] = instr_feed_data
         self._cache[instrument.name] = FieldSet(
             instrument=instrument,
             lastmarket=None,
             lasttraded=Decimal(0.0),
             midprice=Decimal(0.0),
             bid=Decimal(0.0),
             offer=Decimal(0.0),
             average=Decimal(0.0),
             openhour=Decimal(0.0),
             highhour=Decimal(0.0),
             lowhour=Decimal(0.0),
             openday=Decimal(0.0),
             highday=Decimal(0.0),
             lowday=Decimal(0.0),
             lasttradedvol=Decimal(0.0),
             lasttradedvolccy=Decimal(0.0),
             dayvol=Decimal(0.0),
             dayvolccy=Decimal(0.0)
         )
     self._snapshot_cache()
Пример #3
0
 def __init__(self, name, pool, cxt, logger=None, **kwargs):
     [setattr(self, k, kwargs[k]) for k in kwargs]
     self.logger = logger if logger else null_logger
     self._feed_name = name
     self._pool = pool
     self._cfg = self._pool.cfg
     self._cxt = cxt
     self._cache = {}
     self._worker = None
     self._events = FieldSet()
     self._events.OnTick = CosineEventSlot()
Пример #4
0
 def __init__(self, cmdline_args, logger=None):
     super().__init__()
     self._cfg = None
     self._cxt = None
     self._worker_pool = None
     self._venues = None
     self._base_cfg_file = None
     self._environment = None
     self._appname = None
     self._cfg_file = None
     self.logger = None
     self._args = cmdline_args
     self.instr_cache = FieldSet()
     self.init_logging(logger=logger)
Пример #5
0
 def setup_pricing_feeds(self):
     self._cxt.feeds = FieldSet()
     feed_defs = self._cfg.get("feeds", {})
     feed_names = feed_defs.keys()
     feeds = collate_feeds(feed_names)
     self.logger.info("CosineAlgo - feeds:")
     for k in feeds:
         self.logger.info(f"CosineAlgo -     Loading feed: [{k}]")
         PricingFeedClass = feeds[k]
         self._cxt.feeds[k] = PricingFeedClass(k,
                                               self._worker_pool,
                                               self._cxt,
                                               logger=self.logger,
                                               **feed_defs[k])
         self._cxt.feeds[k].setup()
Пример #6
0
 def setup_pricers(self):
     self._cxt.pricers = FieldSet()
     pricer_names = self._cfg.get("pricers",
                                  {}).get("Default",
                                          "nullpricer").split(',')
     pricer_defs = self._cfg.get("pricers", {}).get("settings", {})
     pricers = collate_pricers(pricer_names)
     self._cxt.pricer_seq = pricer_names
     self.logger.info("CosineAlgo - pricers:")
     for k in pricers:
         self.logger.info(f"CosineAlgo -     Loading pricer: [{k}]")
         PricerClass = pricers[k]
         self._cxt.pricers[k] = PricerClass(k,
                                            self._worker_pool,
                                            self._cxt,
                                            logger=self.logger,
                                            **pricer_defs[k])
         self._cxt.pricers[k].setup()
Пример #7
0
    def _setup(self):

        # establish the connection...
        self.logger.info(
            f"CryptoCompareSocketIOFeed - Establishing connection: {self.endpoint} ({self.port})"
        )
        self._socketio = SocketIO(self.endpoint, port=self.port)
        self.logger.info(f"CryptoCompareSocketIOFeed - Connection established")

        # subscribe for all instruments...
        subs = []
        for n in self._cache:
            instrument = self._cache[n].instrument
            if not isinstance(instrument, CosinePairInstrument): continue

            # handle any ticker remapping required for this pricing feed...
            feed_data = instrument.symbology.attrs.get(self._feed_name, {})
            ticker = feed_data.get('Ticker', instrument.asset.symbol)
            ccy_ticker = feed_data.get('TickerCCY', instrument.ccy.symbol)
            ticker_pair = ticker + '/' + ccy_ticker
            self._ticker_map[ticker_pair] = instrument

            # handle any triangulation via a base currency required...
            ccy_base = feed_data.get('BaseCCY')
            if ccy_base:
                ticker_base_pair = ticker + '/' + ccy_base
                self._triangulators[ticker_base_pair] = FieldSet(
                    base=ccy_base,
                    origin=ticker,
                    ccy=ccy_ticker,
                    instr=instrument)
                ccy_ticker = ccy_base

            # now add the ticker for subscription...
            self.logger.info(
                f"CryptoCompareSocketIOFeed - Subscribing for instrument: {instrument.symbol} (via {ticker}/{ccy_ticker})"
            )
            subs.append('5~CCCAGG~{0}~{1}'.format(ticker, ccy_ticker))

        self._socketio.emit('SubAdd', {"subs": subs})
        self._socketio.on('m', self._on_sio_tick)
Пример #8
0
    def setup(self):
        # initialise the HTTP API
        self.trade_api = BlockExTradeApi(
            self.Username,
            self.Password,
            self.APIDomain,
            self.APIID
        )

        # initialise the streaming API
        if self.ConnectSignalR:
            self._setup_signalr_stream()

        # bootstrap the API with some more functions:
        self.trade_api.get_active_currencies = get_active_currencies.__get__(self.trade_api, BlockExTradeApi)
        self.trade_api.get_quote_currencies = get_quote_currencies.__get__(self.trade_api, BlockExTradeApi)

        # retrieve all the currencies supported...
        build_ccy = lambda ccy: FieldSet(
            venue_id=ccy["id"],
            name=ccy["isoCode"],
            symbol=ccy["isoCode"],
            category="crypto" if ccy["type"] is not "fiat" else "fiat",
            type=ccy["type"],
            precision=ccy["precision"],
            symbology={
                "name": ccy["currencyName"],
                "symbol": ccy["isoCode"],
                "symbolmark": ccy["symbol"],
                "iso": ccy["isoCode"],
                "label": ccy.get("description", ccy["currencyName"]),
            }
        )
        self._currencies = {
            ccy["id"]: build_ccy(ccy)
            for ccy in (self.trade_api.get_active_currencies() + self.trade_api.get_quote_currencies())
        }

        # retrieve all the instruments supported...
        self._get_instruments()
Пример #9
0
    def _get_instruments(self):
        trader_instruments = self.trade_api.get_trader_instruments()
        self._instruments = [FieldSet(
            cls="CosinePairInstrument",

            asset=self._currencies[bem_instr["baseCurrencyID"]],
            quote_ccy=self._currencies[bem_instr["quoteCurrencyID"]],

            name=bem_instr["name"],
            symbol=bem_instr["name"],
            venue_id=bem_instr["id"],

            category="crypto",
            type="pair",
            precision=self._currencies[bem_instr["quoteCurrencyID"]].precision,
            symbology={
                "symbol": bem_instr["name"],
                "iso": self._currencies[bem_instr["baseCurrencyID"]]["symbol"] + "/" + self._currencies[bem_instr["quoteCurrencyID"]]["symbol"],
                "label": self._currencies[bem_instr["baseCurrencyID"]].symbology["label"],
                "venue_asset_id": bem_instr["baseCurrencyID"],
                "venue_ccy_id": bem_instr["quoteCurrencyID"],
            }
        ) for bem_instr in trader_instruments]
Пример #10
0
 def init_queue(self):
     self._events = Queue()
     self._slots = FieldSet()