Skip to content

Commit

Permalink
Merge pull request #8 from itzmestar/tvl
Browse files Browse the repository at this point in the history
new api eps
  • Loading branch information
itzmestar authored Apr 11, 2024
2 parents 15bf046 + 7231897 commit 9121517
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 77 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.6, 3.7, 3.8, 3.9]
python-version: [ 3.7, 3.8, 3.9, '3.10' ]

steps:
- uses: actions/checkout@v2
Expand Down
15 changes: 8 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@
[![Python 3.7](https://img.shields.io/badge/python-3.7-blue.svg)](https://www.python.org/downloads/release/python-370/)
[![Python 3.8](https://img.shields.io/badge/python-3.8-blue.svg)](https://www.python.org/downloads/release/python-380/)
[![Python 3.9](https://img.shields.io/badge/python-3.9-blue.svg)](https://www.python.org/downloads/release/python-390/)
[![Python 3.10](https://img.shields.io/badge/python-3.10-blue.svg)](https://www.python.org/downloads/release/python-310/)

[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)

[![Build](https://github.com/itzmestar/DeFiLlama/actions/workflows/python-package.yml/badge.svg)](https://github.com/itzmestar/DeFiLlama/actions/workflows/python-package.yml)

-------

### Unofficial [DeFi Llama API](https://defillama.com/home) client in python

For detailed information about the API endpoints, see [DeFi Llama API Documentation](https://docs.llama.fi/api)
For detailed information about the API endpoints, see [DeFi Llama API Documentation](https://defillama.com/docs/api)

### Installation:

Expand Down Expand Up @@ -45,9 +45,10 @@ response = llama.get_all_protocols()
# Get a protocol data
response = llama.get_protocol(name='uniswap')
# Get historical values of total TVL
response = llama.get_historical_tvl()
```
-------
#### Donate & Help maintain the library

[![Paypal](qrcode.png)](https://www.paypal.com/ncp/payment/KLFNJN7SH39EN)

# Get protocol TVL
response = llama.get_protocol_tvl(name='uniswap')
```
-------
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__ = '1.1.0'
__version__ = '2.0.0'
__build__ = 0x010001
__author__ = 'Tarique Anwer'
__author_email__ = 'itzmetariq@gmail.com'
Expand Down
30 changes: 18 additions & 12 deletions defillama/defillama.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,36 +74,42 @@ def get_protocol(self, name):

def get_historical_tvl(self):
"""
Returns historical values of the total sum of TVLs from all listed protocols.
Endpoint: GET /charts
Get Historical TVL of DeFi on all chains
:return: JSON response
"""
path = '/charts'
path = '/v2/historicalChainTvl'

return self._get(path)

def get_protocol_tvl(self, name):
def get_historical_tvl_chain(self, chain):
"""
Returns historical values of the total sum of TVLs from given protocol.
Mainly meant to make life easier for users that import data to spreadsheets
Endpoint: GET /tvl/{name}
Get Historical TVL of a chain
:return: JSON response
"""
path = f'/v2/historicalChainTvl/{chain}'

return self._get(path)

def get_protocol_current_tvl(self, protocol):
"""
Simplified endpoint that only returns a number, the current TVL of a protocol
:param: name : ID of the protocol to get (eg: uniswap, WBTC...).
This can be obtained from the /protocols endpoint
:return: JSON response
"""
path = f'/tvl/{name}'
path = f'/tvl/{protocol}'

return self._get(path)
def get_chains(self):

def get_chains_current_tvl(self):
"""
Returns list of current TVL of all chains.
Endpoint: GET /chain
:return: JSON response
"""
path = f'/chains/'
path = f'/v2/chains'

return self._get(path)
Binary file added qrcode.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
52 changes: 1 addition & 51 deletions tests/protocol_sample.json

Large diffs are not rendered by default.

33 changes: 28 additions & 5 deletions tests/test_defillama.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from unittest import TestCase

import pytest


Expand All @@ -21,7 +23,7 @@ def test_get_all_protocols(self, llama):

# @pytest.mark.skip(reason='TBD')
def test_get_protocol(self, llama, protocol_json):
response = llama.get_protocol(name='uniswap')
response = llama.get_protocol(name='aave')
assert type(response) is dict
for k in protocol_json.keys():
assert k in response
Expand All @@ -32,9 +34,30 @@ def test_get_historical_tvl(self, llama):
assert type(response) is list
for data in response:
assert 'date' in data
assert 'totalLiquidityUSD' in data
assert 'tvl' in data
break

# @pytest.mark.skip(reason='TBD')
def test_get_protocol_tvl(self, llama):
response = llama.get_protocol_tvl(name='uniswap')
def test_get_historical_tvl_chain(self, llama):
response = llama.get_historical_tvl_chain('Ethereum')
assert type(response) is list
for data in response:
assert 'date' in data
assert 'tvl' in data
break

def test_get_protocol_current_tvl(self, llama):
response = llama.get_protocol_current_tvl('uniswap')
assert type(response) is float

def test_get_chains_current_tvl(self, llama):
response = llama.get_chains_current_tvl()
assert type(response) is list
for data in response:
assert 'gecko_id' in data
assert 'tvl' in data
assert 'tokenSymbol' in data
assert 'cmcId' in data
assert 'name' in data
assert 'chainId' in data
break

0 comments on commit 9121517

Please sign in to comment.