barnumbirr / coinmarketcap Goto Github PK
View Code? Open in Web Editor NEWA python wrapper around the https://coinmarketcap.com API.
License: Apache License 2.0
A python wrapper around the https://coinmarketcap.com API.
License: Apache License 2.0
I'm using this component in my HomeAssistant installation and when it's configured it throws this exception:
2017-12-04 11:42:21 ERROR (MainThread) [homeassistant.components.sensor] Error while setting up platform coinmarketcap
Traceback (most recent call last):
File "/usr/local/lib/python3.6/dist-packages/homeassistant/helpers/entity_component.py", line 171, in _async_setup_platform
SLOW_SETUP_MAX_WAIT, loop=self.hass.loop)
File "/usr/lib/python3.6/asyncio/tasks.py", line 358, in wait_for
return fut.result()
File "/usr/lib/python3.6/asyncio/futures.py", line 245, in result
raise self._exception
File "/usr/lib/python3.6/concurrent/futures/thread.py", line 56, in run
result = self.fn(*self.args, **self.kwargs)
File "/usr/local/lib/python3.6/dist-packages/homeassistant/components/sensor/coinmarketcap.py", line 55, in setup_platform
CoinMarketCapData(currency, display_currency).update()
File "/usr/local/lib/python3.6/dist-packages/homeassistant/components/sensor/coinmarketcap.py", line 133, in update
convert=self.display_currency)
File "/usr/local/lib/python3.6/dist-packages/coinmarketcap/core.py", line 54, in ticker
response = self.__request('ticker/' + currency, params)
File "/usr/local/lib/python3.6/dist-packages/coinmarketcap/core.py", line 28, in __request
response_object = self.session.get(self.base_url + endpoint, params = params, timeout = self.request_timeout)
File "/usr/local/lib/python3.6/dist-packages/coinmarketcap/core.py", line 21, in session
self._session = requests_cache.core.CachedSession(cache_name='coinmarketcap_cache', backend='sqlite', expire_after=120)
File "/usr/local/lib/python3.6/dist-packages/requests_cache/core.py", line 68, in __init__
self.cache = backends.create_backend(backend, cache_name, backend_options)
File "/usr/local/lib/python3.6/dist-packages/requests_cache/backends/__init__.py", line 50, in create_backend
return registry[backend_name](cache_name, **options)
File "/usr/local/lib/python3.6/dist-packages/requests_cache/backends/sqlite.py", line 28, in __init__
self.responses = DbPickleDict(location + extension, 'responses', fast_save=fast_save)
File "/usr/local/lib/python3.6/dist-packages/requests_cache/backends/storage/dbdict.py", line 58, in __init__
with self.connection() as con:
File "/usr/lib/python3.6/contextlib.py", line 81, in __enter__
return next(self.gen)
File "/usr/local/lib/python3.6/dist-packages/requests_cache/backends/storage/dbdict.py", line 70, in connection
con = sqlite.connect(self.filename)
sqlite3.OperationalError: unable to open database file
A few other users are experiencing the same issue here: home-assistant/core#9907
I have this error in python 3.6 and I believe is due to a parameter name change I read about here: bisguzar/twitter-scraper#15
Traceback (most recent call last):
File "/<MY_PATH>/coin_market_cap.py", line 1, in
from coinmarketcap import Market
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/coinmarketcap/init.py", line 10, in
from .core import Market
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/coinmarketcap/core.py", line 8, in
import requests_cache
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/requests_cache/init.py", line 28, in
from .core import(
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/requests_cache/core.py", line 14, in
from requests import Session as OriginalSession
The request sent doesn't have the attribute 'core' Has anyone else had this issue? What version of requests should I have imported to use this library?
For Home Assistant there is an integration which uses coinmarketcap
. In the past we were running into issues if a dependency was pinned to a specific release of one of their requirements.
coinmarketcap
is pinning requests==2.18.4
and requests_cache==0.4.13
. Could you please consider to ease this?
Thanks
I am attempting to use the API on python 2.7, but I have encountered an Unsupported Pickling Protocol: 3. I have done some research into pickle and have been unable to decipher how to correct the pickling protocol using pickle.dumps() and pickle.loads().
I installed the new version of it and every time when I try to get data I get metadeta and error dicts as well which make my work difficult. Just install the old version and everything is working smoother
I just installed via pip on windows, importing 'coinmarketcap' brings this error:
Traceback (most recent call last):
File "C:\Users\David\Desktop\Python\JSON\UTC_test.py", line 1, in
import coinmarketcap
File "C:\Python27\lib\site-packages\coinmarketcap__init__.py", line 19, in
from .core import (
ImportError: cannot import name about
[Finished in 0.4s with exit code 1]
Any ideas ?
Hey again,
I'm wondering if you can help me, i'm trying to pull volume for each coin.
Out of 120 coins 15 don't work, i suspect it's because the coin names I have are different here's the pastebin for the coins that don't work: (i included DOGE as a control)
http://pastebin.com/uqawGyqw
I got the coin names from a scrapper on poloniex, so maybe some of them don't match, is there a way to use the coin symbol to acquire the coin name so i can replace all my existing coin names with the correct ones that agree with coinmarketcap's ?
Here's a copy of the spreadsheet im saving the data to:
new_values2.xlsx
Tremendous Thanks
Dave
Hi there,
I'm trying to scrape, on a daily basis, the summary for each coin using this function:
coinmarketcap.coin_summary('bitcoin')
However i'm struggling to find a way to get all the coin names. Do you happen to have a list ?
Kind Regards,
I need to search through currencies so here's what i do :
Let's say the user enters the word "bit", First i get the ids of the searched currency with listing
endpoint, now i want to get list of those coins but there's no way to do this according to the documentation since ticker/{id}
gives data only for 1 currency. is there any other way to do this?
So im calling
from coinmarketcap import Market
coinmarketcap = Market()
coinmarketcap.ticker(start=0, limit=3, convert='EUR')
as stated in the manual you provided and I have installed all the dependicies using PyCharm but every time I run it it just returns
Traceback (most recent call last):
File "C:/Users/J/PycharmProjects/Learning/coinmarketcap.py", line 1, in
from coinmarketcap import Market
File "C:\Users\J\PycharmProjects\Learning\coinmarketcap.py", line 1, in
from coinmarketcap import Market
ImportError: cannot import name 'Market'
I'm pretty new to python but have coded in the past in other languages im just not understanding what im doing wrong.
I have requests installed and requests cache installed i tried restarting PyCharm to see if maybe they werent registering but still to no avail. The module is installed in my Pycharm directory and the class Market() does exist im just not sure what im doing wrong...
Getting this error with version 4.0. Did not have any trouble with 3.0.1.
With 4.0 it says I need requests_cache. When I install requests_cache I get this error:
`
import coinmarketcap
coinmarketcap = coinmarketcap.Market()
stats = coinmarketcap.stats()
Traceback (most recent call last):
File "", line 1, in
File "/usr/local/lib/python2.7/dist-packages/coinmarketcap/core.py", line 64, in stats
response = self.__request('global/', params)
File "/usr/local/lib/python2.7/dist-packages/coinmarketcap/core.py", line 34, in __request
response[0][u'cached'] = response_object.from_cache
KeyError: 0
`
Is there a way to use the data acquired from CoinMarketCap without creating an SQLITE File or any supplementary files?
Hello, I am under Debian8 and the answer is very long to come (about 1mn) ...
HI,
I am trying to train a NLP dataset using tensorflow But I am facing the below error
File "train.py", line 52, in
with tf.Session() as sess:
AttributeError: module 'tensorflow' has no attribute 'Session'
I am using tensorflow - 2.3.0, Python - 3.6.8
Please help!
Hey ,
I want coin image url and graph url .can you please guide me how can I get the api..
Anyway I can get the altcoin prices on Bitcoins?
Im trying to install this onto my server through SSH and getting this error. Probably a newbie mistake as im just learning. I get this after trying to run the setup file after extraction
I have started to get this error when I do a pip install
I get this error when trying to call coinmarketcap. Despite a seemingly successful install using pip.
Python 3.4.3 (default, Nov 17 2016, 01:08:31)
[GCC 4.8.4] on linux
Type "help", "copyright", "credits" or "license" for more information.
from coinmarketcap import Market
Traceback (most recent call last):
File "", line 1, in
ImportError: No module named 'coinmarketcap'
(venv)speed@speed-desktop:~/py3project/venv/bin$ pip install coinmarketcap
Requirement already satisfied: coinmarketcap in /home/speed/py3project/venv/lib/python3.4/site-packages
Requirement already satisfied: requests in /home/speed/py3project/venv/lib/python3.4/site-packages (from coinmarketcap)
OS: ubuntu Ubuntu 14.04 trusty
Kernel: x86_64 Linux 3.13.0-129-generic
Uptime: 3h 4m
Packages: 4247
Shell: bash 4.3.11
Resolution: 1920x1080
DE: Gnome 3.9.90
WM: GNOME Shell
WM Theme: Adwaita
Radiance [GTK2]
, Radiance [GTK3]
Icon Theme: elementary-xfce-darker
Font: Cantarell 11
CPU: AMD FX-8350 Eight-Core @ 4GHz
GPU: GeForce GTX 750 Ti
RAM: 9844MiB / 24011MiB
Using v5.0.3:
In [1]: from coinmarketcap import Market
In [2]: coinmarketcap = Market()
In [3]: coinmarketcap.stats()
Out[3]:
{'attention': 'WARNING: This API is now deprecated and will be taken offline soon. Please switch to the new CoinMarketCap API to avoid interruptions in service. (https://pro.coinmarketcap.com/migrate/)',
'data': {'active_cryptocurrencies': 2323,
'active_markets': 20133,
'bitcoin_percentage_of_market_cap': 68.03,
'quotes': {'USD': {'total_market_cap': 265457453605.0,
'total_volume_24h': 61539844551.0}},
'last_updated': 1566425791},
'metadata': {'timestamp': 1566425450,
'warning': 'WARNING: This API is now deprecated and will be taken offline soon. Please switch to the new CoinMarketCap API to avoid interruptions in service. (https://pro.coinmarketcap.com/migrate/)',
'error': None},
'cached': False}
The wrapper seems to be working fine without one, but I don't want to get my IP rate limited. In the future I may have to purchase one of the paid api plans to avoid getting limited.
I have looked around and couldn't find where am I supposed to type my api key.
EDIT: I found out why, this wrapper is still using the public API v2. From coinexchange api documentation:
The Public API will be migrating to the new, more powerful Professional API on December 4th, 2018. Please update your application to use the free tier of the Professional API before then.
See #25.
Hi,
with API v2 the ticker request got a result limit of 100. Why? I would like to have one request for all currencies.
Best regards,
Moe
Hi,
I have been looking through the API and there seemed to have one missing data that I would really wish to have. Is it possible to expose the property value for each coin images in the API?
Thank you!
The current implementation stores cached data in a file called coinmarketcap_cache.sqlite in the current working directory. This is a little untidy. Given that the data is really only designed to be useful for a short period of time and it's unlikely that the user would ever want to interact with the cache file directly, would it make sense to save this file in a system temp directory instead?
I've implemented this here and would be happy to submit a pull request if it's something you would be interested in.
OS: Windows 10
Python: 3.5.2
This appears to actually be a problem with requests-cache, which has an open issue regarding just this problem. Just documenting it here as well in case anybody else encounters this. I can try to take a look at it a bit later.
I'm receiving the following error when trying to use the ticker method. I'm still able to access coinmarketcap.com regularly.
Traceback (most recent call last):
File "C:/Users/Hepworth/Documents/portfolio.py", line 23, in <module>
value = coinMarketCap.ticker(coin, limit=3, convert='USD')
File "C:\Python36\lib\site-packages\coinmarketcap\core.py", line 54, in ticker
response = self.__request('ticker/' + currency, params)
File "C:\Python36\lib\site-packages\coinmarketcap\core.py", line 31, in __request
raise Exception('An error occured, please try again.')
Exception: An error occured, please try again.
I am hitting rate limits. Unfortunately the library does not throw an according error, instead I get the following when trying to access the listing endpoint:
TypeError: 'JSONDecodeError' object is not subscriptable
I would suggest to propagate an error message here:
coinmarketcap/coinmarketcap/core.py
Line 44 in 4e90337
When I try for the first time using call 'coinmarketcap.ticker('VTC', limit=3, convert='USD')' I get the following error using python3. Note the cache file is actually created, but it is 0 size.
Traceback (most recent call last):
File "vtc_wallet.py", line 30, in <module>
price = get_vtc_price()
File "vtc_wallet.py", line 21, in get_vtc_price
coinmarketcap.ticker('VTC', limit=3, convert='USD')
File "/usr/local/lib/python3.5/dist-packages/coinmarketcap/core.py", line 54, in ticker
response = self.__request('ticker/' + currency, params)
File "/usr/local/lib/python3.5/dist-packages/coinmarketcap/core.py", line 28, in __request
response_object = self.session.get(self.base_url + endpoint, params = params, timeout = self.request_timeout)
File "/usr/local/lib/python3.5/dist-packages/coinmarketcap/core.py", line 21, in session
self._session = requests_cache.core.CachedSession(cache_name='coinmarketcap_cache', backend='sqlite', expire_after=120)
File "/usr/local/lib/python3.5/dist-packages/requests_cache/core.py", line 68, in __init__
self.cache = backends.create_backend(backend, cache_name, backend_options)
File "/usr/local/lib/python3.5/dist-packages/requests_cache/backends/__init__.py", line 50, in create_backend
return registry[backend_name](cache_name, **options)
File "/usr/local/lib/python3.5/dist-packages/requests_cache/backends/sqlite.py", line 28, in __init__
self.responses = DbPickleDict(location + extension, 'responses', fast_save=fast_save)
File "/usr/local/lib/python3.5/dist-packages/requests_cache/backends/storage/dbdict.py", line 59, in __init__
con.execute("create table if not exists `%s` (key PRIMARY KEY, value)" % self.table_name)
sqlite3.OperationalError: database is locked
I am trying to run the module, I update the library but get a urllib error:
$ python3
Python 3.6.0a1 (default, Jun 6 2016, 14:59:56)
[GCC 4.9.2] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from coinmarketcap import Market
>>> coinmarketcap = Market()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/user/.local/lib/python3.6/site-packages/coinmarketcap/core.py", line 15, in __init__
self.opener = urllib.build_opener()
NameError: name 'urllib' is not defined
>>>
In [4]: coinmarketcap = Market()
In [5]: coinmarketcap.stats()
Out[5]: json.decoder.JSONDecodeError('Expecting value: line 1 column 1 (char 0)')
As simple as that โ๏ธ
Seems the library is broken:
{'statusCode': 410, 'error': 'Gone', 'message': 'WARNING: This API is now offline. Please switch to the new CoinMarketCap API. (https://pro.coinmarketcap.com/migrate/)'}
I wonder how easy is to request the top 10 of 24_change or other category like that, recursively.
I am getting the following bug:
File "setup.py", line 16, in <module>
long_description = file('README.md','r').read(),
NameError: name 'file' is not defined
In [221]: from coinmarketcap import Market
...: cmc=coinmarketcap = Market()
...: coinmarketcap.listings()
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-221-fa9a3c90ed80> in <module>
----> 1 from coinmarketcap import Market
2 cmc=coinmarketcap = Market()
3 coinmarketcap.listings()
C:\QGB\Anaconda3\lib\site-packages\coinmarketcap\__init__.py in <module>
8 __license__ = 'Apache v2.0 License'
9
---> 10 from .core import Market
C:\QGB\Anaconda3\lib\site-packages\coinmarketcap\core.py in <module>
7 import requests
8 import tempfile
----> 9 import requests_cache
10
11 class Market(object):
C:\QGB\Anaconda3\lib\site-packages\requests_cache\__init__.py in <module>
5 __version__ = '1.0.1'
6
----> 7 from .backends import *
8 from .cache_keys import *
9 from .models import *
C:\QGB\Anaconda3\lib\site-packages\requests_cache\backends\__init__.py in <module>
5
6 from .._utils import get_placeholder_class, get_valid_kwargs
----> 7 from .base import BaseCache, BaseStorage, DictStorage
8
9 # Backend-specific keyword arguments equivalent to 'cache_name'
C:\QGB\Anaconda3\lib\site-packages\requests_cache\backends\base.py in <module>
18
19 from ..cache_keys import create_key, redact_response
---> 20 from ..models import AnyRequest, CachedResponse
21 from ..policy import DEFAULT_CACHE_NAME, CacheSettings, ExpirationTime
22 from ..serializers import SerializerType, init_serializer
C:\QGB\Anaconda3\lib\site-packages\requests_cache\models\__init__.py in <module>
6
7 from .base import RichMixin
----> 8 from .raw_response import CachedHTTPResponse
9 from .request import CachedRequest
10 from .response import CachedResponse, DecodedContent, OriginalResponse
C:\QGB\Anaconda3\lib\site-packages\requests_cache\models\raw_response.py in <module>
3 from typing import TYPE_CHECKING, Optional
4
----> 5 from attr import define, field, fields_dict
6 from requests import Response
7 from urllib3.response import ( # type: ignore # import location false positive
ImportError: cannot import name 'define' from 'attr' (C:\QGB\Anaconda3\lib\site-packages\attr\__init__.py)
When I use the ticker() method, instead of returning a list or dictionary, it returns a string. This is difficult to work with. Is the program supposed to do this?
I'm getting ModuleNotFoundError: No module named 'requests_cache'
when trying to import coinmarketcap
after a clean install from pip. Maybe requests-cache
needs to be added to the dependencies?
import coinmarketcap as cmc
FOURTYTWO_PRICE = cmc.price('42')
print FOURTYTWO_PRICE
Traceback (most recent call last):
File "coinsnake.py", line 23, in
FOURTYTWO_PRICE = cmc.price('42')
File "C:\Python27\lib\site-packages\coinmarketcap\coinmarketcap_api.py", line 39, in price
return coin_info(PARAMETER)[4]
IndexError: list index out of range
http://coinmarketcap.com/currencies/42-coin/
Edit: Needed the dash. Sorry.
Wonder if this module has Python3 support and what to do to adjust.
Tried getting it in my python3 pip but got the issue of:
read(README)...
Instead I used open(README)... and worked. However the new issue is that when it tries to import the coinmarketcap_api and fails.
File "/usr/local/lib/python3.4/dist-packages/coinmarketcap/__init__.py", line 19, in <module>
from coinmarketcap_api import (
ImportError: No module named 'coinmarketcap_api'
Hello all,
I am new to Github so not sure if this is the right way to raise an issue.
I am still beginner in python and would like to know how to run the coinmarketcap on python.
I have the Anaconda ... i typed: pip install marketcap --> successful installation --> what should be the next step ? how can i read the data or visualize it ? is it embedded in the code ?
Thanks
Home Assistant release with the issue:
v98.2
Operating environment (Hass.io/Docker/Windows/etc.):
Docker
Description of problem:
Can't update / setup coinmarketcap sensors
Additional information:
Update for sensor.ethereum fails
Traceback (most recent call last):
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 261, in async_update_ha_state
await self.async_device_update()
File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 441, in async_device_update
await self.hass.async_add_executor_job(self.update)
File "/usr/local/lib/python3.7/concurrent/futures/thread.py", line 57, in run
result = self.fn(*self.args, **self.kwargs)
File "/usr/src/homeassistant/homeassistant/components/coinmarketcap/sensor.py", line 148, in update
self._ticker = self.data.ticker.get("data")
AttributeError: 'JSONDecodeError' object has no attribute 'get'
get error when limit=200, it's fine if not 200 ie 199, 201, etc
from coinmarketcap import Market
coinmarketcap = Market()
markets = coinmarketcap.ticker(limit=200)
error:
Traceback (most recent call last):
File "cmc.py", line 50, in <module>
markets = coinmarketcap.ticker(limit=200) #limit=200
File "C:\Python27\lib\site-packages\coinmarketcap\core.py", line 54, in ticker
response = self.__request('ticker/' + currency, params)
File "C:\Python27\lib\site-packages\coinmarketcap\core.py", line 28, in __request
response_object = self.session.get(self.base_url + endpoint, params = params, timeout = self.request_timeout)
File "C:\Python27\lib\site-packages\requests\sessions.py", line 521, in get
return self.request('GET', url, **kwargs)
File "C:\Python27\lib\site-packages\requests_cache\core.py", line 126, in request
**kwargs
File "C:\Python27\lib\site-packages\requests\sessions.py", line 508, in request
resp = self.send(prep, **send_kwargs)
File "C:\Python27\lib\site-packages\requests_cache\core.py", line 97, in send
response, timestamp = self.cache.get_response_and_time(cache_key)
File "C:\Python27\lib\site-packages\requests_cache\backends\base.py", line 70, in get_response_and_time
if key not in self.responses:
File "C:\Python27\lib\_abcoll.py", line 388, in __contains__
self[key]
File "C:\Python27\lib\site-packages\requests_cache\backends\storage\dbdict.py", line 163, in __getitem__
return pickle.loads(bytes(super(DbPickleDict, self).__getitem__(key)))
File "C:\Python27\lib\copy_reg.py", line 50, in _reconstructor
obj = base.__new__(cls, state)
TypeError: ('dict.__new__(HTTPHeaderDict): HTTPHeaderDict is not a subtype of dict', <function _reconstructor at 0x02DC9570>, (<class 'urllib3._collections.HTTPHeaderDict'>, <type 'dict'>, {'content-encoding': ('Content-Encoding', 'gzip'), 'transfer-encoding': ('Transfer-Encoding', 'chunked'), 'cf-cache-status': ('CF-Cache-Status', 'EXPIRED'), 'vary': ('Vary', 'Accept-Encoding'), 'server': ('Server', 'cloudflare-nginx'), 'connection': ('Connection', 'keep-alive'), 'date': ('Date', 'Sat, 23 Sep 2017 01:15:20 GMT'), 'access-control-allow-origin': ('Access-Control-Allow-Origin', '*'), 'content-type': ('Content-Type', 'application/json'), 'cf-ray': ('CF-RAY', '3a29a6f978f865f3-SYD')}))
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.