Skip to content

Commit

Permalink
Remove dummy xrpl rate oracle and replace it with better solution
Browse files Browse the repository at this point in the history
  • Loading branch information
mlguys committed Feb 19, 2024
1 parent 985c2a4 commit 4f78420
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
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.rate_oracle.sources.xrpl_rate_source import XrplRateSource
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 @@ -392,14 +391,7 @@ 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
# Hack to bypass RateOracle for now
if not isinstance(RateOracle.get_instance().source, XrplRateSource):
print("Using XrplRateOracle to set prices")
xrpl_rate_source = XrplRateSource()
RateOracle.get_instance().source = xrpl_rate_source
RateOracle.get_instance().source.set_prices({ticker_data["marketId"]: Decimal(ticker_data["midprice"])})
else:
RateOracle.get_instance().source.set_prices({ticker_data["marketId"]: Decimal(ticker_data["midprice"])})
RateOracle.get_instance().set_price(pair=ticker_data["marketId"], price=Decimal(ticker_data["midprice"]))

return ticker_data["midprice"]

Expand Down
14 changes: 11 additions & 3 deletions hummingbot/core/rate_oracle/rate_oracle.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
from hummingbot.core.rate_oracle.sources.gate_io_rate_source import GateIoRateSource
from hummingbot.core.rate_oracle.sources.kucoin_rate_source import KucoinRateSource
from hummingbot.core.rate_oracle.sources.rate_source_base import RateSourceBase
from hummingbot.core.rate_oracle.sources.xrpl_rate_source import XrplRateSource
from hummingbot.core.rate_oracle.utils import find_rate
from hummingbot.core.utils.async_utils import safe_ensure_future
from hummingbot.logger import HummingbotLogger
Expand All @@ -26,7 +25,6 @@
"kucoin": KucoinRateSource,
"ascend_ex": AscendExRateSource,
"gate_io": GateIoRateSource,
"xrpl": XrplRateSource,
}


Expand Down Expand Up @@ -185,10 +183,20 @@ 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)

for pair, price in new_prices.items():
self.set_price(pair, price)

if self._prices:
self._ready_event.set()
except asyncio.CancelledError:
Expand Down
34 changes: 0 additions & 34 deletions hummingbot/core/rate_oracle/sources/xrpl_rate_source.py

This file was deleted.

0 comments on commit 4f78420

Please sign in to comment.