polyledger/connect

Use CoinAPI.io for OHLCV price data

Closed this issue · 0 comments

Description

We should eventually make the switch from the Cryptocompare API for historical price data to CoinAPI. CoinAPI provides high quality OHLCV price data from 30+ exchanges with every granularity option we could want.

Chart granularity plan:

  • per 15 minutes over 24 hours (360 prices data points)
  • per 30 minutes over 7 days (336 price data points)
  • per 2 hours over 30 days (360 price data points)
  • per 6 hours over 90 days (360 price data points)
  • per 12 hours over 180 days (360 price data points)
  • per 1 day over 365 days (365 price data points)

The engineering challenge behind this switch is how we fetch/remove prices every 15 min. Fetching the price is easy, but determining which prices to remove is hard.

Here is an algorithm:

Every 15 minutes, fetch the prices. Check the time.

If it is 0:00, remove prices from 1 year and 1 day ago
If it is 12:00, remove price from 180 and 1/2 days ago
If it is 6:00 or 8:00, remove price from 90 and 1/4 days ago
If it is 2:00, 4:00, 8:00, 10:00, 14:00, 16:00, 20:00, or 22:00, remove price from 30 and 1/12 days ago
If it is 0:30, 1:00, 1:30, 2:30, 3, ..., 20:30, 21:00, 21:30, 22:30, remove price from 7 and 1/48 days ago
If it is 0:15, 0:45, 1:15, 1:45, 2:15, ..., 21:15, 21:45, 22:15, 22:45, remove price from 1 and 1/96 days ago

CoinAPI Pricing

Even if we only support 10 assets, with 96 fifteen minute intervals in a day we’d make 96 * 10 = 960 requests per day which barely falls into their $79/mo. plan (https://www.coinapi.io/pricing).