Skip to main content

Library to retrieve price or candle history of crypto assets using multiple sources

Project description

Note

This library is under development by EtWnn, feel free to drop your suggestions or remarks in the discussion tab of the git repo. You are also welcome to contribute by submitting PRs.

This library is made to retrieve price or candle history of crypto assets using multiple sources.

Source Code:

https://github.com/EtWnn/CryptoPrice

Documentation:

https://cryptoprice.readthedocs.io

Features

The idea is to have under a single library several price history API to be able to fetch effortlessly the price of large amount of different tokens or to compare the price difference between exchanges.

It currently includes:
  • Binance API

  • Kucoin API

  • Coinbase API

  • Cross-API logic

Quick Tour

Installation

CryptoPrice is available on PYPI, install with pip:

pip install --no-deps python-CryptoPrice
pip install python-CryptoPrice

Note: –no-deps is needed as one of the dependencies is not hosted one PYPI, simply on git.

You can also install the latest developments (not stable):

pip install git+https://github.com/EtWnn/CryptoPrice.git@develop

Examples

A price retriever is already provided by the library, but feel free to check the documentation to instantiate one yourself.

import datetime
from CryptoPrice import get_default_retriever

retriever = get_default_retriever()

asset = 'BTC'
ref_asset = 'USDT'
timestamp = int(datetime.datetime(2021, 1, 1, 15, 14).timestamp())

# will return the first price price found close to the timestamp
retriever.get_closest_price(asset, ref_asset, timestamp)
>>Price(value=29480.0, asset='BTC', ref_asset='USDT', timestamp=1609510440, source='binance')

You can also fetch a price even if the trading pair does not exist: The retriever (MetaRetriever) will find a path with several trading pairs to estimate the price between the asset and the ref asset. This method takes much more time than the one above as several API calls (or database requests) may be needed.

import datetime
from CryptoPrice import get_default_retriever

retriever = get_default_retriever()

asset = 'LTC'
ref_asset = 'XRP'
timestamp = int(datetime.datetime(2021, 3, 3, 15, 14).timestamp())

# will return an average price of several trading path
price = retriever.get_mean_price(asset, ref_asset, timestamp)
if price is not None:  # price found
    print(f"{asset} = {price.value:.5f} {ref_asset}, source: {price.source}")
>>LTC = 420.76841 XRP, source: {'binance', 'kucoin', 'coinbase'}

Donation

If this library has helped you in any way, feel free to donate:

  • BTC: 14ou4fMYoMVYbWEKnhADPJUNVytWQWx9HG

  • ETH: 0xfb0ebcf8224ce561bfb06a56c3b9a43e1a4d1be2

  • LTC: LfHgc969RFUjnmyLn41SRDvmT146jUg9tE

  • EGLD: erd1qk98xm2hgztvmq6s4jwtk06g6laattewp6vh20z393drzy5zzfrq0gaefh

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

python-CryptoPrice-0.1.3.tar.gz (15.5 kB view details)

Uploaded Source

File details

Details for the file python-CryptoPrice-0.1.3.tar.gz.

File metadata

  • Download URL: python-CryptoPrice-0.1.3.tar.gz
  • Upload date:
  • Size: 15.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/3.7.3 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.7.10

File hashes

Hashes for python-CryptoPrice-0.1.3.tar.gz
Algorithm Hash digest
SHA256 6c0bf1a5f238d13ed06342794911b5daeb2ceda5cdcdd5cd6ccfb6834b462bef
MD5 e395d9b3d4b13f29b8a7e220136aeaa9
BLAKE2b-256 46f45e59944b93e9cb08a5b5627c7db5eef1b8ee831ce3ca8c460037d4ecb3e3

See more details on using hashes here.

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