Skip to content

Commit

Permalink
Remove price clients
Browse files Browse the repository at this point in the history
  • Loading branch information
moisses89 committed Nov 22, 2023
1 parent e2fb35a commit dacb44b
Show file tree
Hide file tree
Showing 13 changed files with 0 additions and 430 deletions.
4 changes: 0 additions & 4 deletions config/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -496,10 +496,6 @@
"TOKENS_ERC20_GET_BALANCES_BATCH", default=2_000
) # Number of tokens to get balances from in the same request. From 2_500 some nodes raise HTTP 413

TOKEN_ETH_PRICE_TTL = env.int(
"TOKEN_ETH_PRICE_TTL", default=60 * 30 # 30 minutes
) # Expiration time for token eth price

# Notifications
# ------------------------------------------------------------------------------
SLACK_API_WEBHOOK = env("SLACK_API_WEBHOOK", default=None)
Expand Down
4 changes: 0 additions & 4 deletions safe_transaction_service/tokens/clients/__init__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
# flake8: noqa F401
from .binance_client import BinanceClient
from .coingecko_client import CoingeckoClient
from .coinmarketcap_client import CoinMarketCapClient, CoinMarketCapToken
from .exceptions import CannotGetPrice
from .kleros_client import KlerosClient, KlerosToken
from .kraken_client import KrakenClient
from .kucoin_client import KucoinClient
47 changes: 0 additions & 47 deletions safe_transaction_service/tokens/clients/binance_client.py

This file was deleted.

72 changes: 0 additions & 72 deletions safe_transaction_service/tokens/clients/coingecko_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

from safe_transaction_service.tokens.clients.base_client import BaseHTTPClient
from safe_transaction_service.tokens.clients.exceptions import (
CannotGetPrice,
Coingecko404,
CoingeckoRateLimitError,
CoingeckoRequestError,
Expand Down Expand Up @@ -61,44 +60,6 @@ def _do_request(self, url: str) -> Dict[str, Any]:
logger.warning("Problem fetching %s", url)
raise CoingeckoRequestError from e

def _get_price(self, url: str, name: str):
try:
result = self._do_request(url)

# Result is returned with lowercased `name` (if querying by contract address, then `token_address`)
price = result.get(name)
if price and price.get("usd"):
return price["usd"]
else:
raise CannotGetPrice(f"Price from url={url} is {price}")
except CoingeckoRequestError as e:
raise CannotGetPrice(
f"Cannot get price from Coingecko for token={name}"
) from e

def get_price(self, name: str) -> float:
"""
:param name: coin name
:return: usd price for token name, 0. if not found
"""
name = name.lower()
url = urljoin(
self.base_url, f"/api/v3/simple/price?ids={name}&vs_currencies=usd"
)
return self._get_price(url, name)

def get_token_price(self, token_address: ChecksumAddress) -> float:
"""
:param token_address:
:return: usd price for token address, 0. if not found
"""
token_address = token_address.lower()
url = urljoin(
self.base_url,
f"api/v3/simple/token_price/{self.asset_platform}?contract_addresses={token_address}&vs_currencies=usd",
)
return self._get_price(url, token_address)

@lru_cache(maxsize=128)
def get_token_info(
self, token_address: ChecksumAddress
Expand All @@ -117,36 +78,3 @@ def get_token_logo_url(self, token_address: ChecksumAddress) -> Optional[str]:
token_info = self.get_token_info(token_address)
if token_info:
return token_info["image"]["large"]

def get_ada_usd_price(self) -> float:
return self.get_price("cardano")

def get_avax_usd_price(self) -> float:
return self.get_price("avalanche-2")

def get_aoa_usd_price(self) -> float:
return self.get_price("aurora")

def get_bnb_usd_price(self) -> float:
return self.get_price("binancecoin")

def get_ewt_usd_price(self) -> float:
return self.get_price("energy-web-token")

def get_matic_usd_price(self) -> float:
return self.get_price("matic-network")

def get_gather_usd_price(self) -> float:
return self.get_price("gather")

def get_fuse_usd_price(self) -> float:
return self.get_price("fuse-network-token")

def get_kcs_usd_price(self) -> float:
return self.get_price("kucoin-shares")

def get_metis_usd_price(self) -> float:
return self.get_price("metis-token")

def get_mtr_usd_price(self) -> float:
return self.get_price("meter-stable")
4 changes: 0 additions & 4 deletions safe_transaction_service/tokens/clients/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,3 @@ class CoingeckoRateLimitError(CoingeckoRequestError):
}
}
"""


class CannotGetPrice(CoingeckoRequestError):
pass
72 changes: 0 additions & 72 deletions safe_transaction_service/tokens/clients/kraken_client.py

This file was deleted.

89 changes: 0 additions & 89 deletions safe_transaction_service/tokens/clients/kucoin_client.py

This file was deleted.

7 changes: 0 additions & 7 deletions safe_transaction_service/tokens/signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
)

from .models import Token
from .services import PriceServiceProvider

logger = logging.getLogger(__name__)

Expand All @@ -34,9 +33,3 @@ def clear_cache(sender: Type[Model], instance: Token, created: bool, **kwargs) -

collectibles_service = CollectiblesServiceProvider()
collectibles_service.cache_token_info.clear()

price_service = PriceServiceProvider()
price_service.cache_token_eth_value.clear()
price_service.cache_token_info.clear()
price_service.cache_token_usd_value.clear()
price_service.cache_underlying_token.clear()
Loading

0 comments on commit dacb44b

Please sign in to comment.