From aabed5100b70f7f02fa3d749da84bfc699542213 Mon Sep 17 00:00:00 2001 From: Daniel Tan Date: Wed, 24 Mar 2021 16:41:25 +0800 Subject: [PATCH 1/3] (feat) add HBOT broker id to BitMax connector --- .../connector/exchange/bitmax/bitmax_exchange.py | 4 ++-- .../connector/exchange/bitmax/bitmax_utils.py | 15 +++++++-------- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/hummingbot/connector/exchange/bitmax/bitmax_exchange.py b/hummingbot/connector/exchange/bitmax/bitmax_exchange.py index 4606157dd3..5310b02d29 100644 --- a/hummingbot/connector/exchange/bitmax/bitmax_exchange.py +++ b/hummingbot/connector/exchange/bitmax/bitmax_exchange.py @@ -493,10 +493,10 @@ async def _create_order(self, raise ValueError(f"Notional amount {notional} is not withing the range of {bitmax_trading_rule.minNotional}-{bitmax_trading_rule.maxNotional}.") # TODO: check balance - [exchange_order_id, timestamp] = bitmax_utils.gen_exchange_order_id(self._account_uid) + [exchange_order_id, timestamp] = bitmax_utils.gen_exchange_order_id(self._account_uid, order_id) api_params = { - "id": exchange_order_id, + "id": order_id, "time": timestamp, "symbol": bitmax_utils.convert_to_exchange_trading_pair(trading_pair), "orderPrice": f"{price:f}", diff --git a/hummingbot/connector/exchange/bitmax/bitmax_utils.py b/hummingbot/connector/exchange/bitmax/bitmax_utils.py index 45f943688d..3f42a67e03 100644 --- a/hummingbot/connector/exchange/bitmax/bitmax_utils.py +++ b/hummingbot/connector/exchange/bitmax/bitmax_utils.py @@ -15,7 +15,7 @@ DEFAULT_FEES = [0.1, 0.1] -HBOT_BROKER_ID = "hbot-" +HBOT_BROKER_ID = "HBOT" def convert_from_exchange_trading_pair(exchange_trading_pair: str) -> str: @@ -35,21 +35,20 @@ def uuid32(): return ''.join(random.choice(string.ascii_uppercase + string.ascii_lowercase + string.digits) for _ in range(32)) -def derive_order_id(user_uid: str, cl_order_id: str, ts: int, order_src='a') -> str: +def derive_order_id(user_uid: str, cl_order_id: str, ts: int) -> str: """ Server order generator based on user info and input. :param user_uid: user uid :param cl_order_id: user random digital and number id :param ts: order timestamp in milliseconds - :param order_src: 'a' for rest api order, 's' for websocket order. :return: order id of length 32 """ - return (order_src + format(ts, 'x')[-11:] + user_uid[-11:] + cl_order_id[-9:])[:32] + return ("HMBot" + format(ts, 'x')[-11:] + user_uid[-11:] + cl_order_id[-5:])[:32] -def gen_exchange_order_id(userUid: str) -> Tuple[str, int]: +def gen_exchange_order_id(userUid: str, client_order_id: str) -> Tuple[str, int]: """ - Generate an order id + Generates the exchange order id based on user uid and client order id. :param user_uid: user uid :return: order id of length 32 """ @@ -57,7 +56,7 @@ def gen_exchange_order_id(userUid: str) -> Tuple[str, int]: return [ derive_order_id( userUid, - uuid32(), + client_order_id, time ), time @@ -66,7 +65,7 @@ def gen_exchange_order_id(userUid: str) -> Tuple[str, int]: def gen_client_order_id(is_buy: bool, trading_pair: str) -> str: side = "B" if is_buy else "S" - return f"{HBOT_BROKER_ID}{side}-{trading_pair}-{get_tracking_nonce()}" + return f"{HBOT_BROKER_ID}-{side}-{trading_pair}-{get_tracking_nonce()}" KEYS = { From b356f73ea7e8f63e04ab3e8ddf63d9d9f1adb3e6 Mon Sep 17 00:00:00 2001 From: Daniel Tan Date: Wed, 24 Mar 2021 17:06:26 +0800 Subject: [PATCH 2/3] (fix) fix invalid order ID error --- hummingbot/connector/exchange/bitmax/bitmax_exchange.py | 2 +- hummingbot/connector/exchange/bitmax/bitmax_utils.py | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/hummingbot/connector/exchange/bitmax/bitmax_exchange.py b/hummingbot/connector/exchange/bitmax/bitmax_exchange.py index 5310b02d29..bef04d3a52 100644 --- a/hummingbot/connector/exchange/bitmax/bitmax_exchange.py +++ b/hummingbot/connector/exchange/bitmax/bitmax_exchange.py @@ -496,7 +496,7 @@ async def _create_order(self, [exchange_order_id, timestamp] = bitmax_utils.gen_exchange_order_id(self._account_uid, order_id) api_params = { - "id": order_id, + "id": exchange_order_id, "time": timestamp, "symbol": bitmax_utils.convert_to_exchange_trading_pair(trading_pair), "orderPrice": f"{price:f}", diff --git a/hummingbot/connector/exchange/bitmax/bitmax_utils.py b/hummingbot/connector/exchange/bitmax/bitmax_utils.py index 3f42a67e03..13b3b708ce 100644 --- a/hummingbot/connector/exchange/bitmax/bitmax_utils.py +++ b/hummingbot/connector/exchange/bitmax/bitmax_utils.py @@ -49,7 +49,8 @@ def derive_order_id(user_uid: str, cl_order_id: str, ts: int) -> str: def gen_exchange_order_id(userUid: str, client_order_id: str) -> Tuple[str, int]: """ Generates the exchange order id based on user uid and client order id. - :param user_uid: user uid + :param user_uid: user uid, + :param client_order_id: client order id used for local order tracking :return: order id of length 32 """ time = get_ms_timestamp() From 91fba43a34396821110a912875707371810f96e7 Mon Sep 17 00:00:00 2001 From: Daniel Tan Date: Mon, 29 Mar 2021 08:35:12 +0800 Subject: [PATCH 3/3] (clean) clean up constant variables in utils --- hummingbot/connector/exchange/bitmax/bitmax_utils.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/hummingbot/connector/exchange/bitmax/bitmax_utils.py b/hummingbot/connector/exchange/bitmax/bitmax_utils.py index 13b3b708ce..93d33eb9d1 100644 --- a/hummingbot/connector/exchange/bitmax/bitmax_utils.py +++ b/hummingbot/connector/exchange/bitmax/bitmax_utils.py @@ -15,7 +15,7 @@ DEFAULT_FEES = [0.1, 0.1] -HBOT_BROKER_ID = "HBOT" +HBOT_BROKER_ID = "HMBot" def convert_from_exchange_trading_pair(exchange_trading_pair: str) -> str: @@ -43,7 +43,7 @@ def derive_order_id(user_uid: str, cl_order_id: str, ts: int) -> str: :param ts: order timestamp in milliseconds :return: order id of length 32 """ - return ("HMBot" + format(ts, 'x')[-11:] + user_uid[-11:] + cl_order_id[-5:])[:32] + return (HBOT_BROKER_ID + format(ts, 'x')[-11:] + user_uid[-11:] + cl_order_id[-5:])[:32] def gen_exchange_order_id(userUid: str, client_order_id: str) -> Tuple[str, int]: