Files
OpenBB/gamestonk_terminal/cryptocurrency/coinpaprika_helpers.py
jp 28e3970912 Refactoring crypto menu 2nd part (#724)
* Add separate view for finbrain for crypto curreny sentiment analysis

* Move json with symbols to separate directory, little refactoring, update readme

* Add screenshot of finbrain for PolkaDot

* Remove not used methods, remove binance_view, binance_model from discovery menu (It's not needed, as we use all_coins view for finding coins from all sources

* Refactoring Due Diligence menu. Changing views, moving argparsers to controller

* Refactor cryptomenu. Overview, Discovery, DD menu - move argparsers to controllers, add typing hints, change names of views/models, adjust tests

* Adjust tests

* Move finbrain and find/coins method to controller

* Move report argparser into controller. Adjust tests

* Adjust docstrings

* Add helper method to take care about retry/wait for coingecko scraping

* Fix failing test

* Adjust newlines, docstrings, cmd descriptions

* Add use tabulate df flag for all crypto views

* Add status code for coingecko

* Add note, that some coingecko commands can fail

Co-authored-by: Jakub Pluta <jakub.pluta@cdq.com>
2021-09-05 17:15:35 +01:00

63 lines
2.1 KiB
Python

"""CoinPaprika helpers"""
__docformat__ = "numpy"
from typing import Any, Optional
import requests
from requests.adapters import HTTPAdapter
class PaprikaSession:
PAPRIKA_BASE_URL = "https://api.coinpaprika.com/v1"
ENDPOINTS = {
"global": "/global",
"coin": "/coins/{}",
"coins": "/coins",
"coin_tweeter": "/coins/{}/twitter",
"coin_events": "/coins/{}/events",
"coin_exchanges": "/coins/{}/exchanges",
"coin_markets": "/coins/{}/markets",
"ohlcv": "/coins/{}/ohlcv/latest",
"ohlcv_hist": "/coins/{}/ohlcv/historical",
"people": "/people/{}",
"tickers": "/tickers",
"ticker_info": "/tickers/{}",
"exchanges": "/exchanges",
"exchange_info": "/exchanges/{}",
"exchange_markets": "/exchanges/{}/markets",
"contract_platforms": "/contracts",
"contract_platform_addresses": "/contracts/{}",
"search": "/search",
}
def __init__(self, max_retries: int = 5):
self.session = requests.Session()
self.session.mount(self.PAPRIKA_BASE_URL, HTTPAdapter(max_retries=max_retries))
def make_request(
self, endpoint: str, payload: Optional[Any] = None, **kwargs: Any
) -> dict:
"""Helper method that handles request for coinpaprika api.
It prepares URL for given endpoint and payload if it's part of requests
Parameters
----------
endpoint: str,
it's an endpoint that we want to query. e.g. to get twitter data for given coin we need to use:
https://api.coinpaprika.com/v1/coins/{}/twitter
payload: dict
the body of your request. Contains the data send to the CoinPaprika API when making an API request
kwargs:
additional parameters that will be added to payload
Returns
-------
dict with response data
"""
url = f"{self.PAPRIKA_BASE_URL}{endpoint}"
if payload is None:
payload = {}
if kwargs:
payload.update(kwargs)
return self.session.get(url, params=payload).json()