Skip to content

Commit

Permalink
Merge branch 'hotfix/params_fix'
Browse files Browse the repository at this point in the history
  • Loading branch information
man-c committed Mar 30, 2021
2 parents 87e6ec2 + 656f0a9 commit bf02690
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 7 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
@@ -1,4 +1,9 @@

1.4.1 / 2021-03-30
==================

* fixed __api_url_params issue for optional parametes of few endpoints (such as /coins/{id}/market_chart)

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

Expand Down
16 changes: 10 additions & 6 deletions pycoingecko/api.py
Expand Up @@ -37,9 +37,13 @@ def __request(self, url):
# pass
raise

def __api_url_params(self, api_url, params):
def __api_url_params(self, api_url, params, api_url_has_params=False):
if params:
api_url += '?'
# if api_url contains already params and there is already a '?' avoid
# adding second '?' (api_url += '&' if '?' in api_url else '?'); causes
# issues with request parametes (usually for endpoints with required
# arguments passed as parameters)
api_url += '&' if api_url_has_params else '?'
for key, value in params.items():
api_url += "{0}={1}&".format(key, value)
api_url = api_url[:-1]
Expand Down Expand Up @@ -152,7 +156,7 @@ def get_coin_market_chart_by_id(self, id, vs_currency, days, **kwargs):
"""Get historical market data include price, market cap, and 24h volume (granularity auto)"""

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

return self.__request(api_url)

Expand All @@ -163,7 +167,7 @@ def get_coin_market_chart_range_by_id(self, id, vs_currency, from_timestamp, to_
api_url = '{0}coins/{1}/market_chart/range?vs_currency={2}&from={3}&to={4}'.format(self.api_base_url, id,
vs_currency, from_timestamp,
to_timestamp)
api_url = self.__api_url_params(api_url, kwargs)
api_url = self.__api_url_params(api_url, kwargs, api_url_has_params=True)

return self.__request(api_url)

Expand All @@ -181,7 +185,7 @@ 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)
api_url = self.__api_url_params(api_url, kwargs, api_url_has_params=True)

return self.__request(api_url)

Expand All @@ -202,7 +206,7 @@ def get_coin_market_chart_from_contract_address_by_id(self, id, contract_address
api_url = '{0}coins/{1}/contract/{2}/market_chart/?vs_currency={3}&days={4}'.format(self.api_base_url, id,
contract_address,
vs_currency, days)
api_url = self.__api_url_params(api_url, kwargs)
api_url = self.__api_url_params(api_url, kwargs, api_url_has_params=True)

return self.__request(api_url)

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Expand Up @@ -3,7 +3,7 @@

setuptools.setup(
name='pycoingecko',
version='1.4.0',
version='1.4.1',
packages=['pycoingecko',],
license='MIT',
description = 'Python wrapper around the CoinGecko API',
Expand Down

0 comments on commit bf02690

Please sign in to comment.