Skip to main content

Wrapper for CryptoCompare.com

Project description

cryptocompare GitHub Workflow Status (branch) Coverage Status PyPI - Python Version PyPI version Requirements Status

Python3 wrapper to query cryptocurrency prices (and more) using the CryptoCompare API.

Install

pip3 install cryptocompare

Usage

import cryptocompare

API Key

If you have an API key, you can either set it as environment variable CRYPTOCOMPARE_API_KEY or set it manually with:

cryptocompare.cryptocompare._set_api_key_parameter(KEY_HERE)

Coin List

cryptocompare.get_coin_list(format=False)
# ...
# },
# 'BTC': {
#  'Id': '1182'
#  'Url': '/coins/btc/overview'
#  'ImageUrl': '/media/19633/btc.png'
#  'Name': 'BTC'
#  'CoinName': 'Bitcoin'
#  'FullName': 'Bitcoin (BTC)'
#  'Algorithm': 'SHA256'
#  'ProofType': 'PoW'
#  'FullyPremined': '0'
#  'TotalCoinSupply': '21000000'
#  'PreMinedValue': 'N/A'
#  'TotalCoinsFreeFloat': 'N/A'
#  'SortOrder': '1'
# },
# ...

If format is True, the coin list is returned as Python list, containing only the abbreviations (like BTC).

Price

cryptocompare.get_price('BTC')
# or
cryptocompare.get_price('BTC', currency='USD', full=True)
# or
cryptocompare.get_price(['BTC', 'ETH'], ['EUR', 'GBP'])

# {'BTC': {'EUR': 3709.04, 'GBP': 3354.78},
#  'ETH': {'EUR': 258.1, 'GBP': 241.25}}

Historical Prices

# pass either datetime or time instance
cryptocompare.get_historical_price('XMR', timestamp=datetime.datetime(2017,6,6), exchange='CCCAGG')
# or
cryptocompare.get_historical_price('XMR', 'EUR', datetime.datetime(2017,6,6))

# {'XMR': {'EUR': 43.05}}

Day

cryptocompare.get_historical_price_day('BTC', currency='EUR')
cryptocompare.get_historical_price_day('BTC', currency='EUR', limit=30)
cryptocompare.get_historical_price_day('BTC', 'EUR', limit=24, exchange='CCCAGG', toTs=datetime.datetime(2019,6,6))
# or
cryptocompare.get_historical_price_day('BTC', 'EUR', limit=24, exchange='CCCAGG', toTs=datetime.datetime(1559815200))

Hour

cryptocompare.get_historical_price_hour('BTC', currency='EUR')
cryptocompare.get_historical_price_hour('BTC', currency='EUR', limit=24)
cryptocompare.get_historical_price_hour('BTC', 'EUR', limit=24, exchange='CCCAGG')
cryptocompare.get_historical_price_hour('BTC', 'EUR', limit=24, exchange='CCCAGG', toTs=datetime.datetime(2019,6,6,12))
# or
cryptocompare.get_historical_price_hour('BTC', 'EUR', limit=24, exchange='CCCAGG', toTs=datetime.datetime(1559815200))

Minute

cryptocompare.get_historical_price_minute('BTC', currency='EUR')
cryptocompare.get_historical_price_minute('BTC', currency='EUR', limit=1440)
cryptocompare.get_historical_price_minute('BTC', 'EUR', limit=24, exchange='CCCAGG', toTs=datetime.datetime.now())

Average

cryptocompare.get_avg('BTC', currency='EUR', exchange='Kraken')
# {
# 'MARKET': 'CUSTOMAGG',
# 'FROMSYMBOL': 'BTC',
# 'TOSYMBOL': 'EUR',
# 'FLAGS': 0,
# 'PRICE': 3610,
# 'LASTUPDATE': 1503066719,
# 'LASTVOLUME': 0.5,
# 'LASTVOLUMETO': 1805,
# 'LASTTRADEID': 1503066719.7584,
# 'VOLUME24HOUR': 12614.509997469995,
# 'VOLUME24HOURTO': 46397723.00499387,
# 'OPEN24HOUR': 3847.9,
# 'HIGH24HOUR': 3848.96,
# 'LOW24HOUR': 3555,
# 'LASTMARKET': 'Kraken',
# 'CHANGE24HOUR': -237.9000000000001,
# 'CHANGEPCT24HOUR': -6.182593102731363
# }

Exchanges

cryptocompare.get_exchanges()

Pairs

cryptocompare.get_pairs()
pairs = cryptocompare.get_pairs(exchange='Kraken')

Developing

Tests run assuming you have an API key, otherwise they will error due to rate limiting. Install the dev dependencies and run the tests:

pip3 install -r requirements.txt
python3 -m pytest

Credit

Disclaimer

This is a hobby project, no guarantees. If you find bugs or want additional features, open an issue and/or create a pull request.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

cryptocompare-0.7.5.tar.gz (5.2 kB view details)

Uploaded Source

File details

Details for the file cryptocompare-0.7.5.tar.gz.

File metadata

  • Download URL: cryptocompare-0.7.5.tar.gz
  • Upload date:
  • Size: 5.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.23.0 setuptools/53.0.0 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.9.1

File hashes

Hashes for cryptocompare-0.7.5.tar.gz
Algorithm Hash digest
SHA256 7583d5519dc74cbd9e4c704e1530c5e8446f4500d4dda481357616e3439410da
MD5 4783b8c1d618d237cfe69012fe53b834
BLAKE2b-256 148ac16e4a8dae729b8115b4385f372890018f34473ad840b3b2d66b74576828

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page