diff --git a/hummingbot/connector/exchange/hitbtc/hitbtc_exchange.py b/hummingbot/connector/exchange/hitbtc/hitbtc_exchange.py index 9f6f83ec15..ba0ecadcb0 100644 --- a/hummingbot/connector/exchange/hitbtc/hitbtc_exchange.py +++ b/hummingbot/connector/exchange/hitbtc/hitbtc_exchange.py @@ -42,6 +42,7 @@ from hummingbot.connector.exchange.hitbtc.hitbtc_utils import ( convert_from_exchange_trading_pair, convert_to_exchange_trading_pair, + translate_asset, get_new_client_order_id, aiohttp_response_with_errors, retry_sleep_time, @@ -740,7 +741,7 @@ def _process_balance_message(self, balance_update): local_asset_names = set(self._account_balances.keys()) remote_asset_names = set() for account in balance_update: - asset_name = account["currency"] + asset_name = translate_asset(account["currency"]) self._account_available_balances[asset_name] = Decimal(str(account["available"])) self._account_balances[asset_name] = Decimal(str(account["reserved"])) + Decimal(str(account["available"])) remote_asset_names.add(asset_name) diff --git a/hummingbot/connector/exchange/hitbtc/hitbtc_utils.py b/hummingbot/connector/exchange/hitbtc/hitbtc_utils.py index 66a3de90cf..3f430227b0 100644 --- a/hummingbot/connector/exchange/hitbtc/hitbtc_utils.py +++ b/hummingbot/connector/exchange/hitbtc/hitbtc_utils.py @@ -57,18 +57,22 @@ def split_trading_pair(trading_pair: str) -> Optional[Tuple[str, str]]: return None -def translate_tokens(hb_trading_pair: str) -> str: - token_replacements = [ +def translate_asset(asset_name: str) -> str: + asset_replacements = [ ("USD", "USDT"), ] - tokens = hb_trading_pair.split('-') - for token_replacement in token_replacements: - for x in range(len(tokens)): - for inv in [0, 1]: - if tokens[x] == token_replacement[inv]: - tokens[x] = token_replacement[(0 if inv else 1)] - break - return '-'.join(tokens) + for asset_replacement in asset_replacements: + for inv in [0, 1]: + if asset_name == asset_replacement[inv]: + return asset_replacement[(0 if inv else 1)] + return asset_name + + +def translate_assets(hb_trading_pair: str) -> str: + assets = hb_trading_pair.split('-') + for x in range(len(assets)): + assets[x] = translate_asset(assets[x]) + return '-'.join(assets) def convert_from_exchange_trading_pair(ex_trading_pair: str) -> Optional[str]: @@ -77,12 +81,12 @@ def convert_from_exchange_trading_pair(ex_trading_pair: str) -> Optional[str]: return None # HitBTC uses uppercase (BTCUSDT) base_asset, quote_asset = split_trading_pair(ex_trading_pair) - return translate_tokens(f"{base_asset.upper()}-{quote_asset.upper()}") + return translate_assets(f"{base_asset.upper()}-{quote_asset.upper()}") def convert_to_exchange_trading_pair(hb_trading_pair: str) -> str: # HitBTC uses uppercase (BTCUSDT) - return translate_tokens(hb_trading_pair).replace("-", "").upper() + return translate_assets(hb_trading_pair).replace("-", "").upper() def get_new_client_order_id(is_buy: bool, trading_pair: str) -> str: diff --git a/test/connector/exchange/hitbtc/test_hitbtc_exchange.py b/test/connector/exchange/hitbtc/test_hitbtc_exchange.py index 0456f5a8a9..9baec3de55 100644 --- a/test/connector/exchange/hitbtc/test_hitbtc_exchange.py +++ b/test/connector/exchange/hitbtc/test_hitbtc_exchange.py @@ -54,7 +54,7 @@ class HitbtcExchangeUnitTest(unittest.TestCase): ] connector: HitbtcExchange event_logger: EventLogger - trading_pair = "BTC-USD" + trading_pair = "BTC-USDT" base_token, quote_token = trading_pair.split("-") stack: contextlib.ExitStack @@ -159,7 +159,7 @@ def test_buy_and_sell(self): self.assertEqual(order_id, order_completed_event.order_id) self.assertEqual(amount, order_completed_event.base_asset_amount) self.assertEqual("BTC", order_completed_event.base_asset) - self.assertEqual("USD", order_completed_event.quote_asset) + self.assertEqual("USDT", order_completed_event.quote_asset) self.assertAlmostEqual(base_amount_traded, order_completed_event.base_asset_amount) self.assertAlmostEqual(quote_amount_traded, order_completed_event.quote_asset_amount) self.assertGreater(order_completed_event.fee_amount, Decimal(0)) @@ -189,7 +189,7 @@ def test_buy_and_sell(self): self.assertEqual(order_id, order_completed_event.order_id) self.assertEqual(amount, order_completed_event.base_asset_amount) self.assertEqual("BTC", order_completed_event.base_asset) - self.assertEqual("USD", order_completed_event.quote_asset) + self.assertEqual("USDT", order_completed_event.quote_asset) self.assertAlmostEqual(base_amount_traded, order_completed_event.base_asset_amount) self.assertAlmostEqual(quote_amount_traded, order_completed_event.quote_asset_amount) self.assertGreater(order_completed_event.fee_amount, Decimal(0)) @@ -280,7 +280,7 @@ def test_order_quantized_values(self): # Make sure there's enough balance to make the limit orders. self.assertGreater(self.connector.get_balance("BTC"), Decimal("0.0005")) - self.assertGreater(self.connector.get_balance("USD"), Decimal("10")) + self.assertGreater(self.connector.get_balance("USDT"), Decimal("10")) # Intentionally set some prices with too many decimal places s.t. they # need to be quantized. Also, place them far away from the mid-price s.t. they won't diff --git a/test/connector/exchange/hitbtc/test_hitbtc_order_book_tracker.py b/test/connector/exchange/hitbtc/test_hitbtc_order_book_tracker.py index ae3778e7c9..bb929c3474 100755 --- a/test/connector/exchange/hitbtc/test_hitbtc_order_book_tracker.py +++ b/test/connector/exchange/hitbtc/test_hitbtc_order_book_tracker.py @@ -25,8 +25,8 @@ class HitbtcOrderBookTrackerUnitTest(unittest.TestCase): OrderBookEvent.TradeEvent ] trading_pairs: List[str] = [ - "BTC-USD", - "ETH-USD", + "BTC-USDT", + "ETH-USDT", ] @classmethod @@ -87,7 +87,7 @@ def test_tracker_integrity(self): # Wait 5 seconds to process some diffs. self.ev_loop.run_until_complete(asyncio.sleep(5.0)) order_books: Dict[str, OrderBook] = self.order_book_tracker.order_books - eth_usd: OrderBook = order_books["ETH-USD"] + eth_usd: OrderBook = order_books["ETH-USDT"] self.assertIsNot(eth_usd.last_diff_uid, 0) self.assertGreaterEqual(eth_usd.get_price_for_volume(True, 10).result_price, eth_usd.get_price(True)) @@ -96,8 +96,8 @@ def test_tracker_integrity(self): def test_api_get_last_traded_prices(self): prices = self.ev_loop.run_until_complete( - HitbtcAPIOrderBookDataSource.get_last_traded_prices(["BTC-USD", "LTC-BTC"])) + HitbtcAPIOrderBookDataSource.get_last_traded_prices(["BTC-USDT", "LTC-BTC"])) for key, value in prices.items(): print(f"{key} last_trade_price: {value}") - self.assertGreater(prices["BTC-USD"], 1000) + self.assertGreater(prices["BTC-USDT"], 1000) self.assertLess(prices["LTC-BTC"], 1) diff --git a/test/connector/exchange/hitbtc/test_hitbtc_user_stream_tracker.py b/test/connector/exchange/hitbtc/test_hitbtc_user_stream_tracker.py index 5c82f2372b..c53dcff7bc 100644 --- a/test/connector/exchange/hitbtc/test_hitbtc_user_stream_tracker.py +++ b/test/connector/exchange/hitbtc/test_hitbtc_user_stream_tracker.py @@ -24,7 +24,7 @@ class HitbtcUserStreamTrackerUnitTest(unittest.TestCase): @classmethod def setUpClass(cls): cls.ev_loop: asyncio.BaseEventLoop = asyncio.get_event_loop() - cls.trading_pairs = ["BTC-USD"] + cls.trading_pairs = ["BTC-USDT"] cls.user_stream_tracker: HitbtcUserStreamTracker = HitbtcUserStreamTracker( hitbtc_auth=HitbtcAuth(cls.api_key, cls.api_secret), trading_pairs=cls.trading_pairs)