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
  • Websocket client with transparent handling of protobuf messages
  • 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


pip install cryptowatch-sdk


The cryptowatch library is not related with Cryptowatch. If you installed it by mistake run pip uninstall cryptowatch to remove it.

The correct library name is cryptowatch-sdk.


Showing all Kraken markets that already gained at least 5% over the current weekly candle.

import cryptowatch as cw
from datetime import datetime, timedelta

# Get all Kraken markets
kraken ="kraken")

# For each Kraken market...
for market in

    # Forge current market ticker, like KRAKEN:BTCUSD
    ticker = "{}:{}".format(, market.pair).upper()
    # Request weekly candles for that market
    candles =, ohlc=True, periods=["1w"])

    # Each candle is a list of [close_timestamp, open, high, low, close, volume, volume_quote]
    # Get close_timestamp, open and close from the most recent weekly candle
    close_ts, wkly_open, wkly_close = (

    # Compute market performance, skip if open was 0
    if wkly_open == 0:
    perf = (wkly_open - wkly_close) * 100 / wkly_open

    # If the market performance was 5% or more, print it
    if perf >= 5:
        open_ts = datetime.utcfromtimestamp(close_ts) - timedelta(days=7)
        print("{} gained {:.2f}% since {}".format(ticker, perf, open_ts))


  • python v3.7+
  • requests v0.8.8+
  • marshmallow v3.2.2+
  • pyyaml v5.1.2+
  • websocket-client v0.56+
  • protobuf v3.11.3+

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.



import cryptowatch as cw

# Set your API Key, it is by default read from  your ~/.cw/credentials.yml file
cw.api_key = "123"

# Assets

# Exchanges

# Instruments

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

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

# Returns market last trades"KRAKEN:BTCUSD", trades=True)

# Return market current orderbook"KRAKEN:BTCUSD", orderbook=True)
# Return market current orderbook liquidity"KRAKEN:BTCUSD", liquidity=True)

You can access the raw HTTP response received via the _http_response attribute which is a requests.Response object:

import cryptowatch as cw

bitcoin = cw.assets.get('btc')


import cryptowatch as cw

# Set your API Key
cw.api_key = "123"

# Subscribe to resources ( = ["markets:*:trades"]

# What to do on each trade update
def handle_trades_update(trade_update):
        trade_update follows Cryptowatch protocol buffer format:
    market_msg = ">>> Market#{} Exchange#{} Pair#{}: {} New Trades".format(,,,
    for trade in trade_update.marketUpdate.tradesUpdate.trades:
        trade_msg = "\tID:{} TIMESTAMP:{} TIMESTAMPNANO:{} PRICE:{} AMOUNT:{}".format(
        print(trade_msg) = handle_trades_update

# Start receiving

# Call disconnect to close the stream connection

See this script for more streaming example.

Converting protobuf messages to JSON

If you need to convert the protobuf message to JSON, you can do so with MessageToJson. See the example below:

from google.protobuf.json_format import MessageToJson
import cryptowatch as cw

# Set your API Key
cw.api_key = "123"

# Subscribe to resources ( = ["markets:*:trades"]

# What to do on each trade update
def handle_trades_update(trade_update):
        trade_update follows Cryptowatch protocol buffer format:
    MessageToJson(trade_update) = handle_trades_update

# Start receiving


Logging can be enabled through Python's logging module:

import logging



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

By default it returns Kraken's BTCUSD market

> cryptowatch

Add another Kraken market to return this market last price

> cryptowatch btceur

You can also specify your own exchange

> cryptowatch binance:ethbtc

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

> cryptowatch binance:nosuchmarketusd
> echo $?


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


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



Project details

Download files

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

Files for cryptowatch-sdk, version 0.0.14
Filename, size File type Python version Upload date Hashes
Filename, size cryptowatch_sdk-0.0.14-py3-none-any.whl (50.3 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size cryptowatch-sdk-0.0.14.tar.gz (40.6 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page