Skip to content

Commit

Permalink
cache current token prices
Browse files Browse the repository at this point in the history
  • Loading branch information
BlazeWasHere committed Jan 22, 2022
1 parent ae43ed9 commit ec44f0c
Showing 1 changed file with 4 additions and 9 deletions.
13 changes: 4 additions & 9 deletions syn/utils/price.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
import dateutil.parser
import requests

from .data import COINGECKO_BASE_URL, COINGECKO_HISTORIC_URL, POPULATE_CACHE
from .cache import timed_cache, redis_cache
from .data import COINGECKO_HISTORIC_URL, POPULATE_CACHE
from .cache import redis_cache

logger = logging.Logger(__name__)

Expand Down Expand Up @@ -296,11 +296,6 @@ def get_price_for_address(chain: str, address: str) -> Decimal:
return get_price_coingecko(ADDRESS_TO_CGID[chain][address])


@timed_cache(60 * 10, maxsize=500)
def get_price_coingecko(_id: CoingeckoIDS, currency: str = "usd") -> Decimal:
# CG rate limits us @ 10-50 r/m, let's hope this makes us not trigger it.
if POPULATE_CACHE:
time.sleep(randint(5, 20))

r = requests.get(COINGECKO_BASE_URL.format(_id.value, currency))
return Decimal(r.json(use_decimal=True)[_id.value][currency])
# Proxy method for get_historic_price() with `_date` as today.
return get_historic_price(_id, datetime.now().date().isoformat(), currency)

0 comments on commit ec44f0c

Please sign in to comment.