def test_api_get_last_traded_prices(self): prices = self.ev_loop.run_until_complete( CoinbaseProAPIOrderBookDataSource.get_last_traded_prices( ["BTC-USD", "LTC-USD"])) for key, value in prices.items(): print(f"{key} last_trade_price: {value}") self.assertGreater(prices["BTC-USD"], 1000) self.assertLess(prices["LTC-USD"], 1000)
def test_get_last_traded_prices(self, mock_api): alt_pair = "BTC-USDT" url = f"{CONSTANTS.REST_URL}{CONSTANTS.PRODUCTS_PATH_URL}/{self.trading_pair}/ticker" alt_url = f"{CONSTANTS.REST_URL}{CONSTANTS.PRODUCTS_PATH_URL}/{alt_pair}/ticker" price = 10.0 alt_price = 15.0 resp = self.get_products_ticker_response_mock(price=price) alt_resp = self.get_products_ticker_response_mock(price=alt_price) mock_api.get(url, body=json.dumps(resp)) mock_api.get(alt_url, body=json.dumps(alt_resp)) trading_pairs = [self.trading_pair, alt_pair] ret = self.async_run_with_timeout( coroutine=CoinbaseProAPIOrderBookDataSource.get_last_traded_prices(trading_pairs) ) self.assertEqual(ret[self.trading_pair], Decimal(resp["price"])) self.assertEqual(ret[alt_pair], Decimal(alt_resp["price"]))