Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor/ rename Huobi to HTX #6796

Merged
merged 24 commits into from Feb 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -110,4 +110,4 @@ To have your exchange connector or other pull request merged into the codebase,
## Legal

* **License**: Hummingbot is licensed under [Apache 2.0](./LICENSE).
* **Data collection**: read important information regarding [Hummingbot Data Collection](./DATA_COLLECTION.md).
* **Data collection**: read important information regarding [Hummingbot Data Collection](./DATA_COLLECTION.md).
6 changes: 3 additions & 3 deletions conf/__init__.py
Expand Up @@ -54,9 +54,9 @@
coinbase_pro_passphrase = os.getenv("COINBASE_PRO_PASSPHRASE")


# Huobi Tests
huobi_api_key = os.getenv("HUOBI_API_KEY")
huobi_secret_key = os.getenv("HUOBI_SECRET_KEY")
# Htx Tests
htx_api_key = os.getenv("HTX_API_KEY")
htx_secret_key = os.getenv("HTX_SECRET_KEY")

# Bittrex Tests
bittrex_api_key = os.getenv("BITTREX_API_KEY")
Expand Down
2 changes: 1 addition & 1 deletion hummingbot/connector/connector_status.py
Expand Up @@ -31,7 +31,7 @@
'hitbtc': 'bronze',
'hyperliquid_perpetual_testnet': 'bronze',
'hyperliquid_perpetual': 'bronze',
'huobi': 'bronze',
'htx': 'bronze',
'kraken': 'silver',
'kucoin': 'silver',
'kucoin_perpetual': 'silver',
Expand Down
Expand Up @@ -2,8 +2,8 @@
import uuid
from typing import TYPE_CHECKING, Any, Dict, List, Optional

import hummingbot.connector.exchange.huobi.huobi_constants as CONSTANTS
from hummingbot.connector.exchange.huobi.huobi_web_utils import public_rest_url
import hummingbot.connector.exchange.htx.htx_constants as CONSTANTS
from hummingbot.connector.exchange.htx.htx_web_utils import public_rest_url
from hummingbot.core.data_type.common import TradeType
from hummingbot.core.data_type.order_book_message import OrderBookMessage, OrderBookMessageType
from hummingbot.core.data_type.order_book_tracker_data_source import OrderBookTrackerDataSource
Expand All @@ -13,16 +13,16 @@
from hummingbot.logger import HummingbotLogger

if TYPE_CHECKING:
from hummingbot.connector.exchange.huobi.huobi_exchange import HuobiExchange
from hummingbot.connector.exchange.htx.htx_exchange import HtxExchange


class HuobiAPIOrderBookDataSource(OrderBookTrackerDataSource):
class HtxAPIOrderBookDataSource(OrderBookTrackerDataSource):

_logger: Optional[HummingbotLogger] = None

def __init__(self,
trading_pairs: List[str],
connector: 'HuobiExchange',
connector: 'HtxExchange',
api_factory: WebAssistantsFactory,
):
super().__init__(trading_pairs)
Expand All @@ -43,7 +43,7 @@ async def get_last_traded_prices(self, trading_pairs: List[str], domain: Optiona
async def listen_for_order_book_snapshots(self, ev_loop: asyncio.AbstractEventLoop, output: asyncio.Queue):
"""
Suppressing call to this function as the orderbook snapshots are handled by
listen_for_order_book_diffs() for Huobi
listen_for_order_book_diffs() for Htx
"""
pass

Expand Down
@@ -1,27 +1,27 @@
import asyncio
from typing import TYPE_CHECKING, List, Optional

import hummingbot.connector.exchange.huobi.huobi_constants as CONSTANTS
from hummingbot.connector.exchange.huobi.huobi_auth import HuobiAuth
import hummingbot.connector.exchange.htx.htx_constants as CONSTANTS
from hummingbot.connector.exchange.htx.htx_auth import HtxAuth
from hummingbot.core.data_type.user_stream_tracker_data_source import UserStreamTrackerDataSource
from hummingbot.core.web_assistant.connections.data_types import WSJSONRequest, WSResponse
from hummingbot.core.web_assistant.web_assistants_factory import WebAssistantsFactory
from hummingbot.core.web_assistant.ws_assistant import WSAssistant
from hummingbot.logger import HummingbotLogger

if TYPE_CHECKING:
from hummingbot.connector.exchange.huobi.huobi_exchange import HuobiExchange
from hummingbot.connector.exchange.htx.htx_exchange import HtxExchange


class HuobiAPIUserStreamDataSource(UserStreamTrackerDataSource):
class HtxAPIUserStreamDataSource(UserStreamTrackerDataSource):

_logger: Optional[HummingbotLogger] = None

def __init__(self, huobi_auth: HuobiAuth,
def __init__(self, htx_auth: HtxAuth,
trading_pairs: List[str],
connector: 'HuobiExchange',
connector: 'HtxExchange',
api_factory: Optional[WebAssistantsFactory]):
self._auth: HuobiAuth = huobi_auth
self._auth: HtxAuth = htx_auth
self._connector = connector
self._api_factory = api_factory
self._trading_pairs = trading_pairs
Expand All @@ -34,7 +34,7 @@ async def _connected_websocket_assistant(self) -> WSAssistant:

async def _authenticate_client(self, ws: WSAssistant):
"""
Sends an Authentication request to Huobi's WebSocket API Server
Sends an Authentication request to Htx's WebSocket API Server
"""
try:
ws_request: WSJSONRequest = WSJSONRequest(
Expand Down Expand Up @@ -84,12 +84,12 @@ async def _subscribe_channels(self, websocket_assistant: WSAssistant):
"""
try:
await self._authenticate_client(websocket_assistant)
await self._subscribe_topic(CONSTANTS.HUOBI_ACCOUNT_UPDATE_TOPIC, websocket_assistant)
await self._subscribe_topic(CONSTANTS.HTX_ACCOUNT_UPDATE_TOPIC, websocket_assistant)
for trading_pair in self._trading_pairs:
exchange_symbol = await self._connector.exchange_symbol_associated_to_pair(trading_pair=trading_pair)
await self._subscribe_topic(CONSTANTS.HUOBI_TRADE_DETAILS_TOPIC.format(exchange_symbol),
await self._subscribe_topic(CONSTANTS.HTX_TRADE_DETAILS_TOPIC.format(exchange_symbol),
websocket_assistant)
await self._subscribe_topic(CONSTANTS.HUOBI_ORDER_UPDATE_TOPIC.format(exchange_symbol),
await self._subscribe_topic(CONSTANTS.HTX_ORDER_UPDATE_TOPIC.format(exchange_symbol),
websocket_assistant)
except asyncio.CancelledError:
raise
Expand Down
Expand Up @@ -10,13 +10,13 @@
from hummingbot.core.web_assistant.auth import AuthBase
from hummingbot.core.web_assistant.connections.data_types import RESTRequest, WSJSONRequest

HUOBI_HOST_NAME = "api.huobi.pro"
HTX_HOST_NAME = "api.huobi.pro"
blagodar1 marked this conversation as resolved.
Show resolved Hide resolved


class HuobiAuth(AuthBase):
class HtxAuth(AuthBase):
def __init__(self, api_key: str, secret_key: str, time_provider: TimeSynchronizer):
self.api_key: str = api_key
self.hostname: str = HUOBI_HOST_NAME
self.hostname: str = HTX_HOST_NAME
self.secret_key: str = secret_key
self.time_provider = time_provider

Expand Down
Expand Up @@ -3,7 +3,7 @@
from hummingbot.core.api_throttler.data_types import RateLimit
from hummingbot.core.data_type.in_flight_order import OrderState

EXCHANGE_NAME = "huobi"
EXCHANGE_NAME = "htx"
BROKER_ID = "AAc484720a"
DOMAIN = ""
MAX_CLIENT_ORDER_ID_LENGTH = 64
Expand Down Expand Up @@ -34,11 +34,11 @@
CANCEL_ORDER_URL = "/v1/order/orders/{}/submitcancel"
BATCH_CANCEL_URL = "/v1/order/orders/batchcancel"

HUOBI_ACCOUNT_UPDATE_TOPIC = "accounts.update#2"
HUOBI_ORDER_UPDATE_TOPIC = "orders#{}"
HUOBI_TRADE_DETAILS_TOPIC = "trade.clearing#{}#0"
HTX_ACCOUNT_UPDATE_TOPIC = "accounts.update#2"
HTX_ORDER_UPDATE_TOPIC = "orders#{}"
HTX_TRADE_DETAILS_TOPIC = "trade.clearing#{}#0"

HUOBI_SUBSCRIBE_TOPICS = {HUOBI_ORDER_UPDATE_TOPIC, HUOBI_ACCOUNT_UPDATE_TOPIC, HUOBI_TRADE_DETAILS_TOPIC}
HTX_SUBSCRIBE_TOPICS = {HTX_ORDER_UPDATE_TOPIC, HTX_ACCOUNT_UPDATE_TOPIC, HTX_TRADE_DETAILS_TOPIC}

WS_CONNECTION_LIMIT_ID = "WSConnection"
WS_REQUEST_LIMIT_ID = "WSRequest"
Expand Down
Expand Up @@ -4,13 +4,13 @@

from bidict import bidict

import hummingbot.connector.exchange.huobi.huobi_constants as CONSTANTS
import hummingbot.connector.exchange.htx.htx_constants as CONSTANTS
from hummingbot.connector.constants import s_decimal_0, s_decimal_NaN
from hummingbot.connector.exchange.huobi import huobi_web_utils as web_utils
from hummingbot.connector.exchange.huobi.huobi_api_order_book_data_source import HuobiAPIOrderBookDataSource
from hummingbot.connector.exchange.huobi.huobi_api_user_stream_data_source import HuobiAPIUserStreamDataSource
from hummingbot.connector.exchange.huobi.huobi_auth import HuobiAuth
from hummingbot.connector.exchange.huobi.huobi_utils import is_exchange_information_valid
from hummingbot.connector.exchange.htx import htx_web_utils as web_utils
from hummingbot.connector.exchange.htx.htx_api_order_book_data_source import HtxAPIOrderBookDataSource
from hummingbot.connector.exchange.htx.htx_api_user_stream_data_source import HtxAPIUserStreamDataSource
from hummingbot.connector.exchange.htx.htx_auth import HtxAuth
from hummingbot.connector.exchange.htx.htx_utils import is_exchange_information_valid
from hummingbot.connector.exchange_py_base import ExchangePyBase
from hummingbot.connector.trading_rule import TradingRule
from hummingbot.connector.utils import combine_to_hb_trading_pair
Expand All @@ -26,33 +26,33 @@
from hummingbot.client.config.config_helpers import ClientConfigAdapter


class HuobiExchange(ExchangePyBase):
class HtxExchange(ExchangePyBase):

web_utils = web_utils

def __init__(
self,
client_config_map: "ClientConfigAdapter",
huobi_api_key: str,
huobi_secret_key: str,
htx_api_key: str,
htx_secret_key: str,
trading_pairs: Optional[List[str]] = None,
trading_required: bool = True,
):
self.huobi_api_key = huobi_api_key
self.huobi_secret_key = huobi_secret_key
self.htx_api_key = htx_api_key
self.htx_secret_key = htx_secret_key
self._trading_pairs = trading_pairs
self._trading_required = trading_required
self._account_id = ""
super().__init__(client_config_map=client_config_map)

@property
def name(self) -> str:
return "huobi"
return "htx"

@property
def authenticator(self):
return HuobiAuth(
api_key=self.huobi_api_key, secret_key=self.huobi_secret_key, time_provider=self._time_synchronizer
return HtxAuth(
api_key=self.htx_api_key, secret_key=self.htx_secret_key, time_provider=self._time_synchronizer
)

@property
Expand Down Expand Up @@ -143,13 +143,13 @@ def _create_web_assistants_factory(self) -> WebAssistantsFactory:
)

def _create_order_book_data_source(self):
return HuobiAPIOrderBookDataSource(
return HtxAPIOrderBookDataSource(
trading_pairs=self.trading_pairs, connector=self, api_factory=self._web_assistants_factory
)

def _create_user_stream_data_source(self) -> UserStreamTrackerDataSource:
return HuobiAPIUserStreamDataSource(
huobi_auth=self._auth,
return HtxAPIUserStreamDataSource(
htx_auth=self._auth,
trading_pairs=self._trading_pairs,
connector=self,
api_factory=self._web_assistants_factory,
Expand Down Expand Up @@ -419,7 +419,7 @@ async def _place_order(
exchange_order_id = str(creation_response["data"])
return exchange_order_id, self.current_timestamp
else:
raise ValueError(f"Huobi rejected the order {order_id} ({creation_response})")
raise ValueError(f"Htx rejected the order {order_id} ({creation_response})")

async def _place_cancel(self, order_id: str, tracked_order: InFlightOrder):
if tracked_order is None:
Expand Down
Expand Up @@ -28,29 +28,29 @@ def is_exchange_information_valid(exchange_info: Dict[str, Any]) -> bool:
return False


class HuobiConfigMap(BaseConnectorConfigMap):
connector: str = Field(default="huobi", client_data=None)
huobi_api_key: SecretStr = Field(
class HtxConfigMap(BaseConnectorConfigMap):
connector: str = Field(default="htx", client_data=None)
htx_api_key: SecretStr = Field(
default=...,
client_data=ClientFieldData(
prompt=lambda cm: "Enter your Huobi API key",
prompt=lambda cm: "Enter your HTX API key",
is_secure=True,
is_connect_key=True,
prompt_on_new=True,
)
)
huobi_secret_key: SecretStr = Field(
htx_secret_key: SecretStr = Field(
default=...,
client_data=ClientFieldData(
prompt=lambda cm: "Enter your Huobi secret key",
prompt=lambda cm: "Enter your HTX secret key",
is_secure=True,
is_connect_key=True,
prompt_on_new=True,
)
)

class Config:
title = "huobi"
title = "htx"


KEYS = HuobiConfigMap.construct()
KEYS = HtxConfigMap.construct()
@@ -1,6 +1,6 @@
from typing import Callable, Optional

import hummingbot.connector.exchange.huobi.huobi_constants as CONSTANTS
import hummingbot.connector.exchange.htx.htx_constants as CONSTANTS
from hummingbot.connector.time_synchronizer import TimeSynchronizer
from hummingbot.connector.utils import GZipCompressionWSPostProcessor, TimeSynchronizerRESTPreProcessor
from hummingbot.core.api_throttler.async_throttler import AsyncThrottler
Expand Down
12 changes: 6 additions & 6 deletions hummingbot/templates/conf_fee_overrides_TEMPLATE.yml
Expand Up @@ -102,12 +102,12 @@ hitbtc_maker_percent_fee:
hitbtc_percent_fee_token:
hitbtc_taker_fixed_fees:
hitbtc_taker_percent_fee:
huobi_buy_percent_fee_deducted_from_returns:
huobi_maker_fixed_fees:
huobi_maker_percent_fee:
huobi_percent_fee_token:
huobi_taker_fixed_fees:
huobi_taker_percent_fee:
htx_buy_percent_fee_deducted_from_returns:
htx_maker_fixed_fees:
htx_maker_percent_fee:
htx_percent_fee_token:
htx_taker_fixed_fees:
htx_taker_percent_fee:
kraken_buy_percent_fee_deducted_from_returns:
kraken_maker_fixed_fees:
kraken_maker_percent_fee:
Expand Down
2 changes: 1 addition & 1 deletion test/connector/README.md
Expand Up @@ -22,5 +22,5 @@ Markets that currently can run unit mock testing:

- Binance
- Coinbase Pro
- Huobi
- Htx
- KuCoin