mirror of
https://github.com/OpenBB-finance/OpenBB.git
synced 2026-10-29 13:32:08 +00:00
* Fixes * Update stocks_helper.py * update git-actions set-output to new format * Update stocks_helper.py * Update terminal_helper.py * removed LineAnnotateDrawer from qa_view * lint * few changes * updates * sdk auto gen modules done * Update stocks_helper.py * updates to changed imports, and remove first sdk_modules * Update generate_sdk.py * Update generate_sdk.py * pylint * revert stocks_helper * Update generate_sdk.py * Update sdk.py * Update generate_sdk.py * full auto generation, added sdk.py/controllers creation * missed enable forecasting * added running black in subprocess after sdk files generation completes * removed deleted sdk_arg_logger * comment out tests * property doc fix * clean up * Update generate_sdk.py * make trailmap classes useable for doc generation * Update generate_sdk.py * added lineon to trailmap class for linking to func in markdown * changed lineon to dict * added full_path to trailmap for linking in docs * updated portfolio * feat: initial files * feat: added meta head * feat: added funcdef * added func_def to trailmap attributes for markdown in docs, added missing type hints to covid functions * feat: added view and merged with jaun * Update generate_sdk.py * Update generate_sdk.py * Update generate_sdk.py * Update generate_sdk.py * init * fix returns * fix: random stuff * fix: random * fixed encoding issue on windows * fix: generate tabs * update * Update generate_sdk_markdown.py * Create .pydocstyle.ini * added type hint classes for views * fixes * alt, ba * alt-economy * Update finviz_compare_model.py * fixs * Update substack_model.py * Update generate_sdk.py * last of my section * porfolio * po * Update optimizer_model.py * fixing more things * few more * keys done * update * fixes * Update generate_sdk_markdown.py * Update generate_sdk_markdown.py * mypy forecast fix * Update generate_sdk_markdown.py * Update generate_sdk_markdown.py * Update generate_sdk_markdown.py * fixes * forecast fixes * one more fix * Update coinbase_model.py * Update generate_sdk_markdown.py Co-authored-by: Colin Delahunty <72827203+colin99d@users.noreply.github.com> Co-authored-by: James Maslek <jmaslek11@gmail.com> Co-authored-by: jose-donato <zmcdonato@gmail.com> Co-authored-by: andrewkenreich <andrew.kenreich@gmail.com>
68 lines
2.4 KiB
Python
68 lines
2.4 KiB
Python
"""Cryptosaurio model"""
|
|
__docformat__ = "numpy"
|
|
|
|
import logging
|
|
from typing import Tuple
|
|
import pandas as pd
|
|
import requests
|
|
|
|
from openbb_terminal.decorators import log_start_end
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
api_url = "https://barney.cryptosaurio.com"
|
|
|
|
|
|
@log_start_end(log=logger)
|
|
def get_anchor_data(address: str = "") -> Tuple[pd.DataFrame, pd.DataFrame, str]:
|
|
"""Returns anchor protocol earnings data of a certain terra address
|
|
[Source: https://cryptosaurio.com/]
|
|
|
|
Parameters
|
|
----------
|
|
address : str
|
|
Terra address. Valid terra addresses start with 'terra'
|
|
|
|
Returns
|
|
-------
|
|
Tuple[pd.DataFrame, pd.DataFrame, str]
|
|
- pd.DataFrame: Earnings over time in UST
|
|
- pd.DataFrame: History of transactions
|
|
- str: Overall statistics
|
|
"""
|
|
|
|
if not address.startswith("terra"):
|
|
raise Exception(
|
|
"Select a valid address. Valid terra addresses start with 'terra'"
|
|
)
|
|
|
|
response = requests.get(f"{api_url}/get-anchor-protocol-data-v2/{address}")
|
|
if response.status_code != 200:
|
|
raise Exception(f"Status code: {response.status_code}. Reason: {response.text}")
|
|
|
|
data = response.json()
|
|
df = pd.DataFrame(reversed(data["historicalData"]))
|
|
df["time"] = pd.to_datetime(df["time"])
|
|
df["yield"] = df["yield"].astype("float64")
|
|
df_deposits = pd.DataFrame(data["deposits"], columns=["out", "fee", "time"])
|
|
df_deposits["out"] = df_deposits["out"].astype("float64")
|
|
df_deposits["fee"] = df_deposits["fee"].astype("float64")
|
|
df_deposits["time"] = pd.to_datetime(df_deposits["time"])
|
|
df_deposits["Type"] = df_deposits.apply(
|
|
lambda row: "Deposit" if row.out > 0 else "Withdrawal", axis=1
|
|
)
|
|
df_deposits.columns = ["Amount [UST]", "Fee [UST]", "Date", "Type"]
|
|
df_deposits = df_deposits[["Type", "Amount [UST]", "Fee [UST]", "Date"]]
|
|
|
|
stats_str = f"""Current anchor APY is {data['currentRate']}%
|
|
Deposit amount in Anchor Earn of address {address} is {data["totalYield"]["ustHoldings"]} UST.
|
|
You already earned [bold]{df.iloc[-1, 1]}[/bold] UST in Anchor Earn.
|
|
Your deposit is generating approximately:
|
|
- {data["estimatedYield"]["perHour"]} UST hourly
|
|
- {data["estimatedYield"]["perDay"]} UST daily
|
|
- {data["estimatedYield"]["perWeek"]} UST weekly
|
|
- {data["estimatedYield"]["perMonth"]} UST monthly
|
|
- {data["estimatedYield"]["perYear"]} UST yearly"""
|
|
|
|
return df, df_deposits, stats_str
|