Coder Social home page Coder Social logo

saporitigianni / coinmarketcappy Goto Github PK

View Code? Open in Web Editor NEW
7.0 0.0 5.0 48 KB

Python 3+ API to retrieve, scrape and cache historical data from coinmarketcap.com

License: MIT License

Python 100.00%
coinmarketcap-api cryptocurrency coinmarketcap historical-cryptocurrency-prices

coinmarketcappy's Introduction

coinmarketcappy: Python wrapper and scraper for coinmarketcap data

Installation

To install coinmarketcappy, simply use pip:

$ pip install coinmarketcappy

or install directly from source to include latest changes:

$ pip install git+https://github.com/saporitigianni/coinmarketcappy.git

or clone and then install:

$ git clone https://github.com/saporitigianni/coinmarketcappy.git
$ cd coinmarketcappy
$ python3 setup.py install

Usage

Every method supports the arguments 'out_file' and 'wformat' to save the information to a file. If 'out_file' is present then the info will be saved to that file. Use absolute path unless you want to save locally. If 'wformat' is not specified, it will default to 'json' ('csv' also supported)

All methods except for available_snaps and historical_snapshots also support the 'epoch' parameter. If True it will return all times as epochs, if False it will return them as date and time (e.g. '2018-05-01 00:19:31')

To get Historical Snapshots (taken every Sunday since 20130428) or Global Charts data:

import coinmarketcappy as cmc

# Get all available historical snapshots to choose from
# or visit https://coinmarketcap.com/historical/
dates = cmc.available_snaps()

# Retrieve info for the last 10 snapshots
snaps = cmc.historical_snapshots(dates[-10:])

# Percentage of Market Capitalization (Dominance)
dom = cmc.dominance()

# Total Market Capitalization
cap = cmc.total_market_cap()

# Total Market Capitalization (Excluding Bitcoin)
cap = cmc.total_market_cap(exclude_btc=True)

To get tickers and simple global data:

import coinmarketcappy as cmc

# Get a list of all tickers organized by rank
tickers = cmc.get_tickers()

# Get a specific ticker (by its name not symbol. e.g. bitcoin, ethereum,... not btc, eth)
ticker = cmc.get_ticker(name='bitcoin')

# Get ticker's historical data (also by its name)
temp = cmc.get_ticker_historical(name='bitcoin')

# Get global data in ERU
glob = cmc.get_global_data(convert='eur')

Acknowledgements

This data is being sourced either from the coinmarketcap API or is being scraped from coinmarketcap.com. Its free to use so please respect their rate limit. :octocat:

Contributing

Please read the CONTRIBUTING document before making changes that you would like adopted in the code.

Code of Conduct

Everyone interacting in the coinmarketcappy project's codebase, issue trackers, chat rooms, and mailing lists is expected to follow the PyPA Code of Conduct.

Buy me a coffee?

ETH 0xaD1F09626b9B8e701D5f0F4a237193Df73d3C445
BTC 199zsVqCusefv8yjdYQhUQZmLCyh75dqNV
LTC LUBqs7VxC43ttPsQuM1jaZFmshKTAU1Rs9

coinmarketcappy's People

Contributors

saporitigianni avatar tzachshabtay avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

coinmarketcappy's Issues

get_ticker(name='bitcoin') doesn't work

import coinmarketcappy as cmc
ticker = cmc.get_ticker(name='bitcoin')

gives the following:
Traceback (most recent call last):
File "/usr/local/lib/python3.9/dist-packages/requests-2.31.0-py3.9.egg/requests/models.py", line 971, in json
return complexjson.loads(self.text, **kwargs)
File "/usr/lib/python3.9/json/init.py", line 346, in loads
return _default_decoder.decode(s)
File "/usr/lib/python3.9/json/decoder.py", line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/usr/lib/python3.9/json/decoder.py", line 355, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

_retrieve_snaps problem

@saporitigianni

I got this error when run this code

symbol, name = td[1].get_text().strip().lower().split('\n')
ValueError: too many values to unpack (expected 2)

The solution is very simple, when this division occurs in the line it is divided into 3 parts, like this:
['pizza', '', 'pizzacoin']

I change the 117 line from scrape.py to this:

symbol, line, name = td[1].get_text().strip().lower().split('\n')

Missing values in currency historical ticker

I found missing values of the historical ticker, did anyone encounter such problem?

In [99]: temp = cmc.get_ticker_historical('bitcoin')
In [100]: temp.keys()
Out[100]: dict_keys(['price_btc', 'market_cap_by_available_supply', 'volume_usd', 'price_usd'])
In [101]: len(temp['price_usd'])
Out[101]: 1924
In [102]: temp['price_usd'][0]
Out[102]: ['2013-04-29 02:47:21', 135.3]
In [103]: temp['price_usd'][-1]
Out[103]: ['2018-08-20 15:19:19', 6461.89]
In [104]: pd.date_range('2013-04-29', '2018-08-20').size
Out[104]: 1940

Dates with Missing Values
2013-06-04 NaN
2013-11-29 NaN
2014-02-12 NaN
2014-03-29 NaN
2014-05-24 NaN
2014-06-28 NaN
2014-07-04 NaN
2014-07-07 NaN
2014-10-01 NaN
2014-12-12 NaN
2014-12-13 NaN
2015-04-01 NaN
2015-06-13 NaN
2015-09-18 NaN
2016-02-05 NaN
2017-06-27 NaN
2017-07-24 NaN

`cmc.dominance()` does not work

The error code is as follows:

ConnectionError: HTTPSConnectionPool(host='graphs2.coinmarketcap.com', port=443): Max retries exceeded with url: /global/dominance/ (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x000001CC6D8833A0>: Failed to establish a new connection: [Errno 11001] getaddrinfo failed'))

What should I do to avoid the error?

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.