Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Coins #11

Merged
merged 4 commits into from
Apr 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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__ = 'itzmetariq@gmail.com'
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
Loading