From 47a7bebf7a3e44e30dcae358ce18422170b3c491 Mon Sep 17 00:00:00 2001 From: Tarique Anwer Date: Sat, 27 Apr 2024 20:53:00 +0530 Subject: [PATCH 1/4] coins eps added --- defillama/__version__.py | 2 +- defillama/defillama.py | 59 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+), 1 deletion(-) diff --git a/defillama/__version__.py b/defillama/__version__.py index 1a084aa..46f7ecf 100644 --- a/defillama/__version__.py +++ b/defillama/__version__.py @@ -2,7 +2,7 @@ __title__ = 'DeFiLlama' __description__ = 'Unofficial DeFi Llama API client.' __url__ = 'https://github.com/itzmestar/DeFiLlama' -__version__ = '2.1.1' +__version__ = '2.2.0' __build__ = 0x010001 __author__ = 'Tarique Anwer' __author_email__ = 'itzmetariq@gmail.com' diff --git a/defillama/defillama.py b/defillama/defillama.py index a1b96d4..c78f4d9 100644 --- a/defillama/defillama.py +++ b/defillama/defillama.py @@ -117,6 +117,65 @@ def get_chains_current_tvl(self): return self._get(path) + # ##### Coins EPs ###### # + def get_token_current_prices(self, coins: str, searchWidth: str = '4h'): + """ + Get current prices of tokens by contract address + """ + path = f'/prices/current/{coins}' + params = { + 'searchWidth': searchWidth + } + + return self._get(path, params=params) + + def get_token_historical_prices(self, coins: str, timestamp: int, searchWidth: str = '4h'): + """ + Get historical prices of tokens by contract address + """ + path = f'/prices/historical/{timestamp}/{coins}' + params = { + 'searchWidth': searchWidth + } + + return self._get(path, params=params) + + def get_batch_historical_prices(self, coins: str, searchWidth: str = '600'): + """ + Get historical prices of tokens by contract address + """ + path = f'https://coins.llama.fi/batchHistorical' + params = { + 'coins': coins, + 'searchWidth': searchWidth + } + + return self._get(path, params=params, full_url=True) + + def get_token_prices_at_intervals( + self, + coins: str, + start: int, + end: int, + span: int = 0, + period: str = '2d', + searchWidth: str = '600' + ): + """ + Get token prices at regular time intervals + """ + path = f"/chart/{coins}" + + params = { + 'start': start, + 'end': end, + 'span': span, + 'period': period, + 'searchWidth': searchWidth + } + + return self._get(path, params=params) + # ##### Yields EPs ###### # def get_pools(self): From dd5392457e16098ffd10a9e1166daff568e4e27e Mon Sep 17 00:00:00 2001 From: Tarique Anwer Date: Sat, 27 Apr 2024 20:58:29 +0530 Subject: [PATCH 2/4] add get_percentage_price_change --- defillama/defillama.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/defillama/defillama.py b/defillama/defillama.py index c78f4d9..d3625a6 100644 --- a/defillama/defillama.py +++ b/defillama/defillama.py @@ -176,6 +176,19 @@ def get_token_prices_at_intervals( return self._get(path, params=params) + def get_percentage_price_change(self, coins: str, timestamp: int, lookForward: bool = False, period: str = '3w'): + """ + Get percentage change in price over time + """ + path = f"/percentage/{coins}" + + params = { + 'timestamp': timestamp, + 'lookForward': lookForward, + 'period': period + } + + return self._get(path, params=params) # ##### Yields EPs ###### # def get_pools(self): From 0e0b71d0d6910ba136081622f021106704184a3c Mon Sep 17 00:00:00 2001 From: Tarique Anwer Date: Sat, 27 Apr 2024 21:07:23 +0530 Subject: [PATCH 3/4] add get_earliest_ts_price --- defillama/defillama.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/defillama/defillama.py b/defillama/defillama.py index d3625a6..02a2ede 100644 --- a/defillama/defillama.py +++ b/defillama/defillama.py @@ -189,6 +189,15 @@ def get_percentage_price_change(self, coins: str, timestamp: int, lookForward: b } return self._get(path, params=params) + + def get_earliest_ts_price(self, coins: str): + """ + Get earliest timestamp price record for coins + """ + path = f"/percentage/{coins}" + + return self._get(path) + # ##### Yields EPs ###### # def get_pools(self): From 110e7f77d8916aed9b477b586993ddf7fede045a Mon Sep 17 00:00:00 2001 From: Tarique Anwer Date: Sat, 27 Apr 2024 22:14:01 +0530 Subject: [PATCH 4/4] added get_closest_ts_block --- defillama/defillama.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/defillama/defillama.py b/defillama/defillama.py index 02a2ede..d61ec90 100644 --- a/defillama/defillama.py +++ b/defillama/defillama.py @@ -198,6 +198,14 @@ def get_earliest_ts_price(self, coins: str): return self._get(path) + def get_closest_ts_block(self, chain: str, timestamp: int): + """ + Get the closest block to a timestamp + """ + path = f"/block/{chain}/{timestamp}" + + return self._get(path) + # ##### Yields EPs ###### # def get_pools(self):