def get_external_market_center_price(self, external_price_source): """ Get center price from an external market for current market pair. :param external_price_source: External market name :return: Center price as float """ self.log.debug('inside get_external_mcp, exchange: {} '.format( external_price_source)) market = self.market.get_string('/') self.log.debug('market: {} '.format(market)) price_feed = PriceFeed(external_price_source, market) price_feed.filter_symbols() center_price = price_feed.get_center_price(None) self.log.debug('PriceFeed: {}'.format(center_price)) if center_price is None: # Try USDT center_price = price_feed.get_center_price("USDT") self.log.debug( 'Substitute USD/USDT center price: {}'.format(center_price)) if center_price is None: # Try consolidated center_price = price_feed.get_consolidated_price() self.log.debug( 'Consolidated center price: {}'.format(center_price)) return center_price
def test_exchanges(): symbol = 'BTC/USD' exchanges = ['gecko', 'bitfinex', 'kraken', 'gdax', 'binance', 'waves'] for exchange in exchanges: price_feed = PriceFeed(exchange, symbol) price_feed.filter_symbols() center_price = price_feed.get_center_price(None) print("Center price: {}".format(center_price)) if center_price is None: # Try USDT center_price = price_feed.get_center_price('USDT') print("Try again, USD/USDT center price: {}".format(center_price))
def test_alternative_usd(): # Todo - Refactor price_feed to handle alt USD options. alternative_usd = ['USDT', 'USDC', 'TUSD', 'GUSD'] exchanges = ['bittrex', 'poloniex', 'gemini', 'bitfinex', 'kraken', 'binance', 'okex'] symbol = 'BTC/USD' # Replace with alt usd for exchange in exchanges: for alternative in alternative_usd: price_feed = PriceFeed(exchange, symbol) center_price = price_feed.get_center_price(None) if center_price: print('{} using alt: {} {}'.format(symbol, alternative, center_price)) else: center_price = price_feed.get_center_price(alternative) if center_price: print('{} using alt: {} {}'.format(symbol, alternative, center_price))