mirror of
https://github.com/OpenBB-finance/OpenBB.git
synced 2026-11-05 17:01:58 +00:00
* bring dashboards and reports menus one step above * remove checkpoints * add notebooks again
161 lines
4.4 KiB
Plaintext
Vendored
161 lines
4.4 KiB
Plaintext
Vendored
{
|
|
"cells": [
|
|
{
|
|
"cell_type": "markdown",
|
|
"id": "6e198e40-0c33-45b3-a79b-2d9ee9eff7b9",
|
|
"metadata": {
|
|
"tags": []
|
|
},
|
|
"source": [
|
|
"# Cryptocurrency exchange rates to USD ($)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "da655985-c9b7-492e-aefa-fbe3bc1865d5",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"import json\n",
|
|
"import os\n",
|
|
"\n",
|
|
"import ipywidgets as ipw\n",
|
|
"from IPython.display import display\n",
|
|
"import pandas as pd\n",
|
|
"\n",
|
|
"from openbb_terminal import api as openbb\n",
|
|
"\n",
|
|
"ipw.HTML(f\"<style>{openbb.widgets.price_card_stylesheet()}</style>\")"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "dcbbf867-af50-4d06-ae5c-7c09647aa55d",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"COIN_LIST = (\n",
|
|
" \"BTC,ETH,USDT,BNB,USDC,XRP,LUNA,ADA,\"\n",
|
|
" + \"SOL,AVAX,DOT,BUSD,DOGE,UST,SHIB,WBTC,\"\n",
|
|
" + \"MATIC,CRO,DAI,LTC,ATOM,NEAR,LINK,BCH,\"\n",
|
|
" + \"UNI,TRX,FTT,ETC,LEO,ALGO,XLM,MANA,\"\n",
|
|
" + \"BTCB,HBAR,EGLD,ICP,SAND,XMR,WAVES,VET,\"\n",
|
|
" + \"APE,FIL,FTM,AXS,THETA,KLAY,XTZ,RUNE\"\n",
|
|
").split(\",\")\n",
|
|
"exchange_rates = {}"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "deeeb80a-3675-44fb-9a1b-2325d8da4e7d",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"def get_exchange_rate(coin: str, days: int = 2):\n",
|
|
" \"\"\"Get exchange rate for a cryptocurrency agains USD.\"\"\"\n",
|
|
" (_, _, _, _, current_df, _,) = openbb.crypto.load(\n",
|
|
" coin=coin,\n",
|
|
" source=\"cp\",\n",
|
|
" days=days,\n",
|
|
" vs=\"usd\",\n",
|
|
" interval=\"1day\",\n",
|
|
" should_load_ta_data=True,\n",
|
|
" )\n",
|
|
" price_color = \"neutral_color\"\n",
|
|
" if current_df[\"Close\"].iloc[-1] > current_df[\"Close\"].iloc[-2]:\n",
|
|
" price_color = \"up_color\"\n",
|
|
" elif current_df[\"Close\"].iloc[-1] < current_df[\"Close\"].iloc[-2]:\n",
|
|
" price_color = \"down_color\"\n",
|
|
" price = str(current_df[\"Close\"].iloc[-1])[:7]\n",
|
|
"\n",
|
|
" return price, price_color"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "18acf5cb-6cbf-484d-8042-107c030098de",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"def show_rates(btn):\n",
|
|
" \"\"\"Show exchange rates in grid box widget.\"\"\"\n",
|
|
" grid.children = ()\n",
|
|
" for coin in COIN_LIST:\n",
|
|
" if coin not in exchange_rates.keys():\n",
|
|
" exchange_rates[coin] = {\"price\": None, \"color\": None}\n",
|
|
" try:\n",
|
|
" price, price_color = get_exchange_rate(coin=coin)\n",
|
|
" except:\n",
|
|
" price, price_color = \"-------\", \"neutral_color\"\n",
|
|
" widgets = list(grid.children)\n",
|
|
" widgets.append(\n",
|
|
" ipw.HTML(\n",
|
|
" openbb.widgets.price_card(\n",
|
|
" ticker=coin,\n",
|
|
" price=price,\n",
|
|
" price_color=price_color,\n",
|
|
" )\n",
|
|
" )\n",
|
|
" )\n",
|
|
" grid.children = tuple(widgets)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "cf2021e9-de8a-466e-b341-fcd6abda64b5",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"update_rates = ipw.Button(description=\"Update rates\")\n",
|
|
"update_rates.on_click(show_rates)\n",
|
|
"header = ipw.HBox([update_rates])\n",
|
|
"\n",
|
|
"layout = ipw.Layout(grid_template_columns=\"1fr \" * 8)\n",
|
|
"grid = ipw.GridBox(\n",
|
|
" [],\n",
|
|
" layout=layout,\n",
|
|
")\n",
|
|
"\n",
|
|
"display(header, grid)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "19dfcbfe-eaec-406e-bb3c-72d1b3538a6e",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": []
|
|
}
|
|
],
|
|
"metadata": {
|
|
"kernelspec": {
|
|
"display_name": "Python 3 (ipykernel)",
|
|
"language": "python",
|
|
"name": "python3"
|
|
},
|
|
"language_info": {
|
|
"codemirror_mode": {
|
|
"name": "ipython",
|
|
"version": 3
|
|
},
|
|
"file_extension": ".py",
|
|
"mimetype": "text/x-python",
|
|
"name": "python",
|
|
"nbconvert_exporter": "python",
|
|
"pygments_lexer": "ipython3",
|
|
"version": "3.8.12"
|
|
},
|
|
"voila": {
|
|
"theme": "dark"
|
|
}
|
|
},
|
|
"nbformat": 4,
|
|
"nbformat_minor": 5
|
|
}
|