def test_create_paper_trade_market_for_connector_using_generic_tracker( self): paper_exchange = create_paper_trade_market( exchange_name="binance", trading_pairs=["COINALPHA-HBOT"]) self.assertEqual(BinanceAPIOrderBookDataSource, type(paper_exchange.order_book_tracker.data_source)) paper_exchange = create_paper_trade_market( exchange_name="kucoin", trading_pairs=["COINALPHA-HBOT"]) self.assertEqual(KucoinAPIOrderBookDataSource, type(paper_exchange.order_book_tracker.data_source))
def _initialize_markets(self, market_names: List[Tuple[str, List[str]]]): # aggregate trading_pairs if there are duplicate markets for market_name, trading_pairs in market_names: if market_name not in self.market_trading_pairs_map: self.market_trading_pairs_map[market_name] = [] for hb_trading_pair in trading_pairs: self.market_trading_pairs_map[market_name].append( hb_trading_pair) for connector_name, trading_pairs in self.market_trading_pairs_map.items( ): conn_setting = CONNECTOR_SETTINGS[connector_name] if global_config_map.get( "paper_trade_enabled" ).value and conn_setting.type == ConnectorType.Exchange: try: connector = create_paper_trade_market( connector_name, trading_pairs) except Exception: raise paper_trade_account_balance = global_config_map.get( "paper_trade_account_balance").value for asset, balance in paper_trade_account_balance.items(): connector.set_balance(asset, balance) else: Security.update_config_map(global_config_map) keys = { key: config.value for key, config in global_config_map.items() if key in conn_setting.config_keys } init_params = conn_setting.conn_init_parameters(keys) init_params.update(trading_pairs=trading_pairs, trading_required=self._trading_required) if conn_setting.use_ethereum_wallet: ethereum_rpc_url = global_config_map.get( "ethereum_rpc_url").value # Todo: Hard coded this execption for now until we figure out how to handle all ethereum connectors. if connector_name in [ "balancer", "uniswap", "perpetual_finance" ]: private_key = get_eth_wallet_private_key() init_params.update(wallet_private_key=private_key, ethereum_rpc_url=ethereum_rpc_url) else: assert self.wallet is not None init_params.update(wallet=self.wallet, ethereum_rpc_url=ethereum_rpc_url) connector_class = get_connector_class(connector_name) connector = connector_class(**init_params) self.markets[connector_name] = connector self.markets_recorder = MarketsRecorder( self.trade_fill_db, list(self.markets.values()), self.strategy_file_name, self.strategy_name, ) self.markets_recorder.start()
def _initialize_markets(self, market_names: List[Tuple[str, List[str]]]): ethereum_rpc_url = global_config_map.get("ethereum_rpc_url").value # aggregate trading_pairs if there are duplicate markets market_trading_pairs_map = {} for market_name, trading_pairs in market_names: if market_name not in market_trading_pairs_map: market_trading_pairs_map[market_name] = [] for hb_trading_pair in trading_pairs: market_trading_pairs_map[market_name].append(hb_trading_pair) for connector_name, trading_pairs in market_trading_pairs_map.items(): if global_config_map.get("paper_trade_enabled").value: try: connector = create_paper_trade_market( market_name, trading_pairs) except Exception: raise paper_trade_account_balance = global_config_map.get( "paper_trade_account_balance").value for asset, balance in paper_trade_account_balance.items(): connector.set_balance(asset, balance) elif connector_name in CEXES or connector_name in DERIVATIVES: keys = dict((key, value.value) for key, value in dict( filter(lambda item: connector_name in item[0], global_config_map.items())).items()) connector_class = get_connector_class(connector_name) connector = connector_class( **keys, trading_pairs=trading_pairs, trading_required=self._trading_required) elif connector_name in DEXES: assert self.wallet is not None keys = dict((key, value.value) for key, value in dict( filter(lambda item: connector_name in item[0], global_config_map.items())).items()) connector_class = get_connector_class(connector_name) connector = connector_class( **keys, wallet=self.wallet, ethereum_rpc_url=ethereum_rpc_url, trading_pairs=trading_pairs, trading_required=self._trading_required) # TO-DO for DEXes: rename all extra argument to match key in global_config_map else: raise ValueError( f"Connector name {connector_name} is invalid.") self.markets[connector_name] = connector self.markets_recorder = MarketsRecorder( self.trade_fill_db, list(self.markets.values()), self.strategy_file_name, self.strategy_name, ) self.markets_recorder.start()
def _initialize_markets(self, market_names: List[Tuple[str, List[str]]]): # aggregate trading_pairs if there are duplicate markets for market_name, trading_pairs in market_names: if market_name not in self.market_trading_pairs_map: self.market_trading_pairs_map[market_name] = [] for hb_trading_pair in trading_pairs: self.market_trading_pairs_map[market_name].append(hb_trading_pair) for connector_name, trading_pairs in self.market_trading_pairs_map.items(): conn_setting = AllConnectorSettings.get_connector_settings()[connector_name] if connector_name.endswith("paper_trade") and conn_setting.type == ConnectorType.Exchange: connector = create_paper_trade_market(conn_setting.parent_name, self.client_config_map, trading_pairs) paper_trade_account_balance = self.client_config_map.paper_trade.paper_trade_account_balance if paper_trade_account_balance is not None: for asset, balance in paper_trade_account_balance.items(): connector.set_balance(asset, balance) else: keys = Security.api_keys(connector_name) init_params = conn_setting.conn_init_parameters(keys) init_params.update(trading_pairs=trading_pairs, trading_required=self._trading_required) connector_class = get_connector_class(connector_name) read_only_config = ReadOnlyClientConfigAdapter.lock_config(self.client_config_map) connector = connector_class(read_only_config, **init_params) self.markets[connector_name] = connector self.markets_recorder = MarketsRecorder( self.trade_fill_db, list(self.markets.values()), self.strategy_file_name, self.strategy_name, ) self.markets_recorder.start()
def _initialize_markets(self, market_names: List[Tuple[str, List[str]]]): ethereum_rpc_url = global_config_map.get("ethereum_rpc_url").value # aggregate trading_pairs if there are duplicate markets market_trading_pairs_map = {} for market_name, trading_pairs in market_names: if market_name not in market_trading_pairs_map: market_trading_pairs_map[market_name] = [] for hb_trading_pair in trading_pairs: market_trading_pairs_map[market_name].append(hb_trading_pair) for market_name, trading_pairs in market_trading_pairs_map.items(): if global_config_map.get("paper_trade_enabled").value: try: market = create_paper_trade_market(market_name, trading_pairs) except Exception: raise paper_trade_account_balance = global_config_map.get( "paper_trade_account_balance").value for asset, balance in paper_trade_account_balance.items(): market.set_balance(asset, balance) elif market_name == "binance": binance_api_key = global_config_map.get( "binance_api_key").value binance_api_secret = global_config_map.get( "binance_api_secret").value market = BinanceMarket(binance_api_key, binance_api_secret, trading_pairs=trading_pairs, trading_required=self._trading_required) elif market_name == "radar_relay": assert self.wallet is not None market = RadarRelayMarket( wallet=self.wallet, ethereum_rpc_url=ethereum_rpc_url, trading_pairs=trading_pairs, trading_required=self._trading_required, ) elif market_name == "bamboo_relay": assert self.wallet is not None use_coordinator = global_config_map.get( "bamboo_relay_use_coordinator").value pre_emptive_soft_cancels = global_config_map.get( "bamboo_relay_pre_emptive_soft_cancels").value market = BambooRelayMarket( wallet=self.wallet, ethereum_rpc_url=ethereum_rpc_url, trading_pairs=trading_pairs, use_coordinator=use_coordinator, pre_emptive_soft_cancels=pre_emptive_soft_cancels, trading_required=self._trading_required, ) elif market_name == "coinbase_pro": coinbase_pro_api_key = global_config_map.get( "coinbase_pro_api_key").value coinbase_pro_secret_key = global_config_map.get( "coinbase_pro_secret_key").value coinbase_pro_passphrase = global_config_map.get( "coinbase_pro_passphrase").value market = CoinbaseProMarket( coinbase_pro_api_key, coinbase_pro_secret_key, coinbase_pro_passphrase, trading_pairs=trading_pairs, trading_required=self._trading_required) elif market_name == "huobi": huobi_api_key = global_config_map.get("huobi_api_key").value huobi_secret_key = global_config_map.get( "huobi_secret_key").value market = HuobiMarket(huobi_api_key, huobi_secret_key, trading_pairs=trading_pairs, trading_required=self._trading_required) elif market_name == "liquid": liquid_api_key = global_config_map.get("liquid_api_key").value liquid_secret_key = global_config_map.get( "liquid_secret_key").value market = LiquidMarket(liquid_api_key, liquid_secret_key, trading_pairs=trading_pairs, trading_required=self._trading_required) elif market_name == "dolomite": assert self.wallet is not None is_test_net: bool = global_config_map.get( "ethereum_chain_name").value == "DOLOMITE_TEST" market = DolomiteMarket( wallet=self.wallet, ethereum_rpc_url=ethereum_rpc_url, trading_pairs=trading_pairs, isTestNet=is_test_net, trading_required=self._trading_required, ) elif market_name == "bittrex": bittrex_api_key = global_config_map.get( "bittrex_api_key").value bittrex_secret_key = global_config_map.get( "bittrex_secret_key").value market = BittrexMarket(bittrex_api_key, bittrex_secret_key, trading_pairs=trading_pairs, trading_required=self._trading_required) elif market_name == "kucoin": kucoin_api_key = global_config_map.get("kucoin_api_key").value kucoin_secret_key = global_config_map.get( "kucoin_secret_key").value kucoin_passphrase = global_config_map.get( "kucoin_passphrase").value market = KucoinMarket(kucoin_api_key, kucoin_passphrase, kucoin_secret_key, trading_pairs=trading_pairs, trading_required=self._trading_required) elif market_name == "eterbase": eterbase_api_key = global_config_map.get( "eterbase_api_key").value eterbase_secret_key = global_config_map.get( "eterbase_secret_key").value eterbase_account = global_config_map.get( "eterbase_account").value market = EterbaseMarket( eterbase_api_key, eterbase_secret_key, trading_pairs=trading_pairs, trading_required=self._trading_required, eterbase_account=eterbase_account) elif market_name == "kraken": kraken_api_key = global_config_map.get("kraken_api_key").value kraken_secret_key = global_config_map.get( "kraken_secret_key").value market = KrakenMarket(kraken_api_key, kraken_secret_key, trading_pairs=trading_pairs, trading_required=self._trading_required) elif market_name == "crypto_com": api_key = global_config_map.get("crypto_com_api_key").value secret_key = global_config_map.get( "crypto_com_secret_key").value market = CryptoComExchange( api_key, secret_key, trading_pairs=trading_pairs, trading_required=self._trading_required) else: raise ValueError(f"Market name {market_name} is invalid.") self.markets[market_name]: ExchangeBase = market self.markets_recorder = MarketsRecorder( self.trade_fill_db, list(self.markets.values()), self.strategy_file_name, self.strategy_name, ) self.markets_recorder.start()