Beispiel #1
0
    def _setup_adapters(self, config: Dict[str, object], logger: LiveLogger) -> None:
        # Setup each data client
        for name, config in config.items():
            if name.startswith("ccxt-"):
                try:
                    import ccxtpro  # TODO: Find a better way of doing this
                except ImportError:
                    raise ImportError("ccxtpro is not installed, "
                                      "installation instructions can be found at https://ccxt.pro")

                client_cls = getattr(ccxtpro, name.partition('-')[2].lower())

                if name == "ccxt-binance":
                    data_client, exec_client = BinanceClientsFactory.create(
                        client_cls=client_cls,
                        config=config,
                        data_engine=self._data_engine,
                        exec_engine=self._exec_engine,
                        clock=self._clock,
                        logger=logger,
                    )
                elif name == "ccxt-bitmex":
                    data_client, exec_client = BitmexClientsFactory.create(
                        client_cls=client_cls,
                        config=config,
                        data_engine=self._data_engine,
                        exec_engine=self._exec_engine,
                        clock=self._clock,
                        logger=logger,
                    )
                else:
                    raise NotImplementedError(f"{name} not implemented in this version.")
                    # data_client, exec_client = CCXTClientsFactory.create(
                    #     client_cls=client_cls,
                    #     config=config,
                    #     data_engine=self._data_engine,
                    #     exec_engine=self._exec_engine,
                    #     clock=self._clock,
                    #     logger=logger,
                    # )
            elif name == "oanda":
                data_client = OandaDataClientFactory.create(
                    config=config,
                    data_engine=self._data_engine,
                    clock=self._clock,
                    logger=logger,
                )
                exec_client = None  # TODO: Implement
            else:
                self._log.error(f"No adapter available for `{name}`.")
                continue

            if data_client is not None:
                self._data_engine.register_client(data_client)

            if exec_client is not None:
                self._exec_engine.register_client(exec_client)
    def test_create(self):
        # Arrange
        config = {
            "api_token": "OANDA_API_TOKEN",    # value is the environment variable name
            "account_id": "OANDA_ACCOUNT_ID",  # value is the environment variable name
        }

        # Act
        client = OandaDataClientFactory.create(
            config=config,
            data_engine=self.data_engine,
            clock=self.clock,
            logger=self.logger,
        )

        # Assert
        self.assertEqual(OandaDataClient, type(client))