Skip to content

Commit

Permalink
fix: apply hyperliquid market rate fix to fetch_orders
Browse files Browse the repository at this point in the history
  • Loading branch information
xmatthias committed Dec 27, 2024
1 parent a4ae5b7 commit 6f3dca4
Showing 1 changed file with 31 additions and 5 deletions.
36 changes: 31 additions & 5 deletions freqtrade/exchange/hyperliquid.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Hyperliquid exchange subclass"""

import logging
from copy import deepcopy
from datetime import datetime

from freqtrade.constants import BuySell
Expand Down Expand Up @@ -157,9 +158,15 @@ def get_funding_fees(
logger.warning(f"Could not update funding fees for {pair}.")
return 0.0

def fetch_order(self, order_id: str, pair: str, params: dict | None = None) -> CcxtOrder:
order = super().fetch_order(order_id, pair, params)

def _adjust_hyperliquid_order(
self,
order: dict,
) -> dict:
"""
Adjusts order response for Hyperliquid
:param order: Order response from Hyperliquid
:return: Adjusted order response
"""
if (
order["average"] is None
and order["status"] in ("canceled", "closed")
Expand All @@ -168,7 +175,9 @@ def fetch_order(self, order_id: str, pair: str, params: dict | None = None) -> C
# Hyperliquid does not fill the average price in the order response
# Fetch trades to calculate the average price to have the actual price
# the order was executed at
trades = self.get_trades_for_order(order_id, pair, since=dt_from_ts(order["timestamp"]))
trades = self.get_trades_for_order(
order["id"], order["symbol"], since=dt_from_ts(order["timestamp"])
)

if trades:
total_amount = sum(t["amount"] for t in trades)
Expand All @@ -177,6 +186,23 @@ def fetch_order(self, order_id: str, pair: str, params: dict | None = None) -> C
if total_amount
else None
)
self._log_exchange_response("fetch_order2", order)
return order

def fetch_order(self, order_id: str, pair: str, params: dict | None = None) -> CcxtOrder:
order = super().fetch_order(order_id, pair, params)

order = self._adjust_hyperliquid_order(order)
self._log_exchange_response("fetch_order2", order)

return order

def fetch_orders(
self, pair: str, since: datetime, params: dict | None = None
) -> list[CcxtOrder]:
orders = super().fetch_orders(pair, since, params)
for idx, order in enumerate(deepcopy(orders)):
order2 = self._adjust_hyperliquid_order(order)
orders[idx] = order2

self._log_exchange_response("fetch_orders2", orders)
return orders

0 comments on commit 6f3dca4

Please sign in to comment.