Skip to content

Conversation

@onyb
Copy link
Member

@onyb onyb commented Jun 9, 2025

This PR introduces a significant optimization to our CoinGecko API usage by implementing the following:

  • a multi-level caching system (memcache + redis) to prevent unnecessary reads to Redis on every price request
  • resolving chain id + contract addresses to coingecko id, to avoid making duplicate price lookups to the same underlying token

Request: (3 unique tokens)

curl -X 'POST' \
  'http://127.0.0.1:8000/api/pricing/v1/getPrices?vs_currency=usd' \
  -H 'accept: application/json' \
  -H 'Content-Type: application/json' \
  -d '[
  {
    "address": "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
    "chain_id": "0x1",
    "coin_type": "ETH"
  },
  {
    "address": "0x833589fcd6edb6e08f4c7c32d4f71b54bda02913",
    "chain_id": "0x2105",
    "coin_type": "ETH"
  },
  {
    "address": "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
    "chain_id": "0x65",
    "coin_type": "SOL"
  }
]'

Response: (only 1 underlying price lookup)

[
  {
    "coin_type": "ETH",
    "chain_id": "0x1",
    "address": "0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
    "price": 0.999797,
    "vs_currency": "usd",
    "cache_status": "HIT"
  },
  {
    "coin_type": "SOL",
    "chain_id": "0x65",
    "address": "EPjFWdd5AufqSSqeM2qN1xzybapC8G4wEGGkZwyTDt1v",
    "price": 0.999797,
    "vs_currency": "usd",
    "cache_status": "HIT"
  },
  {
    "coin_type": "ETH",
    "chain_id": "0x2105",
    "address": "0x833589fcd6edb6e08f4c7c32d4f71b54bda02913",
    "price": 0.999797,
    "vs_currency": "usd",
    "cache_status": "MISS"
  }
]

@onyb onyb requested a review from Douglashdaniel June 9, 2025 18:23
@onyb onyb self-assigned this Jun 9, 2025
Copy link

@Douglashdaniel Douglashdaniel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

++

@onyb onyb merged commit 3fbce91 into master Jun 9, 2025
5 checks passed
@onyb onyb deleted the f/optimise-pricing branch June 9, 2025 19:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants