mirror of
https://github.com/freqtrade/freqtrade.git
synced 2024-11-10 10:21:59 +00:00
Add CoinGeckoApi Wrapper
This commit is contained in:
parent
7a309d6927
commit
c1f780794a
24
freqtrade/util/CoinGecko.py
Normal file
24
freqtrade/util/CoinGecko.py
Normal file
|
@ -0,0 +1,24 @@
|
|||
from pycoingecko import CoinGeckoAPI
|
||||
|
||||
|
||||
class FtCoinGeckoApi(CoinGeckoAPI):
|
||||
"""
|
||||
Simple wrapper around pycoingecko's api to support Demo API keys.
|
||||
|
||||
"""
|
||||
|
||||
__API_URL_BASE = "https://api.coingecko.com/api/v3/"
|
||||
__PRO_API_URL_BASE = "https://pro-api.coingecko.com/api/v3/"
|
||||
_api_key: str = ""
|
||||
|
||||
def __init__(self, api_key: str = "", *, is_demo=True, retries=5):
|
||||
super().__init__(retries=retries)
|
||||
# Doint' pass api_key to parent, instead set the header on the session directly
|
||||
self._api_key = api_key
|
||||
|
||||
if api_key and not is_demo:
|
||||
self.api_base_url = self.__PRO_API_URL_BASE
|
||||
self.session.headers.update({"x-cg-pro-api-key": api_key})
|
||||
else:
|
||||
self.api_base_url = self.__API_URL_BASE
|
||||
self.session.headers.update({"x-cg-demo-api-key": api_key})
|
Loading…
Reference in New Issue
Block a user