Skip to content

Commit

Permalink
use coingecko pro api
Browse files Browse the repository at this point in the history
  • Loading branch information
lachlanglen committed May 23, 2024
1 parent ba8c3e9 commit 48b20ec
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
7 changes: 6 additions & 1 deletion base/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
AWS_SECRET_ACCESS_KEY = os.environ.get("PL_AWS_SECRET_ACCESS_KEY")
# CACHALOT_ENABLED = strtobool(os.environ.get("PL_CACHALOT_ENABLED", "False"))
# CACHALOT_TIMEOUT = os.environ.get("PL_CACHALOT_TIMEOUT")
COINGECKO_API_KEY = os.environ.get("PL_COINGECKO_API_KEY")
DEBUG = strtobool(os.environ.get("PL_DEBUG", "False"))
ENVIRONMENT = os.environ.get("PL_ENVIRONMENT", "local")
LOG_LEVEL = os.getenv("PL_LOG_LEVEL", "INFO").upper()
Expand All @@ -53,7 +54,11 @@

BLOCK_SAVE_HEIGHT = os.environ.get("BLOCK_SAVE_HEIGHT")

COINGECKO_URL = "https://api.coingecko.com/api/v3"
COINGECKO_URL = (
"https://pro-api.coingecko.com/api/v3"
if COINGECKO_API_KEY
else "https://api.coingecko.com/api/v3"
)
# Number of hours around a given timestamp for querying historical prices
HISTORICAL_PRICE_QUERY_HOURS = 24

Expand Down
2 changes: 2 additions & 0 deletions donations/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,8 @@ def fetch_usd_prices(self):
"No existing price within acceptable time period; fetching historical price..."
)
endpoint = f"{settings.COINGECKO_URL}/coins/{self.ft.id}/history?date={format_date(self.donated_at)}&localization=false"
if settings.COINGECKO_API_KEY:
endpoint += f"&x_cg_pro_api_key={settings.COINGECKO_API_KEY}"
logger.info(f"coingecko endpoint: {endpoint}")
response = requests.get(endpoint)
logger.info(f"coingecko response: {response}")
Expand Down
2 changes: 1 addition & 1 deletion indexer_app/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def listen_to_near_events():
try:
# Update below with desired network & block height
# start_block = get_block_height("current_block_height")
start_block = 112952680
start_block = 112959664
logger.info(f"what's the start block, pray tell? {start_block-1}")
loop.run_until_complete(indexer("mainnet", start_block - 1, None))
except WorkerLostError:
Expand Down

0 comments on commit 48b20ec

Please sign in to comment.