Files
OpenBB/openbb_terminal/cryptocurrency/pyth_view.py
jose-donato 1661ddd440 Integrate live feeds from Pyth (#2178)
* added dependency

* added pyth models

* dependencies

* docs

* some improvements to this pyth command (#2433)

* some improvements to this pyth command

* minor improv

* dependencies

* tests

Co-authored-by: DidierRLopes <dro.lopes@campus.fct.unl.pt>; COlin
2022-09-21 13:32:03 +01:00

32 lines
973 B
Python

# pylint: disable= C0301
import asyncio
import logging
from openbb_terminal.cryptocurrency.pyth_model import get_price
from openbb_terminal.decorators import log_start_end
from openbb_terminal.rich_config import console
logger = logging.getLogger(__name__)
@log_start_end(log=logger)
def display_price(symbol: str) -> None:
"""Displays live price from pyth live feed [Source: https://pyth.network/]
Parameters
----------
symbol : str
Symbol of the asset to get price for
"""
try:
while True:
price, confidence, previous_price = asyncio.run(get_price(symbol))
console.print(
f"{symbol} = {'[red]' if previous_price >= price else '[green]'}"
f"{price}{'[/red]' if previous_price >= price else '[/green]'} ± {confidence}",
end="\r",
)
except KeyboardInterrupt:
print(f"\n\nStopped watching {symbol} price and confidence interval\n")