mirror of
https://github.com/OpenBB-finance/OpenBB.git
synced 2026-11-09 02:42:36 +00:00
* example changes in slopes * change lettering size and side bar capitalization * revert back to Fira * start automatic website generation * this was autogen * add examples to slopes model * generate slopes doc * change to _index.md * allow italic formatting * fix regex * option to regenerate paths * update alt docs * fix generate * update alt * fix generate * update common * target italic only for types * format alt * format italic common * add sig indentation * update sig indent alt * update common ident * add todo * generate docstrings for all menus * fix maxdd * fix returns font size * fix keys docs * fix more docstrings * escape literal symbols * escape literal symbols * reformat keys * format opt * remove literal escape * remove another literal escape * remove another literal escape * unindent returns * update docs return unindent * add comma in last arg * fix funcs without params * fix signature * compact some code * refactor some more code * refactor some code * some final cleanup * write docstrings * change main * move futures paths * generate futures docs * add external axes references * fix typo * revert to double docstring * fix small bug * remove docs folder * generate.py in website folder * add forecast to docs * clear some warnings * fix underscore * remove cite * refresh website docs * fix forecast docstrings * fix po * fix po docs and remove italic * fix more docstrings * remove last warning * codespell * flake8 * exclude website contente from flake * noqa on optimizer * update website * fix mypy * remove setup from mypy * mypy to openbbterminal * update precommit * pylint * try to remove sdk loading issue * avoid logging on test Co-authored-by: Jeroen Bouma <jer.bouma@gmail.com>
166 lines
4.2 KiB
Python
166 lines
4.2 KiB
Python
"""Coindix model"""
|
|
__docformat__ = "numpy"
|
|
|
|
import logging
|
|
from typing import Optional
|
|
|
|
import urllib3
|
|
import pandas as pd
|
|
import requests
|
|
|
|
from openbb_terminal.decorators import log_start_end
|
|
from openbb_terminal.helper_funcs import get_user_agent, lambda_long_number_format
|
|
|
|
|
|
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
VAULTS_FILTERS = ["name", "chain", "protocol", "apy", "tvl", "link"]
|
|
CHAINS = [
|
|
"ethereum",
|
|
"polygon",
|
|
"avalanche",
|
|
"bsc",
|
|
"terra",
|
|
"fantom",
|
|
"moonriver",
|
|
"celo",
|
|
"heco",
|
|
"okex",
|
|
"cronos",
|
|
"arbitrum",
|
|
"eth",
|
|
"harmony",
|
|
"fuse",
|
|
"defichain",
|
|
"solana",
|
|
"optimism",
|
|
"kusama",
|
|
"metis",
|
|
"osmosis",
|
|
]
|
|
PROTOCOLS = [
|
|
"aave",
|
|
"acryptos",
|
|
"alpaca",
|
|
"anchor",
|
|
"autofarm",
|
|
"balancer",
|
|
"bancor",
|
|
"beefy",
|
|
"belt",
|
|
"compound",
|
|
"convex",
|
|
"cream",
|
|
"curve",
|
|
"defichain",
|
|
"geist",
|
|
"lido",
|
|
"liquity",
|
|
"mirror",
|
|
"pancakeswap",
|
|
"raydium",
|
|
"sushi",
|
|
"tarot",
|
|
"traderjoe",
|
|
"tulip",
|
|
"ubeswap",
|
|
"uniswap",
|
|
"venus",
|
|
"yearn",
|
|
"osmosis",
|
|
"tulip",
|
|
]
|
|
VAULT_KINDS = [
|
|
"lp",
|
|
"single",
|
|
"noimploss",
|
|
"stable",
|
|
]
|
|
|
|
|
|
@log_start_end(log=logger)
|
|
def _prepare_params(**kwargs) -> dict:
|
|
"""Helper method, which handles preparation of parameters for requests to coindix api.
|
|
|
|
Parameters
|
|
----------
|
|
kwargs: keyword arguments: chain, kind, protocol
|
|
|
|
Returns
|
|
-------
|
|
dict:
|
|
Prepared parameters for request
|
|
"""
|
|
|
|
params = {"sort": "-apy", "tvl": "1m", "kind": "all"}
|
|
mapping = {"chain": CHAINS, "protocol": PROTOCOLS, "kind": VAULT_KINDS}
|
|
for key, value in kwargs.items():
|
|
category = mapping.get(key, [])
|
|
if value in category:
|
|
params.update({key: value})
|
|
return {k: v.lower() for k, v in params.items()}
|
|
|
|
|
|
@log_start_end(log=logger)
|
|
def get_defi_vaults(
|
|
chain: Optional[str] = None,
|
|
protocol: Optional[str] = None,
|
|
kind: Optional[str] = None,
|
|
ascend: bool = True,
|
|
sortby: str = "apy",
|
|
) -> pd.DataFrame:
|
|
"""Get DeFi Vaults Information. DeFi Vaults are pools of funds with an assigned strategy which main goal is to
|
|
maximize returns of its crypto assets. [Source: https://coindix.com/]
|
|
|
|
Parameters
|
|
----------
|
|
chain: str
|
|
Blockchain - one from list [
|
|
'ethereum', 'polygon', 'avalanche', 'bsc', 'terra', 'fantom',
|
|
'moonriver', 'celo', 'heco', 'okex', 'cronos', 'arbitrum', 'eth',
|
|
'harmony', 'fuse', 'defichain', 'solana', 'optimism'
|
|
]
|
|
protocol: str
|
|
DeFi protocol - one from list: [
|
|
'aave', 'acryptos', 'alpaca', 'anchor', 'autofarm', 'balancer', 'bancor',
|
|
'beefy', 'belt', 'compound', 'convex', 'cream', 'curve', 'defichain', 'geist',
|
|
'lido', 'liquity', 'mirror', 'pancakeswap', 'raydium', 'sushi', 'tarot', 'traderjoe',
|
|
'tulip', 'ubeswap', 'uniswap', 'venus', 'yearn'
|
|
]
|
|
kind: str
|
|
Kind/type of vault - one from list: ['lp','single','noimploss','stable']
|
|
|
|
Returns
|
|
-------
|
|
pd.DataFrame
|
|
Top 100 DeFi Vaults for given chain/protocol sorted by APY.
|
|
"""
|
|
|
|
headers = {"User-Agent": get_user_agent()}
|
|
params = _prepare_params(chain=chain, protocol=protocol, kind=kind)
|
|
response = requests.get(
|
|
"https://apiv2.coindix.com/search", headers=headers, params=params, verify=False
|
|
)
|
|
if not 200 <= response.status_code < 300:
|
|
raise Exception(f"Coindix api exception: {response.text}")
|
|
|
|
try:
|
|
data = response.json()["data"]
|
|
if len(data) == 0:
|
|
return pd.DataFrame()
|
|
df = pd.DataFrame(data)[VAULTS_FILTERS]
|
|
except Exception as e:
|
|
logger.exception(e)
|
|
raise ValueError(f"Invalid Response: {response.text}") from e
|
|
|
|
df = df.sort_values(by=sortby, ascending=ascend).fillna("NA")
|
|
df["tvl"] = df["tvl"].apply(lambda x: lambda_long_number_format(x))
|
|
df["apy"] = df["apy"].apply(
|
|
lambda x: f"{str(round(x * 100, 2))} %" if isinstance(x, (int, float)) else x
|
|
)
|
|
df.columns = [x.title() for x in df.columns]
|
|
df.rename(columns={"Apy": "APY (%)", "Tvl": "TVL ($)"}, inplace=True)
|
|
return df
|