diff --git a/.gitignore b/.gitignore index 4b982d0..db0cb9f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ dist -defi.egg-info \ No newline at end of file +defi.egg-info +defi/__pycache__/ \ No newline at end of file diff --git a/defi/defi_tools.py b/defi/defi_tools.py index 9164e75..c8cb5b1 100644 --- a/defi/defi_tools.py +++ b/defi/defi_tools.py @@ -158,18 +158,19 @@ def geckoPrice(tokens, quote): -def geckoList(page=1, per_page=250): +def geckoList(page=1, per_page=250, ids=None): """Returns list of full detail conGecko currency list Args: page (int, optional): number of pages per_page (int, optional): number of records per page + ids (string, optional): The ids of the coin, comma separated crytocurrency symbols (base). refers to /coins/list Returns: DataFrame: list of full detail conGecko currency list """ url = "https://api.coingecko.com/api/v3/coins/markets" - params = {"vs_currency":"usd", "order":"market_cap_desc", "per_page":per_page, "page":page} + params = {"vs_currency":"usd", "order":"market_cap_desc", "per_page":per_page, "page":page, "ids":ids} r = requests.get(url, params).json() df = pd.DataFrame(r) df.set_index('symbol', inplace=True) diff --git a/test/Defi_toolsTestCase.py b/test/Defi_toolsTestCase.py new file mode 100644 index 0000000..e021fc4 --- /dev/null +++ b/test/Defi_toolsTestCase.py @@ -0,0 +1,16 @@ +import unittest +import defi.defi_tools as dft + +class Defi_toolsTestCase(unittest.TestCase): + + def test_geckoList(self): + result = dft.geckoList() + self.assertEqual(len(result.index), 250) #default por page + + def test_geckoListIds(self): + result = dft.geckoList(ids="bitcoin,ethereum") + self.assertEqual(len(result.index), 2) + self.assertEqual(sorted(result['id'].tolist()), ["bitcoin", "ethereum"]) #alphabetically order + +if __name__ == "__main__": + unittest.main() \ No newline at end of file