Skip to content

Commit

Permalink
Merge pull request #11 from itzmestar/coins
Browse files Browse the repository at this point in the history
Coins
  • Loading branch information
itzmestar committed Apr 27, 2024
2 parents edba4bb + 110e7f7 commit 6b1a885
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 1 deletion.
2 changes: 1 addition & 1 deletion defillama/__version__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__ = '[email protected]'
Expand Down
89 changes: 89 additions & 0 deletions defillama/defillama.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,95 @@ 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)

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)

def get_earliest_ts_price(self, coins: str):
"""
Get earliest timestamp price record for coins
"""
path = f"/percentage/{coins}"

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):
Expand Down

0 comments on commit 6b1a885

Please sign in to comment.