Skip to content

Commit

Permalink
Merge pull request hummingbot#6855 from hummingbot/fix/xrpl-increase-…
Browse files Browse the repository at this point in the history
…snapshot-update-interval

Fix/Increase update interval for XRPL + Make Rate Oracle work with not supported pairs
  • Loading branch information
fengtality authored Feb 20, 2024
2 parents a06e27b + b94b27d commit 84b4f9c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
from hummingbot.core.data_type.trade_fee import MakerTakerExchangeFeeRates, TokenAmount, TradeFeeBase, TradeFeeSchema
from hummingbot.core.event.events import MarketEvent
from hummingbot.core.gateway.gateway_http_client import GatewayHttpClient
from hummingbot.core.rate_oracle.rate_oracle import RateOracle
from hummingbot.core.utils.async_utils import safe_gather
from hummingbot.core.utils.tracking_nonce import NonceCreator
from hummingbot.logger import HummingbotLogger
Expand Down Expand Up @@ -62,8 +63,8 @@ def __init__(
self._client = JsonRpcClient(self._base_url)
self._client_order_id_nonce_provider = NonceCreator.for_microseconds()
self._throttler = AsyncThrottler(rate_limits=CONSTANTS.RATE_LIMITS)
self.max_snapshots_update_interval = 10
self.min_snapshots_update_interval = 3
self.max_snapshots_update_interval = 15
self.min_snapshots_update_interval = 5

@property
def connector_name(self) -> str:
Expand Down Expand Up @@ -390,6 +391,8 @@ async def _get_ticker_data(self, trading_pair: str) -> Dict[str, Any]:

def _get_last_trade_price_from_ticker_data(self, ticker_data: Dict[str, Any]) -> Decimal:
# Get mid-price from order book for now since there is no easy way to get last trade price from ticker data
RateOracle.get_instance().set_price(pair=ticker_data["marketId"], price=Decimal(ticker_data["midprice"]))

return ticker_data["midprice"]

@staticmethod
Expand Down
10 changes: 9 additions & 1 deletion hummingbot/core/rate_oracle/rate_oracle.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,10 +183,18 @@ async def rate_async(self, pair: str) -> Decimal:
prices = await self._source.get_prices(quote_token=self._quote_token)
return find_rate(prices, pair)

def set_price(self, pair: str, price: Decimal):
"""
Update keys in self._prices with new prices
"""
self._prices[pair] = price

async def _fetch_price_loop(self):
while True:
try:
self._prices = await self._source.get_prices(quote_token=self._quote_token)
new_prices = await self._source.get_prices(quote_token=self._quote_token)
self._prices.update(new_prices)

if self._prices:
self._ready_event.set()
except asyncio.CancelledError:
Expand Down

0 comments on commit 84b4f9c

Please sign in to comment.