Skip to main content

cryptoapi

Asynchronous cryptocurrency REST and websocket API with support for multiple exchanges.

Cryptoapi is built on top of the fantastic CCXT library. If you plan to do any serious trading, I would recommend paying for access to CCXT Pro because cryptoapi is still in development.

Installation

Cryptoapi is available on PyPI.

It is recommended to use the --user flag on package installations. Drop the flag if installing cryptoapi system-wide.

pip install --user cryptoapi

Usage

The API currently supports Bitfinex (API version 2), Bitvavo, Coinbase Pro, and Kraken.

Unified Methods

Each exchange has four unified websocket methods in addition to the REST methods provided by CCXT. All results are formatted the same as in the CCXT library.

All of the methods put the results received from the exchange in the exchange_instance.result asyncio queue. The results can be retrieved by using the .get() corountine method on the queue.

  • subscribe_ticker: ticker as a dictionary.
  • subscribe_trades: a list of trades recieved from the exchange.
  • subscribe_ohlcvs: a list of [timestamp, open, high, low, close, volume] candles, often just one candle is present (the candle for the timeframe provided, which is one minute by default).
  • subscribe_order_book: the data sent to the queue is the update from the exchange. Cryptoapi automatically keeps an updated order book for every instance (see the Local Order Book section below).

Example

Note that asyncio must be available to take advantage of asynchronous capabilities. The results from the exchanges are stored in the exchange.result asyncio queue in the form of (channel, data) tuples. The channel in this example is 'order_book'. The data is the reply from the exchange.

import asyncio
import cryptoapi


async def main():
    exchanges = [
        cryptoapi.Bitfinex(),
    ]
    for exchange in exchanges:
        await exchange.load_markets()
    symbols = ['BTC/EUR', 'ETH/EUR']
    tasks = [
        asyncio.create_task(exchange.subscribe_order_book(symbols))
        for exchange in exchanges
    ]
    tasks.append(asyncio.create_task(get_results(exchanges, symbols)))
    for t in tasks:
        await t
    for exchange in exchanges:
        exchange.close()


async def get_results(exchanges, symbols):
    while True:
        for exchange in exchanges:
            for symbol in symbols:
                if symbol in exchange.symbols:
                    channel, data = await exchange.result.get()
                    print(data)


if __name__ == "__main__":
    asyncio.run(main())

Local Order Book

If you subscribe to an order book channel, cryptoapi will keep a local copy of the order book in the exchange.order_book dictionary. Keep in mind that this dictionary is tied to the exchange instance, so if you have multiple instances of the same exchange you will also have multiple order books. An example structure of the dictionary is outlined below.

{
    'BTC/USD': {
        'bids': [[11111, 1.7], ...]             # [price, amount] sorted by price in descending order (best bid first).    
        'asks': [[11112, 3], ...]               # [price, amount] sorted by price in ascending order (best ask first).
        'timestamp': 1596729013,                # Unix timestamp for when the book was last updated.
        'datetime': '2020-08-06T15:50:56.714Z', # iso860 datetime. Computed from the timestamp property.
        'nonce': 109335233,                     # Exchange-provided nonce. None if not provided.
    },
    ...
}

Metadata

Release files for cryptoapi 0.1.22

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for cryptoapi 0.1.22
File Size Uploaded Provenance Actions
cryptoapi-0.1.22.tar.gz 14.1 kB Without provenance Details for cryptoapi-0.1.22.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for cryptoapi 0.1.22
File Interpreter ABI Platform Actions
cryptoapi-0.1.22-py3-none-any.whl Python 3 none any Details for cryptoapi-0.1.22-py3-none-any.whl

Total release size: 28.6 kB

Release files / cryptoapi-0.1.22.tar.gz

Download URL cryptoapi-0.1.22.tar.gz
Size 14.1 kB
Tags Source
SHA-256 checksum
How to use checksums
72d7aedba2aeb4208e53036bdff8c7854ad1f1db96b2a893451c6a398b44380a
BLAKE2b-256 checksum
How to use checksums
1452dacbe9fbea1102582e1a0d2831c59e28e29ebc2ab532df18423503b55b1c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.2.0 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.8.3

Release files / cryptoapi-0.1.22-py3-none-any.whl

Download URL cryptoapi-0.1.22-py3-none-any.whl
Size 14.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a070ccdf9deee9bc7fa209d4cb56ecff3a43dc52b028b763e89e82a6d55b11e2
BLAKE2b-256 checksum
How to use checksums
7d5bd9806fa2cc94384954939364662c118773b3076ab45d272c5fa1127b8dfb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/49.2.0 requests-toolbelt/0.9.1 tqdm/4.48.0 CPython/3.8.3

Security for cryptoapi 0.1.22

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.22 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page