Skip to content

Commit

Permalink
Merge branch 'release/1.4.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
man-c committed Oct 3, 2020
2 parents 2e267df + 53a8625 commit 8b7a845
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 3 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@

1.4.0 / 2020-10-03
==================

* added new endpoints (/coins/{id}/ohlc, /search/trending, /global/decentralized_finance_defi)
* updated tests

1.3.0 / 2020-07-12
==================

Expand Down
17 changes: 15 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ cg = CoinGeckoAPI()
```

### Examples
The required parameters for each endpoint are defined as required (mandatory) parameters for the coresponding functions.
The required parameters for each endpoint are defined as required (mandatory) parameters for the corresponding functions.
**Any optional parameters** can be also passed using same names, as defined in CoinGecko API doc (https://www.coingecko.com/api/docs/v3)

*Lists are also supported as input for multiple-valued comma-separated parameters (e.g. see /simple/price usage examples).*
Expand All @@ -44,7 +44,7 @@ Usage examples:
>>> cg.get_price(ids=['bitcoin', 'litecoin', 'ethereum'], vs_currencies=['usd', 'eur'])
{'bitcoin': {'usd': 3459.39, 'eur': 3019.33}, 'ethereum': {'usd': 106.91, 'eur': 93.31}, 'litecoin': {'usd': 32.72, 'eur': 28.56}}

# optional parameteres can be passed as defined in the API doc (https://www.coingecko.com/api/docs/v3)
# optional parameters can be passed as defined in the API doc (https://www.coingecko.com/api/docs/v3)
>>> cg.get_price(ids='bitcoin', vs_currencies='usd', include_market_cap='true', include_24hr_vol='true', include_24hr_change='true', include_last_updated_at='true')
{'bitcoin': {'usd': 3458.74, 'usd_market_cap': 60574330199.29028, 'usd_24h_vol': 4182664683.6247883, 'usd_24h_change': 1.2295378479069035, 'last_updated_at': 1549071865}}
```
Expand Down Expand Up @@ -105,6 +105,10 @@ https://www.coingecko.com/api/docs/v3
```python
cg.get_coin_status_updates_by_id()
```
- **/coins/{id}/ohlc** (Get coin's OHLC (beta))
```python
cg.get_coin_ohlc_by_id()
```
- *contract*
- **/coins/{id}/contract/{contract_address}** (Get coin info from contract address)
```python
Expand Down Expand Up @@ -205,11 +209,20 @@ https://www.coingecko.com/api/docs/v3
```python
cg.get_exchange_rates()
```
- *trending*
- **/search/trending** (Get trending search coins (Top-7) on CoinGecko in the last 24 hours)
```python
cg.get_search_trending()
```
- *global*
- **/global** (Get cryptocurrency global data)
```python
cg.get_global()
```
- **/global/decentralized_finance_defi** (Get cryptocurrency global decentralized finance(defi) data)
```python
cg.get_global_decentralized_finance_defi()
```

### Test

Expand Down
27 changes: 27 additions & 0 deletions pycoingecko/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,15 @@ def get_coin_status_updates_by_id(self, id, **kwargs):
api_url = self.__api_url_params(api_url, kwargs)

return self.__request(api_url)

@list_args_to_comma_separated
def get_coin_ohlc_by_id(self, id, vs_currency, days, **kwargs):
"""Get coin's OHLC"""

api_url = '{0}coins/{1}/ohlc?vs_currency={2}&days={3}'.format(self.api_base_url, id, vs_currency, days)
api_url = self.__api_url_params(api_url, kwargs)

return self.__request(api_url)

# ---------- Contract ----------#
@list_args_to_comma_separated
Expand Down Expand Up @@ -382,6 +391,15 @@ def get_exchange_rates(self, **kwargs):
api_url = self.__api_url_params(api_url, kwargs)

return self.__request(api_url)

# ---------- TRENDING ----------#
def get_search_trending(self, **kwargs):
"""Get top 7 trending coin searches"""

api_url = '{0}search/trending'.format(self.api_base_url)
api_url = self.__api_url_params(api_url, kwargs)

return self.__request(api_url)

# ---------- GLOBAL ----------#
def get_global(self, **kwargs):
Expand All @@ -391,3 +409,12 @@ def get_global(self, **kwargs):
api_url = self.__api_url_params(api_url, kwargs)

return self.__request(api_url)['data']

def get_global_decentralized_finance_defi(self, **kwargs):
"""Get cryptocurrency global decentralized finance(defi) data"""

api_url = '{0}global/decentralized_finance_defi'.format(self.api_base_url)
api_url = self.__api_url_params(api_url, kwargs)

return self.__request(api_url)['data']

2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

setuptools.setup(
name='pycoingecko',
version='1.3.0',
version='1.4.0',
packages=['pycoingecko',],
license='MIT',
description = 'Python wrapper around the CoinGecko API',
Expand Down
28 changes: 28 additions & 0 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -508,7 +508,35 @@ def test_get_exchange_rates(self):

## Assert
assert response == json_response

#---------- TRENDING ----------#

#---------- /search/trending ----------#
@responses.activate
def test_failed_search_get_trending(self):
# Arrange
responses.add(responses.GET, 'https://api.coingecko.com/api/v3/search/trending',
status = 404)
exception = HTTPError("HTTP Error")

# Act Assert
with pytest.raises(HTTPError) as HE:
CoinGeckoAPI().get_search_trending()


@responses.activate
def test_get_search_trending(self):
# Arrange
json_response = { "coins": [{"item": {"id":"iris-network", "name":"IRISnet", "symbol":"IRIS", "market_cap_rank":159, "thumb":"/coins/images/5135/thumb/IRIS.png", "score":0}}, {"item": {"id":"hegic", "name":"Hegic", "symbol":"HEGIC", "market_cap_rank":386, "thumb":"/coins/images/12454/thumb/Hegic.png", "score":1}}, {"item": {"id":"moonswap", "name":"MoonSwap", "symbol":"MOON", "market_cap_rank":373, "thumb":"/coins/images/12441/thumb/moon.jpg", "score":2}}, {"item": {"id":"yfv-finance", "name":"YFValue", "symbol":"YFV", "market_cap_rank":179, "thumb":"/coins/images/12198/thumb/yfv.jpg", "score":3}}, {"item": {"id":"yffi-finance", "name":"yffi finance", "symbol":"YFFI", "market_cap_rank":531, "thumb":"/coins/images/11940/thumb/yffi-finance.jpg", "score":4}}, {"item": {"id":"relevant", "name":"Relevant", "symbol":"REL", "market_cap_rank":915, "thumb":"/coins/images/11586/thumb/Relevant.png", "score":5}}, {"item": {"id":"sake-token", "name":"SakeToken", "symbol":"SAKE", "market_cap_rank":503, "thumb":"/coins/images/12428/thumb/sake.png", "score":6}}], "exchanges": [] }

responses.add(responses.GET, 'https://api.coingecko.com/api/v3/search/trending',
json = json_response, status = 200)

# Act
response = CoinGeckoAPI().get_search_trending()

## Assert
assert response == json_response

#---------- GLOBAL ----------#

Expand Down

0 comments on commit 8b7a845

Please sign in to comment.