Skip to content

Commit

Permalink
Merge pull request hummingbot#6456 from vdmerweandre/fix/btc_markets_…
Browse files Browse the repository at this point in the history
…test_fixes

(fix): fix and refactored btcmarkets test cases
  • Loading branch information
nikspz authored Aug 16, 2023
2 parents 4b02c52 + 54ee39c commit 2b9a56f
Show file tree
Hide file tree
Showing 5 changed files with 126 additions and 107 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,11 @@
Rate Limits - https://api.btcmarkets.net/doc/v3#section/General-Notes
Rate Limits ws - https://docs.btcmarkets.net/v3/#tag/WS_Overview
"""

# Error codes
INVALID_TIME_WINDOW = "InvalidTimeWindow"
INVALID_TIMESTAMP = "InvalidTimestamp"
INVALID_AUTH_TIMESTAMP = "InvalidAuthTimestamp"
INVALID_AUTH_SIGNATURE = "InvalidAuthSignature"
ORDER_NOT_FOUND = "OrderNotFound"
INVALID_ORDERID = "InvalidOrderId"
32 changes: 9 additions & 23 deletions hummingbot/connector/exchange/btc_markets/btc_markets_exchange.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,31 +159,23 @@ def supported_order_types(self):
# https://docs.btcmarkets.net/v3/#tag/ErrorCodes
def _is_request_exception_related_to_time_synchronizer(self, request_exception: Exception):
error_code = str(request_exception)
is_time_synchronizer_related = "InvalidTimeWindow" in error_code or "InvalidTimestamp" in error_code or "InvalidAuthTimestamp" in error_code or "InvalidAuthSignature" in error_code
is_time_synchronizer_related = CONSTANTS.INVALID_TIME_WINDOW in error_code or CONSTANTS.INVALID_TIMESTAMP in error_code or CONSTANTS.INVALID_AUTH_TIMESTAMP in error_code or CONSTANTS.INVALID_AUTH_SIGNATURE in error_code
return is_time_synchronizer_related

def _is_order_not_found_during_status_update_error(self, status_update_exception: Exception) -> bool:
# TODO: implement this method correctly for the connector
# The default implementation was added when the functionality to detect not found orders was introduced in the
# ExchangePyBase class. Also fix the unit test test_lost_order_removed_if_not_found_during_order_status_update
# when replacing the dummy implementation
return False
return str(CONSTANTS.ORDER_NOT_FOUND) in str(status_update_exception)

def _is_order_not_found_during_cancelation_error(self, cancelation_exception: Exception) -> bool:
# TODO: implement this method correctly for the connector
# The default implementation was added when the functionality to detect not found orders was introduced in the
# ExchangePyBase class. Also fix the unit test test_cancel_order_not_found_in_the_exchange when replacing the
# dummy implementation
return False
return str(CONSTANTS.ORDER_NOT_FOUND) in str(cancelation_exception)

async def _place_cancel(self, order_id: str, tracked_order: InFlightOrder):
response = await self._api_request(
method=RESTMethod.DELETE,
response = await self._api_delete(
path_url=f"{CONSTANTS.ORDERS_URL}/{tracked_order.exchange_order_id}",
is_auth_required=True,
limit_id=f"{CONSTANTS.ORDERS_URL}"
)
cancelled = True if response["clientOrderId"] == order_id else False

return cancelled

async def _place_order(
Expand Down Expand Up @@ -221,13 +213,11 @@ async def _place_order(
post_data["price"] = price_str
post_data["postOnly"] = "true"

order_result = await self._api_request(
method = RESTMethod.POST,
order_result = await self._api_post(
path_url = CONSTANTS.ORDERS_URL,
data = post_data,
is_auth_required = True
)

exchange_order_id = str(order_result["orderId"])

return exchange_order_id, self.current_timestamp
Expand Down Expand Up @@ -280,8 +270,7 @@ async def _update_trading_fees(self):
"""
Update fees information from the exchange
"""
resp = await self._api_request(
method=RESTMethod.GET,
resp = await self._api_get(
path_url=CONSTANTS.FEES_URL,
is_auth_required=True,
limit_id=CONSTANTS.FEES_URL
Expand All @@ -293,7 +282,6 @@ async def _update_trading_fees(self):

async def _all_trade_updates_for_order(self, order: InFlightOrder) -> List[TradeUpdate]:
trade_updates = []

try:
if order.exchange_order_id is not None:
all_fills_response = await self._request_order_fills(order=order)
Expand All @@ -310,8 +298,7 @@ async def _all_trade_updates_for_order(self, order: InFlightOrder) -> List[Trade

async def _request_order_fills(self, order: InFlightOrder) -> Dict[str, Any]:
orderId = await order.get_exchange_order_id()
return await self._api_request(
method=RESTMethod.GET,
return await self._api_get(
path_url=CONSTANTS.TRADES_URL,
params={
"orderId": orderId
Expand All @@ -324,8 +311,7 @@ async def _request_order_update(self, order: InFlightOrder) -> Dict[str, Any]:
return await self._get_order_update(order.exchange_order_id)

async def _get_order_update(self, orderId: int) -> Dict[str, Any]:
return await self._api_request(
method=RESTMethod.GET,
return await self._api_get(
path_url=f"{CONSTANTS.ORDERS_URL}/{orderId}",
is_auth_required=True,
limit_id=CONSTANTS.ORDERS_URL
Expand Down
1 change: 0 additions & 1 deletion hummingbot/connector/exchange_py_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,6 @@ async def _create_order(self,
return
try:
exchange_order_id = await self._place_order_and_process_update(order=order, **kwargs,)

except asyncio.CancelledError:
raise
except Exception as ex:
Expand Down
3 changes: 2 additions & 1 deletion hummingbot/logger/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ def notify(self, msg: str):
hummingbot_app.notify(f"({pd.Timestamp.fromtimestamp(int(time.time()))}) {msg}")

def network(self, log_msg: str, app_warning_msg: Optional[str] = None, *args, **kwargs):
from hummingbot.client.hummingbot_application import HummingbotApplication
if app_warning_msg is not None and not HummingbotLogger.is_testing_mode():
from hummingbot.client.hummingbot_application import HummingbotApplication

from . import NETWORK

Expand Down
Loading

0 comments on commit 2b9a56f

Please sign in to comment.