Skip to main content

Python bindings for the Cryptowatch API. Cryptocurrency markets, assets, instruments and exchanges data.

Project description

Cryptowatch Python SDK

The Cryptowatch Python library provides a convenient access to the Cryptowatch API from applications written in the Python language.

It includes the following features:

  • Auto-serialization of API responses into Python objects
  • API credentials automatically read from your ~/.cw/credentials.yml config file
  • Custom exceptions for API-specific issues (e.g.: Requests Allowance)
  • Smart back-off retries in case of API connectivity loss

Installation

pip install cryptowatch-sdk

Requirements

  • python v3.7+
  • requests v0.8.8+
  • marshmallow v3.2.2+
  • pyyaml v5.1.2+

API Crendential

Using a credential file will allow you to authenticate your requests and grant you the API access of your account tier (Free, Basic or Pro).

Setup your credential file

  1. Generate an Cryptowatch API key from your account
  2. Create your credential file on your machine by running in order: 2.1 mkdir $HOME/.cw 2.2 echo "apikey: 123" > $HOME/.cw/credentials.yml (where 123 is your 20 digits public key)
  3. Verify with cat $HOME/.cw/credentials.yml that you see something like below (123 being your public key):
apikey: 123

The SDK will read your public key as soon as import cryptowatch is ran in your script.

Usage

REST API

import cryptowatch as cw

# Assets
cw.assets.list()
cw.assets.get("BTC")

# Exchanges
cw.exchanges.list()
cw.exchanges.get("KRAKEN")

# Instruments
cw.instruments.list()
cw.instruments.get("BTCUSD")

# Markets
cw.markets.list() # Returns list of all markets on all exchanges
cw.markets.list("BINANCE") # Returns all markets on Binance

# Returns market summary (last, high, low, change, volume)
cw.markets.get("KRAKEN:BTCUSD")
# Return market candlestick info (open, high, low, close, volume) on some timeframes
cw.markets.get("KRAKEN:BTCUSD", "ohlc", periods=["4h", "1h", "1d"])

# Returns market last trades
cw.markets.get("KRAKEN:BTCUSD", "trades")

# Return market current orderbook
cw.markets.get("KRAKEN:BTCUSD", "orderbook")
# Return market current orderbook liquidity
cw.markets.get("KRAKEN:BTCUSD", "liquidity")

Logging

Logging can be enabled through Python's logging module:

import logging

logging.basicConfig()
logging.getLogger("cryptowatch").setLevel(logging.DEBUG)

CLI

The library exposes a simple utility, named cryptowatch, to return last market prices.

By default it returns Kraken's BTCUSD market

> cryptowatch
7425.0

Add another Kraken market to return this market last price

> cryptowatch btceur
6758.1

You can also specify your own exchange

> cryptowatch binance:ethbtc
0.020359

When the market doesn't exist a return code of 1 will be set (0 otherwise):

> cryptowatch binance:nosuchmarketusd
> echo $?
1

Testing

Unit tests are under the tests folder and use pytest, run them all with:

make test

Integration tests sending real HTTP requests to the Cryptowatch API can be run with:

make test-http-real

Development

Testing and developement dependencies are in the requirements.txt file, install them with:

pip install -r requirements.txt

The code base use the Black linter, run it with:

make lint

License

BSD-2-Clause

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

cryptowatch-sdk-0.0.2.tar.gz (11.4 kB view details)

Uploaded Source

Built Distribution

cryptowatch_sdk-0.0.2-py3-none-any.whl (14.3 kB view details)

Uploaded Python 3

File details

Details for the file cryptowatch-sdk-0.0.2.tar.gz.

File metadata

  • Download URL: cryptowatch-sdk-0.0.2.tar.gz
  • Upload date:
  • Size: 11.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.6.0 requests-toolbelt/0.9.1 tqdm/4.40.0 CPython/3.7.4

File hashes

Hashes for cryptowatch-sdk-0.0.2.tar.gz
Algorithm Hash digest
SHA256 2ab709e1291288c39cd63672ff17935ecde1598dd2a7df35e430c53973e4e4c6
MD5 c5752046361dd91d2fe9ab07a7a11067
BLAKE2b-256 734bb537540b892e4989fb527da55610cb879eb35d53a24059acc5464571dbe1

See more details on using hashes here.

File details

Details for the file cryptowatch_sdk-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: cryptowatch_sdk-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 14.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.6.0 requests-toolbelt/0.9.1 tqdm/4.40.0 CPython/3.7.4

File hashes

Hashes for cryptowatch_sdk-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 fe6b884517f7171679f648c6ff9363b830c3419727c7b1524aae4ddfd1fd5211
MD5 6afec6bb8e9a4fa1b080c5122fcb891b
BLAKE2b-256 6db0db89e01e9520cee17cc85a8b4b8cd38cac9d7f782645e5ec3e021d52f86a

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