Coder Social home page Coder Social logo

nigelliyang / coinmarketcap-history Goto Github PK

View Code? Open in Web Editor NEW

This project forked from waultics/coinmarketcap-history

0.0 2.0 0.0 11 KB

Get the CoinMarketCap price history for a particular cryptocurrency and print it in CSV format.

Python 100.00%

coinmarketcap-history's Introduction

CoinMarketCap history scraper

Print the CoinMarketCap USD price history for a particular cryptocurrency in CSV format.

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.

Installation:

This script requires Python 2 to be available at /usr/bin/python. This is the case by default with macOS.

Usage:

Just run in the terminal: ./coinmarketcap_usd_history.py <currency> <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. For example, 2017-10-01 (for 2017 October 10th)
  • <end_year> is the end of the range to fetch data for. You may use the date in the future here to obtain the latest data. Format is the same as in the start date.

The above information can also be found by running: python coinmarketcap_usd_history.py -h in your terminal.

You can, of course, write the results to a file with the output redirection:

./coinmarketcap_usd_history.py <currency> <start_date> <end_date> > <output_filename>

Using in another python 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.

coinmarketcap-history's People

Contributors

jhogan4288 avatar nazariyv avatar nigelliyang avatar

Watchers

James Cloos avatar  avatar

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.