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

Fix/Increase update interval for XRPL + Make Rate Oracle work with not supported pairs #6855

Merged
merged 7 commits into from Feb 20, 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
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
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)
mlguys marked this conversation as resolved.
Show resolved Hide resolved
self._prices.update(new_prices)

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