Skip to main content

CoinMarketCap history scraper


Contents

Obtain CoinMarketCap USD price history data for CoinMarketCap-listed cryptocurrencies in CSV format.

Use this library as a command-line script to obtain historical cryptocurrency data on the fly, or import the library to obtain cryptocurrency data for your programs.

Installation

Download the zip file or navigate to the desired install directory and run:

$ git clone https://github.com/Alescontrela/coinmarketcap-history.git

To install the required dependencies, navigate into the repo and run:

$ pip install -r requirements.txt

Usage

Command Line

Among other things, this is useful for US tax reporting. If you want to know the cost basis for a trade (or for coins acquired through mining), the IRS requires you to denominate that cost basis in USD. In the case of token-for-token trades (e.g. purchasing ETH with BTC), that requires you know the USD:BTC exchange rate at the time of the trade.

Surprisingly, as of October 2017, it's not easy to get this data in a machine-readable format anywhere online.

Rather than getting the exchange rate at the exact moment of your trade, which is generally not feasible, the IRS standard (at least for similar situations w/stock) is to use the average of a stock's high and low price for the day. CoinMarketCap doesn't provide this figure, but this tool calculates this number and includes it in the output.

Command Line Usage

In the terminal, navigate into the repo directory and run:

$ python coinmarketcap.py <currency1> <start_date> <end_date>

where:

  • currency is the (case-insensitive) name of the currency / token as displayed on CoinMarketCap, with dashes in place of spaces
  • start_date is the beginning of the range to fetch data for in yyyy-mm-dd format. For example, 2017-10-01 (for 2017 October 10th)
  • end_year is the end of the range to fetch data for in yyyy-mm-dd format. You may use a date in the future to obtain the latest data. Format is the same as in the start date.

Data for multiple cryptocurrencies can be obtained with:

$ python coinmarketcap.py <currency_1,currency_2,...,currency_n> <start_date> <end_date>

Note: currencies must be comma-separated, with no spaces in between.

The above information can also be found by running:

$ python coinmarketcap.py -h

Write outputs to a file by running:

$ coinmarketcap.py <currency> <start_date> <end_date> > <output_filename>

Command Line Examples

Collecting data for one cryptocurrency:

$ python coinmarketcap.py bitcoin 2017-01-01 2017-12-31

Collecting data for multiple cryptocurrencies:

$ python coinmarketcap.py bitcoin,ripple,ethereum 2017-01-01 2017-12-31

Writing output to a file:

$ python coinmarketcap.py bitcoin 2017-01-01 2017-12-31 > bitcoin_prices.csv

Writing output for multiple cryptocurrencies to a file:

$ python coinmarketcap.py bitcoin,ripple,ethereum 2017-01-01 2017-12-31 > bitcoin_ripple_ethereum_prices.csv

Module

You can also use coinmarketcap.py as a module in other python modules to get back a pandas dataframe with a cryptocurrency's history.

First, you may need to add the path to coinmarketcap_usd_history.py in your sys.path through a command like the following:

sys.path.append(<path_to_coinmarketcap_usd_history.py_parent_folder>)

(Alternatively, just move the coinmarketcap_usd_history.py file to the directory of the including module.)

Second, import the module:

import coinmarketcap_usd_history

Finally perform this to obtain the dataframe:

df = coinmarketcap_usd_history.main(['bitcoin','2017-01-01','2017-12-31','--dataframe'])

If you just wish to have the CSV output returned as a string to another python module, simply omit the '--dataframe' parameter.

Metadata

Release files for cmctestingthree 0.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for cmctestingthree 0.0.1
File Size Uploaded
cmctestingthree-0.0.1.tar.gz 7.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for cmctestingthree 0.0.1
File Interpreter ABI Platform
cmctestingthree-0.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 15.7 kB

Release files / cmctestingthree-0.0.1.tar.gz

Download URL cmctestingthree-0.0.1.tar.gz
Size 7.4 kB
Tags Source
SHA-256 checksum
How to use checksums
6306d276501d4dc599e4a14414812abf805104cd6952df2beb3b9713e232f3ec
BLAKE2b-256 checksum
How to use checksums
a7bc469b726e4ed36c8087c6b6bf6bab2530c8ac6a736b0dacfc57589e29041c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / cmctestingthree-0.0.1-py3-none-any.whl

Download URL cmctestingthree-0.0.1-py3-none-any.whl
Size 8.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
69d8bd637a1c1e806486f81e20e485882d2c715037bca27ecb8d0793c8793146
BLAKE2b-256 checksum
How to use checksums
cdab824ab3a6f2ff71e98547328e147c749772a537b299de2feec3c87d474f4b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

0.0.1 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page