From 07f36a01a513df382dfbb32ccf0aaa8ecde4be5b Mon Sep 17 00:00:00 2001 From: Hayot Date: Fri, 17 Jan 2025 10:58:53 +0900 Subject: [PATCH 1/5] fix: remove defillama pkg --- datamaxi/defillama/__init__.py | 380 --------------------------------- 1 file changed, 380 deletions(-) delete mode 100644 datamaxi/defillama/__init__.py diff --git a/datamaxi/defillama/__init__.py b/datamaxi/defillama/__init__.py deleted file mode 100644 index 82f8e75..0000000 --- a/datamaxi/defillama/__init__.py +++ /dev/null @@ -1,380 +0,0 @@ -from typing import Any, List, Union -import pandas as pd -from datamaxi.api import API -from datamaxi.lib.utils import check_required_parameter -from datamaxi.lib.utils import check_at_least_one_set_parameters -from datamaxi.lib.utils import postprocess -from datamaxi.lib.constants import BASE_URL - - -class Defillama(API): - """Client to fetch Defillama data from DataMaxi+ API.""" - - def __init__(self, api_key=None, **kwargs: Any): - """Initialize the object. - - Args: - api_key (str): The DataMaxi+ API key - **kwargs: Keyword arguments used by `datamaxi.api.API`. - """ - if "base_url" not in kwargs: - kwargs["base_url"] = BASE_URL - super().__init__(api_key, **kwargs) - - def protocols(self) -> List[str]: - """Get supported protocols - - `GET /api/v1/defillama/protocol` - - - - Returns: - List of supported protocols - """ - url_path = "/api/v1/defillama/protocol" - return self.query(url_path) - - def chains(self) -> List[str]: - """Get supported chains - - `GET /api/v1/defillama/chain` - - - - Returns: - List of supported chains - """ - url_path = "/api/v1/defillama/chain" - return self.query(url_path) - - def pools(self) -> List[str]: - """Get supported pools - - `GET /api/v1/defillama/pool` - - - - Returns: - List of supported pools - """ - url_path = "/api/v1/defillama/pool" - return self.query(url_path) - - def stablecoins(self) -> List[str]: - """Get supported stablecoins - - `GET /api/v1/defillama/stablecoin` - - - - Returns: - List of supported stablecoins - """ - url_path = "/api/v1/defillama/stablecoin" - return self.query(url_path) - - @postprocess() - def tvl( - self, protocol: str = None, chain: str = None, pandas: bool = True - ) -> Union[List, pd.DataFrame]: - """Get total TVL across all chains and protocols - - `GET /api/v1/defillama/tvl` - - - - Args: - protocol (str): Protocol name - chain (str): Chain name - pandas (bool): Return data as pandas DataFrame - - Returns: - Timeseries of total TVL - """ - params = {} - if protocol is not None: - params["protocol"] = protocol - - if chain is not None: - params["chain"] = chain - - url_path = "/api/v1/defillama/tvl" - return self.query(url_path, params) - - @postprocess(num_index=2) - def tvl_detail( - self, protocol: str, chain: str = None, token: bool = False, pandas: bool = True - ) -> Union[List, pd.DataFrame]: - """Get TVL detail for given protocol and chain - - `GET /api/v1/defillama/tvl/detail` - - - - Args: - protocol (str): Protocol name - chain (str): Chain name - token (bool): Return token amount (return by default USD) - pandas (bool): Return data as pandas DataFrame - - Returns: - Timeseries of TVL detail for a given protocol and chain - """ - check_required_parameter(protocol, "protocol") - params = {"protocol": protocol} - - if chain is not None: - params["chain"] = chain - - if token: - params["token"] = str(token).lower() - - url_path = "/api/v1/defillama/tvl/detail" - return self.query(url_path, params) - - @postprocess() - def mcap(self, protocol: str, pandas: bool = True) -> Union[List, pd.DataFrame]: - """Get market cap for given protocol - - `GET /api/v1/defillama/mcap` - - - - Args: - protocol (str): Protocol name - pandas (bool): Return data as pandas DataFrame - - Returns: - Timeseries of market cap for given protocol - """ - check_required_parameter(protocol, "protocol") - params = { - "protocol": protocol, - } - return self.query("/api/v1/defillama/mcap", params) - - @postprocess() - def pool_yield(self, poolId: str, pandas: bool = True) -> Union[List, pd.DataFrame]: - """Get yield for given pool - - `GET /api/v1/defillama/pool/yield` - - - - Args: - poolId (str): Pool ID - pandas (bool): Return data as pandas DataFrame - - Returns: - Timeseries of yield for given pool - """ - check_required_parameter(poolId, "poolId") - params = { - "poolId": poolId, - } - return self.query("/api/v1/defillama/pool/yield", params) - - @postprocess() - def stablecoin_mcap( - self, stablecoin: str, chain: str = None, pandas: bool = True - ) -> Union[List, pd.DataFrame]: - """Get market cap for given stablecoin and chain - - `GET /api/v1/defillama/stablecoin/mcap` - - - - Args: - stablecoin (str): Stablecoin name - chain (str): Chain name (optional) - pandas (bool): Return data as pandas DataFrame - - Returns: - Timeseries of market cap for given stablecoin and chain - """ - check_required_parameter(stablecoin, "stablecoin") - params = { - "stablecoin": stablecoin, - } - - if chain is not None: - params["chain"] = chain - - return self.query("/api/v1/defillama/stablecoin/mcap", params) - - @postprocess() - def stablecoin_price( - self, stablecoin: str, pandas: bool = True - ) -> Union[List, pd.DataFrame]: - """Get price for given stablecoin - - `GET /api/v1/defillama/stablecoin/price` - - - - Args: - stablecoin (str): Stablecoin name - pandas (bool): Return data as pandas DataFrame - - Returns: - Timeseries of stablecoin prices - """ - check_required_parameter(stablecoin, "stablecoin") - params = { - "stablecoin": stablecoin, - } - return self.query("/api/v1/defillama/stablecoin/price", params) - - @postprocess() - def fee( - self, - protocol: str = None, - chain: str = None, - daily: bool = True, - pandas: bool = True, - ) -> Union[List, pd.DataFrame]: - """Get fee for given protocol or chain - - `GET /api/v1/defillama/fee` - - - - Args: - protocol (str): Protocol name - chain (str): Chain name - daily (bool): Daily fee or total fee - pandas (bool): Return data as pandas DataFrame - - Returns: - Timeseries of protocol or fees - """ - check_required_parameter(daily, "daily") - params = { - "daily": str(daily).lower(), - } - - if not ((protocol is None) ^ (chain is None)): - raise ValueError("Either protocols or chains should be provided") - - if protocol is not None: - check_required_parameter(protocol, "protocol") - params["protocol"] = protocol - elif chain is not None: - check_required_parameter(chain, "chain") - params["chain"] = chain - - return self.query("/api/v1/defillama/fee", params) - - @postprocess() - def revenue( - self, - protocol: str = None, - chain: str = None, - daily: bool = True, - pandas: bool = True, - ) -> Union[List, pd.DataFrame]: - """Get revenue for given protocol or chain - - `GET /api/v1/defillama/revenue` - - - - Args: - protocol (str): Protocol name - chain (str): Chain name - daily (bool): Daily revenue or total revenue - pandas (bool): Return data as pandas DataFrame - - Returns: - Timeseries of protocol or chain revenues - """ - check_required_parameter(daily, "daily") - params = { - "daily": str(daily).lower(), - } - - if not ((protocol is None) ^ (chain is None)): - raise ValueError("Either protocols or chains should be provided") - - if protocol is not None: - check_required_parameter(protocol, "protocol") - params["protocol"] = protocol - elif chain is not None: - check_required_parameter(chain, "chain") - params["chain"] = chain - - return self.query("/api/v1/defillama/revenue", params) - - @postprocess(num_index=-1) - def fee_detail( - self, - protocol: str = None, - chain: str = None, - daily: bool = True, - pandas: bool = True, - ) -> Union[List, pd.DataFrame]: - """Get fee detail for given protocol and chain - - `GET /api/v1/defillama/fee/detail` - - - - Args: - protocol (str): Protocol name - chain (str): Chain name - daily (bool): Daily fee or total fee - pandas (bool): Return data as pandas DataFrame - - Returns: - Timeseries of fee detail for a given protocol and chain - """ - check_required_parameter(daily, "daily") - params = { - "daily": str(daily).lower(), - } - - check_at_least_one_set_parameters([[protocol, "protocol"], [chain, "chain"]]) - if protocol is not None: - params["protocol"] = protocol - - if chain is not None: - params["chain"] = chain - - return self.query("/api/v1/defillama/fee/detail", params) - - @postprocess(num_index=-1) - def revenue_detail( - self, - protocol: str = None, - chain: str = None, - daily: bool = True, - pandas: bool = True, - ) -> Union[List, pd.DataFrame]: - """Get revenue detail for given protocol and chain - - `GET /api/v1/defillama/revenue/detail` - - - - Args: - protocol (str): Protocol name - chain (str): Chain name - daily (bool): Daily revenue or total revenue - pandas (bool): Return data as pandas DataFrame - - Returns: - Timeseries of revenue detail for a given protocol and chain - """ - check_required_parameter(daily, "daily") - params = { - "daily": str(daily).lower(), - } - - check_at_least_one_set_parameters([[protocol, "protocol"], [chain, "chain"]]) - if protocol is not None: - params["protocol"] = protocol - - if chain is not None: - params["chain"] = chain - - return self.query("/api/v1/defillama/revenue/detail", params) From f78477b74a5a318d80a104cc9a18b6facf683d4f Mon Sep 17 00:00:00 2001 From: Hayot Date: Fri, 17 Jan 2025 10:59:04 +0900 Subject: [PATCH 2/5] fix: remove tests --- tests/defillama/test_defillama_chains.py | 24 ----------------- tests/defillama/test_defillama_pools.py | 24 ----------------- tests/defillama/test_defillama_protocols.py | 24 ----------------- tests/defillama/test_defillama_stablecoins.py | 24 ----------------- tests/defillama/test_defillama_tvl.py | 27 ------------------- 5 files changed, 123 deletions(-) delete mode 100644 tests/defillama/test_defillama_chains.py delete mode 100644 tests/defillama/test_defillama_pools.py delete mode 100644 tests/defillama/test_defillama_protocols.py delete mode 100644 tests/defillama/test_defillama_stablecoins.py delete mode 100644 tests/defillama/test_defillama_tvl.py diff --git a/tests/defillama/test_defillama_chains.py b/tests/defillama/test_defillama_chains.py deleted file mode 100644 index 4ff200b..0000000 --- a/tests/defillama/test_defillama_chains.py +++ /dev/null @@ -1,24 +0,0 @@ -import responses - -from datamaxi.defillama import Defillama as Client -from tests.util import random_str -from tests.util import mock_http_response - - -mock_item = ["a", "b", "c"] - -key = random_str() -client = Client(key) - - -@mock_http_response( - responses.GET, - "/v1/defillama/chain", - mock_item, - 200, -) -def test_defillama_chains(): - """Tests the API endpoint to get Defillama chains.""" - - response = client.chains() - response.should.equal(mock_item) diff --git a/tests/defillama/test_defillama_pools.py b/tests/defillama/test_defillama_pools.py deleted file mode 100644 index aa09f7d..0000000 --- a/tests/defillama/test_defillama_pools.py +++ /dev/null @@ -1,24 +0,0 @@ -import responses - -from datamaxi.defillama import Defillama as Client -from tests.util import random_str -from tests.util import mock_http_response - - -mock_item = ["a", "b", "c"] - -key = random_str() -client = Client(key) - - -@mock_http_response( - responses.GET, - "/v1/defillama/pool", - mock_item, - 200, -) -def test_defillama_pools(): - """Tests the API endpoint to get Defillama pools.""" - - response = client.pools() - response.should.equal(mock_item) diff --git a/tests/defillama/test_defillama_protocols.py b/tests/defillama/test_defillama_protocols.py deleted file mode 100644 index e2221dc..0000000 --- a/tests/defillama/test_defillama_protocols.py +++ /dev/null @@ -1,24 +0,0 @@ -import responses - -from datamaxi.defillama import Defillama as Client -from tests.util import random_str -from tests.util import mock_http_response - - -mock_item = ["a", "b", "c"] - -key = random_str() -client = Client(key) - - -@mock_http_response( - responses.GET, - "/v1/defillama/protocol", - mock_item, - 200, -) -def test_defillama_protocols(): - """Tests the API endpoint to get Defillama protocols.""" - - response = client.protocols() - response.should.equal(mock_item) diff --git a/tests/defillama/test_defillama_stablecoins.py b/tests/defillama/test_defillama_stablecoins.py deleted file mode 100644 index 0dd7ae8..0000000 --- a/tests/defillama/test_defillama_stablecoins.py +++ /dev/null @@ -1,24 +0,0 @@ -import responses - -from datamaxi.defillama import Defillama as Client -from tests.util import random_str -from tests.util import mock_http_response - - -mock_item = ["a", "b", "c"] - -key = random_str() -client = Client(key) - - -@mock_http_response( - responses.GET, - "/v1/defillama/stablecoin", - mock_item, - 200, -) -def test_defillama_stablecoins(): - """Tests the API endpoint to get Defillama stablecoins.""" - - response = client.stablecoins() - response.should.equal(mock_item) diff --git a/tests/defillama/test_defillama_tvl.py b/tests/defillama/test_defillama_tvl.py deleted file mode 100644 index 836de70..0000000 --- a/tests/defillama/test_defillama_tvl.py +++ /dev/null @@ -1,27 +0,0 @@ -import responses - -from datamaxi.defillama import Defillama as Client -from tests.util import random_str -from tests.util import mock_http_response - - -mock_item = [ - ["Timestamp", "Usd"], - ["03/30/2024 00:00:00", "97684389340.879684"], -] - -key = random_str() -client = Client(key) - - -@mock_http_response( - responses.GET, - "/v1/defillama/tvl", - mock_item, - 200, -) -def test_defillama_tvl(): - """Tests the API endpoint to get Defillama tvls.""" - - response = client.tvl(pandas=False) - response.should.equal(mock_item) From ac4112f9159625aee5253dedd7d8cf8785934086 Mon Sep 17 00:00:00 2001 From: Hayot Date: Fri, 17 Jan 2025 10:59:18 +0900 Subject: [PATCH 3/5] fix: docs --- docs/defillama.md | 6 ------ 1 file changed, 6 deletions(-) delete mode 100644 docs/defillama.md diff --git a/docs/defillama.md b/docs/defillama.md deleted file mode 100644 index dd66537..0000000 --- a/docs/defillama.md +++ /dev/null @@ -1,6 +0,0 @@ -# Defillama - -::: datamaxi.defillama - options: - show_submodules: true - show_source: false From aca822cce9f701ea9604284e6bbd0b2113f20aaa Mon Sep 17 00:00:00 2001 From: Hayot Date: Fri, 17 Jan 2025 10:59:31 +0900 Subject: [PATCH 4/5] fix: readme --- README.md | 7 ------- mkdocs.yml | 1 - 2 files changed, 8 deletions(-) diff --git a/README.md b/README.md index 5d8d2fc..94e4be3 100644 --- a/README.md +++ b/README.md @@ -54,7 +54,6 @@ You may use environment variables to configure the SDK to avoid any inline boile DataMaxi+ Python package currently includes the following clients: - `Datamaxi` -- `Defillama` - `Naver` - `Google` @@ -65,9 +64,6 @@ First, import the clients, # Main client to access crypto trading data from datamaxi.datamaxi import Datamaxi -# DeFi -from datamaxi.defillama import Defillama - # Trend from datamaxi.naver import Naver from datamaxi.google import Google @@ -79,9 +75,6 @@ and initialize them. # Main client maxi = Datamaxi(api_key=api_key) -# DeFi -defillama = Defillama(api_key=api_key) - # Trend naver = Naver(api_key=api_key) google = Google(api_key=api_key) diff --git a/mkdocs.yml b/mkdocs.yml index 1a3bedd..1dd3f20 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -47,7 +47,6 @@ nav: - Naver Trend: naver-trend.md - Google Trend: google-trend.md - Telegram: telegram.md - - Defillama: defillama.md theme: name: material From e0aad36145f86b81a7e393af037f18f1f1a3d692 Mon Sep 17 00:00:00 2001 From: Hayot Date: Fri, 17 Jan 2025 11:26:42 +0900 Subject: [PATCH 5/5] fix: update version --- datamaxi/__version__.py | 2 +- pyproject.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/datamaxi/__version__.py b/datamaxi/__version__.py index 8b301a7..770bb8d 100644 --- a/datamaxi/__version__.py +++ b/datamaxi/__version__.py @@ -1 +1 @@ -__version__ = "0.23.0" +__version__ = "0.24.0" diff --git a/pyproject.toml b/pyproject.toml index 288c679..c5545e4 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "datamaxi" -version = "0.23.0" +version = "0.24.0" authors = [ { name="Bisonai", email="business@bisonai.com" }, ]