mirror of
https://github.com/OpenBB-finance/OpenBB.git
synced 2026-10-28 04:52:07 +00:00
* spacing before and after rich tables * fix menus to have standard UI * fix tests * fix tests * fix tests
50 lines
1.3 KiB
Python
50 lines
1.3 KiB
Python
"""AlphaVantage Forex View."""
|
|
__docformat__ = "numpy"
|
|
|
|
import logging
|
|
|
|
import pandas as pd
|
|
|
|
from openbb_terminal.decorators import check_api_key
|
|
from openbb_terminal.decorators import log_start_end
|
|
from openbb_terminal.forex import av_model
|
|
from openbb_terminal.helper_funcs import print_rich_table
|
|
from openbb_terminal.rich_config import console
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
@log_start_end(log=logger)
|
|
@check_api_key(["API_KEY_ALPHAVANTAGE"])
|
|
def display_quote(to_symbol: str, from_symbol: str):
|
|
"""Display current forex pair exchange rate.
|
|
|
|
Parameters
|
|
----------
|
|
to_symbol : str
|
|
To symbol
|
|
from_symbol : str
|
|
From forex symbol
|
|
"""
|
|
quote = av_model.get_quote(to_symbol, from_symbol)
|
|
|
|
if not bool(quote) or "Note" in quote:
|
|
if "Note" in quote:
|
|
console.print(quote["Note"])
|
|
console.print(
|
|
"\n[red]"
|
|
+ "No historical data loaded.\n"
|
|
+ "Make sure 'av' supports the requested pair and you aren't hitting your API call limits."
|
|
+ "[/red]\n"
|
|
)
|
|
return
|
|
|
|
df = pd.DataFrame.from_dict(quote)
|
|
df.index = df.index.to_series().apply(lambda x: x[3:]).values
|
|
df = df.iloc[[0, 2, 5, 4, 7, 8]]
|
|
print_rich_table(
|
|
df,
|
|
show_index=True,
|
|
title=f"[bold]{from_symbol}/{to_symbol} Quote [/bold]",
|
|
)
|