rsz44 / python-coinmarketcap Goto Github PK
View Code? Open in Web Editor NEWCoinMarketCap Python API Wrapper
License: MIT License
CoinMarketCap Python API Wrapper
License: MIT License
I get this error 50% of the times when using cryptocurrency_info()
:
Expecting value: line 1 column 1 (char 0)
cmc.cryptocurrency_listings_latest(id=1) gives me this error.
coinmarketcapapi.CoinMarketCapAPIError: RESPONSE: 805ms ERR 400 ""id" is not allowed": {}
I tested with slug and symbol but still doesn't work.
I keep getting this error, even though I have an active and accurate api from coinmarketcap developers
When I run the test code given at the top of the README:
`from coinmarketcapapi import CoinMarketCapAPI, CoinMarketCapAPIError
cmc = CoinMarketCapAPI('{YOUR_API_KEY}')
r = cmc.cryptocurrency_info(symbol='BTC')
do_something(r.data)`
The cmd gives me this error:
File "C:\Users\Juliano\Desktop\Autre\Projets DEV\En cours\CoinPy\test.py", line 1 from coinmarketcapapi import CoinMarketCapAPI, CoinMarketCapAPIError IndentationError: unexpected indent
However, I installed the package with pip.
Help me pls
I am getting this error with requesting any quote other than BTC to USD. Code:
from coinmarketcapapi import CoinMarketCapAPI
from dotenv import load_dotenv
import argparse
import os
load_dotenv()
class CryptoQuote:
def __init__(self, symbol, currency):
self.quote = cmc.cryptocurrency_quotes_latest(symbol=symbol, convert=currency)
self.price = self.quote.data[f'{symbol}']['quote'][f'{currency}']['price']
self.symbol = str(symbol)
self.circulating = self.quote.data[f'{symbol}']['circulating_supply']
self.max = self.quote.data[f'{symbol}']['max_supply']
self.market_cap = self.quote.data[f'{symbol}']['quote'][f'{currency}']['fully_diluted_market_cap']
def __str__(self):
return f"Current quote for {self.symbol}: \nCurrent Price: ${self.price:,} \n" \
f"Total Circulating Supply: {self.circulating:,} \n" \
f"Max Supply of Token: {self.max:,} \n" \
f"Market Cap of Token: ${self.market_cap:,}"
if __name__ == "__main__":
CMC_API_KEY = os.environ['CMC_API_KEY']
cmc = CoinMarketCapAPI(CMC_API_KEY)
parser = argparse.ArgumentParser(description="CoinmarketCap API tool to get a crypto qutoe ASAP.")
parser.add_argument("--symbol", '-s', help="Which crypto symbol to check.", type=str, required=True, dest='symbol')
parser.add_argument("--currency", '-c', help="Which fiat currency to convert to.", type=str, required=True, dest='currency')
args = parser.parse_args()
new_quote = CryptoQuote(args.symbol, args.currency)
print(new_quote)
I have tried the following combinations:
All of my research suggests that It's my syntax but I can't pinpoint where I'm going wrong on this one.
Note (partly for myself) for the next version...
Priority :
Missing endpoints (on issue date) :
/v1/community/trending/topic
now available to get community trending topics./v1/community/trending/token
now available to get community trending tokens./v1/exchange/assets now available
to get exchange assets in the form of token holdings.Bug fixes :
https://pepy.tech/project/python-coinmarketcap
is now https://static.pepy.tech/badge/python-coinmarketcap
Notes :
First of all thank you for the python wrapper API.
I am running the following code on a raspberry pi and getting lots of timeout errors. Can you please help me?
Here is the code:
#!/usr/bin/env python3
import time
import pickle
from portfolio import portfolio
from coinmarketcapapi import CoinMarketCapAPI, CoinMarketCapAPIError
cmc = CoinMarketCapAPI('****deleted***')
# API requests limits imposed by Coinmarketcap on free API use
max_requests_per_minute = 30.0
max_requests_per_day = 300.0
# Timers to enforce free API usage
market_start_hour = 0.0
market_end_hour = 24.0
minutes_active = (market_end_hour - market_start_hour) * 60.0 # number of minutes in the market operation 8:00 to 24:00
forced_inactivity1 = 60.0 / max_requests_per_minute # do not exceed max_requests_per_minute
# do not exceeed max_requests_per_day
forced_inactivity2 = len(portfolio)*60.0*((minutes_active/max_requests_per_day)-1.0/max_requests_per_minute)
# BATCH OF API_REQUESTS + forced_inactivity2 + BATCH OF API_REQUESTS ...
def loop():
total_now = 0
total_yesterday = 0
for i,amount in portfolio.items():
ticker = cmc.cryptocurrency_quotes_latest(id=i,convert='BRL')
total_now += float(ticker.data[i]['quote']['BRL']['price']) * float(amount)
total_yesterday += float(ticker.data[i]['quote']['BRL']['price']) * float(amount) - (float(ticker.data[i]['quote']['BRL']['price']) * float(ticker.data[i]['quote']['BRL']['percent_change_24h']) / 100.0 * float(amount))
time.sleep(forced_inactivity1)
time.sleep(forced_inactivity2)
gains = total_now - total_yesterday
with open('config.ini', 'wb') as configfile:
pickle.dump(gains,configfile)
def main():
while True:
loop()
if __name__=="__main__":
main()
Here are the errors I am getting:
Jan 08 17:59:31 raspberrypi python3[11965]: Traceback (most recent call last):
Jan 08 17:59:31 raspberrypi python3[11965]: File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 445, in _make_request
Jan 08 17:59:31 raspberrypi python3[11965]: six.raise_from(e, None)
Jan 08 17:59:31 raspberrypi python3[11965]: File "", line 3, in raise_from
Jan 08 17:59:31 raspberrypi python3[11965]: File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 440, in _make_request
Jan 08 17:59:31 raspberrypi python3[11965]: httplib_response = conn.getresponse()
Jan 08 17:59:31 raspberrypi python3[11965]: File "/usr/lib/python3.9/http/client.py", line 1347, in getresponse
Jan 08 17:59:31 raspberrypi python3[11965]: response.begin()
Jan 08 17:59:31 raspberrypi python3[11965]: File "/usr/lib/python3.9/http/client.py", line 307, in begin
Jan 08 17:59:31 raspberrypi python3[11965]: version, status, reason = self._read_status()
Jan 08 17:59:31 raspberrypi python3[11965]: File "/usr/lib/python3.9/http/client.py", line 268, in _read_status
Jan 08 17:59:31 raspberrypi python3[11965]: line = str(self.fp.readline(_MAXLINE + 1), "iso-8859-1")
Jan 08 17:59:31 raspberrypi python3[11965]: File "/usr/lib/python3.9/socket.py", line 704, in readinto
Jan 08 17:59:31 raspberrypi python3[11965]: return self._sock.recv_into(b)
Jan 08 17:59:31 raspberrypi python3[11965]: File "/usr/lib/python3.9/ssl.py", line 1241, in recv_into
Jan 08 17:59:31 raspberrypi python3[11965]: return self.read(nbytes, buffer)
Jan 08 17:59:31 raspberrypi python3[11965]: File "/usr/lib/python3.9/ssl.py", line 1099, in read
Jan 08 17:59:31 raspberrypi python3[11965]: return self._sslobj.read(len, buffer)
Jan 08 17:59:31 raspberrypi python3[11965]: TimeoutError: [Errno 110] Connection timed out
Jan 08 17:59:31 raspberrypi python3[11965]: During handling of the above exception, another exception occurred:
Jan 08 17:59:31 raspberrypi python3[11965]: Traceback (most recent call last):
Jan 08 17:59:31 raspberrypi python3[11965]: File "/usr/lib/python3/dist-packages/requests/adapters.py", line 439, in send
Jan 08 17:59:31 raspberrypi python3[11965]: resp = conn.urlopen(
Jan 08 17:59:31 raspberrypi python3[11965]: File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 755, in urlopen
Jan 08 17:59:31 raspberrypi python3[11965]: retries = retries.increment(
Jan 08 17:59:31 raspberrypi python3[11965]: File "/usr/lib/python3/dist-packages/urllib3/util/retry.py", line 532, in increment
Jan 08 17:59:31 raspberrypi python3[11965]: raise six.reraise(type(error), error, _stacktrace)
Jan 08 17:59:31 raspberrypi python3[11965]: File "/usr/lib/python3/dist-packages/six.py", line 719, in reraise
Jan 08 17:59:31 raspberrypi python3[11965]: raise value
Jan 08 17:59:31 raspberrypi python3[11965]: File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 699, in urlopen
Jan 08 17:59:31 raspberrypi python3[11965]: httplib_response = self._make_request(
Jan 08 17:59:31 raspberrypi python3[11965]: File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 447, in _make_request
Jan 08 17:59:31 raspberrypi python3[11965]: self._raise_timeout(err=e, url=url, timeout_value=read_timeout)
Jan 08 17:59:31 raspberrypi python3[11965]: File "/usr/lib/python3/dist-packages/urllib3/connectionpool.py", line 353, in _raise_timeout
Jan 08 17:59:31 raspberrypi python3[11965]: raise ReadTimeoutError(
Jan 08 17:59:31 raspberrypi python3[11965]: urllib3.exceptions.ReadTimeoutError: HTTPSConnectionPool(host='pro-api.coinmarketcap.com', port=443): Read timed out. (read timeout=None)
Jan 08 17:59:31 raspberrypi python3[11965]: During handling of the above exception, another exception occurred:
Jan 08 17:59:31 raspberrypi python3[11965]: Traceback (most recent call last):
Jan 08 17:59:31 raspberrypi python3[11965]: File "/home/pi/.local/lib/python3.9/site-packages/coinmarketcapapi/init.py", line 172, in __get
Jan 08 17:59:31 raspberrypi python3[11965]: response = self.__session.get(url, params=kwargs)
Jan 08 17:59:31 raspberrypi python3[11965]: File "/usr/lib/python3/dist-packages/requests/sessions.py", line 555, in get
Jan 08 17:59:31 raspberrypi python3[11965]: return self.request('GET', url, **kwargs)
Jan 08 17:59:31 raspberrypi python3[11965]: File "/usr/lib/python3/dist-packages/requests/sessions.py", line 542, in request
Jan 08 17:59:31 raspberrypi python3[11965]: resp = self.send(prep, **send_kwargs)
Jan 08 17:59:31 raspberrypi python3[11965]: File "/usr/lib/python3/dist-packages/requests/sessions.py", line 655, in send
Jan 08 17:59:31 raspberrypi python3[11965]: r = adapter.send(request, **kwargs)
Jan 08 17:59:31 raspberrypi python3[11965]: File "/usr/lib/python3/dist-packages/requests/adapters.py", line 529, in send
Jan 08 17:59:31 raspberrypi python3[11965]: raise ReadTimeout(e, request=request)
Jan 08 17:59:31 raspberrypi python3[11965]: requests.exceptions.ReadTimeout: HTTPSConnectionPool(host='pro-api.coinmarketcap.com', port=443): Read timed out. (read timeout=None)
Jan 08 17:59:31 raspberrypi python3[11965]: During handling of the above exception, another exception occurred:
Jan 08 17:59:31 raspberrypi python3[11965]: Traceback (most recent call last):
Jan 08 17:59:31 raspberrypi python3[11965]: File "/home/pi/cripto/getcripto.py", line 40, in
Jan 08 17:59:31 raspberrypi python3[11965]: main()
Jan 08 17:59:31 raspberrypi python3[11965]: File "/home/pi/cripto/getcripto.py", line 37, in main
Jan 08 17:59:31 raspberrypi python3[11965]: loop()
Jan 08 17:59:31 raspberrypi python3[11965]: File "/home/pi/cripto/getcripto.py", line 26, in loop
Jan 08 17:59:31 raspberrypi python3[11965]: ticker = cmc.cryptocurrency_quotes_latest(id=i,convert='BRL')
Jan 08 17:59:31 raspberrypi python3[11965]: File "/home/pi/.local/lib/python3.9/site-packages/coinmarketcapapi/init.py", line 239, in cryptocurrency_quotes_latest
Jan 08 17:59:31 raspberrypi python3[11965]: return self.__get(
Jan 08 17:59:31 raspberrypi python3[11965]: File "/home/pi/.local/lib/python3.9/site-packages/coinmarketcapapi/init.py", line 190, in __get
Jan 08 17:59:31 raspberrypi python3[11965]: self.__logger.warning(e)
Jan 08 17:59:31 raspberrypi python3[11965]: AttributeError: 'NoneType' object has no attribute 'warning'
I am not sure if its a network error but wifi connections seems stable on the raspberry pi looking at the logs.
Best regards
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.