Files
OpenBB/openbb_terminal/cryptocurrency/crypto_models.py
Jeroen Bouma 0ee2ebcf1e Refractor stocks/fa by incorporating stocks/dd and making the menu less reliant on Yahoo Finance (#4055)
* I missed some sheet_name ones :)

* Move quote to main menu and combine yahoo finance commands

* Update stocks for quote

* First update to move yfinance away from main functionality

* Small updates

* Update tests to reflect changes

* Fix some little things

* Update docs a little too

* Remove the Due Diligence menu

* Update tests for new change

* Update fa and stocks with new text and move some stuff around

* Bye bye dd

* Pls work

* work..

* work..

* work..

* Work..|

* Add tests back in

* Remove tests

* Fix fix fix

* Remove tests to fix conflicts

* Improve the `stocks/search` command (#4084)

* Improve search command

* Make it more intuitive

* Fix tests

* Update the docs

* Ok done

* Ok done 2

* Ok done 3

* Git update tests that failed

* Update commands with --sheet-name that didn't work (#4088)

* Update commands with --sheet-name that didn't work

* Fix test

* oops

* Adds auto completion to `news` (#4089)

* Fix plot look when using eval and add query to choices (#3881)

* convert index to datetime and update choices

* uncomment economy integration test

* fix treasury concat bug

* fix datasets concat on duplciates

* Lock ruff version so that new lints dont break our CI (#3905)

* Lock ruff version so that new lints dont break our CI

* Bumped pre-commit ruff version

* returning always a dataframe

* Revert "returning always a dataframe"

This reverts commit d5dbf3132f.

* quick fix to auto complete args

---------

Co-authored-by: montezdesousa <79287829+montezdesousa@users.noreply.github.com>
Co-authored-by: Colin Delahunty <72827203+colin99d@users.noreply.github.com>
Co-authored-by: James Maslek <jmaslek11@gmail.com>

* Hotfix/Windows-CLI (#4087)

* init

* Update windows10_build.yml

* Update windows10_build.yml

* Update windows10_build.yml

* Update windows10_build.yml

* Update windows10_build.yml

* Update windows10_build.yml

* oops

---------

Co-authored-by: James Maslek <jmaslek11@gmail.com>

* Adds end date to `forex/load` (#4077)

* Fix plot look when using eval and add query to choices (#3881)

* convert index to datetime and update choices

* uncomment economy integration test

* fix treasury concat bug

* fix datasets concat on duplciates

* Lock ruff version so that new lints dont break our CI (#3905)

* Lock ruff version so that new lints dont break our CI

* Bumped pre-commit ruff version

* returning always a dataframe

* Revert "returning always a dataframe"

This reverts commit d5dbf3132f.

* adding end date to the forex load

* added some tests

* added example

* always show msg

* rewriting test

* updating tests

* updating tests

* Redo load tests

---------

Co-authored-by: montezdesousa <79287829+montezdesousa@users.noreply.github.com>
Co-authored-by: Colin Delahunty <72827203+colin99d@users.noreply.github.com>
Co-authored-by: James Maslek <jmaslek11@gmail.com>

* Update tests to reflect changes

* work..

* Remove tests

* Fix fix fix

* Remove tests

* Update the whole test folder

* Small updates

* Revert change

* Update eodhd to reflect it requires a paid plan and update tests

* Fix all the tests

* Update tests

* Update integration tests

* Removing tests so no whining happens

* ADD ALL THE TESTS

* Fix linting

* gitignore.  thanks jer

* Add back dd and redirect to fa

* Update to just display a message

* Update OpenBB SDK commands

* Fixing issues with exporting

* Fix ruff messing up

* Fix tests

* Fix the tests by disabling isort to run on tests folder

---------

Co-authored-by: Jeroen Bouma <jeroenbouma@Jeroens-MacBook-Pro.local>
Co-authored-by: James Maslek <jmaslek11@gmail.com>
Co-authored-by: Henrique Joaquim <h.joaquim@campus.fct.unl.pt>
Co-authored-by: montezdesousa <79287829+montezdesousa@users.noreply.github.com>
Co-authored-by: Colin Delahunty <72827203+colin99d@users.noreply.github.com>
Co-authored-by: teh_coderer <me@tehcoderer.com>
2023-02-06 23:24:15 +01:00

147 lines
4.4 KiB
Python

import difflib
import pandas as pd
from openbb_terminal.rich_config import console
# TODO: Find better algorithm then difflib.get_close_matches to find most similar coins
def find(
query: str,
source: str = "CoinGecko",
key: str = "symbol",
limit: int = 10,
) -> pd.DataFrame:
"""Find similar coin by coin name,symbol or id.
If you don't know exact name or id of the Coin at CoinGecko CoinPaprika, Binance or Coinbase
you use this command to display coins with similar name, symbol or id to your search query.
Example: coin name is something like "polka". So I can try: find -c polka -k name -t 25
It will search for coin that has similar name to polka and display top 25 matches.
Parameters
----------
query: str
Cryptocurrency
source: str
Data source of coins. CoinGecko or CoinPaprika or Binance or Coinbase
key: str
Searching key (symbol, id, name)
limit: int
Number of records to display
Returns
-------
pd.DataFrame
DataFrame with 'limit' similar coins
Examples
--------
>>> from openbb_terminal.sdk import openbb
>>> openbb.crypto.find("polka", "CoinGecko", "name", 25)
"""
df = pd.DataFrame()
if source == "CoinGecko":
df = _find_CoinGecko(key=key, query=query, limit=limit)
elif source == "CoinPaprika":
df = _find_CoinPaprika(key=key, query=query, limit=limit)
elif source == "Binance":
df = _find_Binance(key=key, query=query, limit=limit)
elif source == "Coinbase":
df = _find_Coinbase(key=key, query=query, limit=limit)
else:
console.print(
"Couldn't execute find methods for CoinPaprika, Binance, Coinbase or CoinGecko\n"
)
return df
def _find_CoinGecko(key: str, query: str, limit: int) -> pd.DataFrame:
# pylint: disable=C0415
from openbb_terminal.cryptocurrency.discovery.pycoingecko_model import get_coin_list
coins_df = get_coin_list()
coins_list = coins_df[key].to_list()
if key in ["symbol", "id"]:
query = query.lower()
sim = difflib.get_close_matches(query, coins_list, limit)
df = pd.Series(sim).to_frame().reset_index()
df.columns = ["index", key]
coins_df.drop("index", axis=1, inplace=True)
df = df.merge(coins_df, on=key)
return df
def _find_CoinPaprika(key: str, query: str, limit: int) -> pd.DataFrame:
# pylint: disable=C0415
from openbb_terminal.cryptocurrency.due_diligence.coinpaprika_model import (
get_coin_list,
)
coins_df = get_coin_list()
coins_list = coins_df[key].to_list()
keys = {"name": "title", "symbol": "upper", "id": "lower"}
func_key = keys[key]
query = getattr(query, str(func_key))()
sim = difflib.get_close_matches(query, coins_list, limit)
df = pd.Series(sim).to_frame().reset_index()
df.columns = ["index", key]
df = df.merge(coins_df, on=key)
return df
def _find_Binance(key: str, query: str, limit: int) -> pd.DataFrame:
# pylint: disable=C0415
from openbb_terminal.cryptocurrency.cryptocurrency_helpers import load_binance_map
from openbb_terminal.cryptocurrency.discovery.pycoingecko_model import get_coin_list
# TODO: Fix it in future. Determine if user looks for symbol like ETH or ethereum
if len(query) > 5:
key = "id"
coins_df_gecko = get_coin_list()
coins_df_bin = load_binance_map()
coins = pd.merge(coins_df_bin, coins_df_gecko[["id", "name"]], how="left", on="id")
coins_list = coins[key].to_list()
sim = difflib.get_close_matches(query, coins_list, limit)
df = pd.Series(sim).to_frame().reset_index()
df.columns = ["index", key]
df = df.merge(coins, on=key)
return df
def _find_Coinbase(key: str, query: str, limit: int) -> pd.DataFrame:
# pylint: disable=C0415
from openbb_terminal.cryptocurrency.cryptocurrency_helpers import load_coinbase_map
from openbb_terminal.cryptocurrency.discovery.pycoingecko_model import get_coin_list
if len(query) > 5:
key = "id"
coins_df_gecko = get_coin_list()
coins_df_bin = load_coinbase_map()
coins = pd.merge(coins_df_bin, coins_df_gecko[["id", "name"]], how="left", on="id")
coins_list = coins[key].to_list()
sim = difflib.get_close_matches(query, coins_list, limit)
df = pd.Series(sim).to_frame().reset_index()
df.columns = ["index", key]
df = df.merge(coins, on=key)
return df