Giter VIP home page Giter VIP logo

python-coinmarketcap's People

Contributors

rsz44 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

python-coinmarketcap's Issues

cryptocurrency_listings_latest not working

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.

Problem with the test code

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

TypeError: unsupported format string passed to NoneType.__format__

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:

  • python3 get_price.py -s ETH -c USD
  • python3 get_price.py -s ETH -c GBP
  • python3 get_price.py -s CSPR -c USD
  • python3 get_price.py -s ADA -c USD
  • python3 get_price.py -s ADA -c GBP
  • python3 get_price.py -s ETH -c JPY

All of my research suggests that It's my syntax but I can't pinpoint where I'm going wrong on this one.

Next release notes

Note (partly for myself) for the next version...

Priority :

Missing endpoints (on issue date) :

  • v2.0.9 on June 1, 2023
    • /v1/community/trending/topic now available to get community trending topics.
    • /v1/community/trending/token now available to get community trending tokens.
  • v2.0.8 on November 25, 2022
    • /v1/exchange/assets now available to get exchange assets in the form of token holdings.

Bug fixes :

  • 'Downloads' badge is not available anymore because of changes in pepy.tech URLs (After a curious survey, we can see that the developers are working hard to offer a paid version and this is ironic. Even their 'copy to clipboard' feature is out of date...) :
    • https://pepy.tech/project/python-coinmarketcap is now https://static.pepy.tech/badge/python-coinmarketcap

Notes :

  • New tutorials are available using the library, and should be listed in the Readme.
  • The postman endpoint is still not 'truly' taken into consideration. It could be interesting to provide a secondary class, that automatically binds the routes provided by the postman collection (this will be de-facto slower on the instantiation, because of request time and treatment of received data). For those who want to keep a light and fast version (already written here), the current work should remain available by default. This secondary class will then provide the missings endpoints in the case of a discontinuity in the package updates (for missing endpoints, as is currently the case).
  • Adding parameters in typing notation would enable autocompletion for modern code editors. But would be a real pain to keep up to date (would make more sense for the postman version, previously detailled, so that it's well synchronized with the online version).

Getting lots of timeout errors

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.