cryptoapi


Namecryptoapi JSON
Version 0.1.22 PyPI version JSON
download
home_pagehttps://github.com/joshklop/cryptoapi
SummaryAsynchronous cryptocurrency REST and websocket API with support for multiple exchanges.
upload_time2020-08-07 00:27:19
maintainer
docs_urlNone
authorJosh Klopfenstein
requires_python
licenseMIT
keywords websocket rest api cryptocurrency exchange coinbasepro kraken bitvavo bitfinex
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # cryptoapi

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

Cryptoapi is built on top of the fantastic [CCXT](github.com/ccxt/ccxt) library.
If you plan to do any serious trading, I would recommend paying for access to [CCXT Pro](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](github.com/ccxt/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. 
```python
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.
```python
{
    '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.
    },
    ...
}
```



            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/joshklop/cryptoapi",
    "name": "cryptoapi",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "websocket rest api cryptocurrency exchange coinbasepro kraken bitvavo bitfinex",
    "author": "Josh Klopfenstein",
    "author_email": "joshklop@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/14/52/dacbe9fbea1102582e1a0d2831c59e28e29ebc2ab532df18423503b55b1c/cryptoapi-0.1.22.tar.gz",
    "platform": "",
    "description": "# cryptoapi\n\nAsynchronous cryptocurrency REST and websocket API with support for multiple exchanges.\n\nCryptoapi is built on top of the fantastic [CCXT](github.com/ccxt/ccxt) library.\nIf you plan to do any serious trading, I would recommend paying for access to [CCXT Pro](ccxt.pro) because cryptoapi is still in development.\n\n## Installation\n\nCryptoapi is available on PyPI.\n\nIt is recommended to use the `--user` flag on package installations. Drop the flag if installing cryptoapi system-wide.\n```\npip install --user cryptoapi\n```\n\n## Usage\n\nThe API currently supports Bitfinex (API version 2), Bitvavo, Coinbase Pro, and Kraken.\n\n### Unified Methods\n\nEach exchange has four unified websocket methods in addition to the REST methods provided by [CCXT](github.com/ccxt/ccxt).\nAll results are formatted the same as in the CCXT library.\n\nAll of the methods put the results received from the exchange in the `exchange_instance.result` asyncio queue.\nThe results can be retrieved by using the `.get()` corountine method on the queue.\n\n* `subscribe_ticker`: ticker as a dictionary.\n* `subscribe_trades`: a list of trades recieved from the exchange.\n* `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).\n* `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).\n\n### Example\n\nNote that `asyncio` must be available to take advantage of asynchronous capabilities.\nThe results from the exchanges are stored in the `exchange.result` `asyncio` queue in the form of `(channel, data)` tuples.\nThe `channel` in this example is `'order_book'`. The data is the reply from the exchange. \n```python\nimport asyncio\nimport cryptoapi\n\n\nasync def main():\n    exchanges = [\n        cryptoapi.Bitfinex(),\n    ]\n    for exchange in exchanges:\n        await exchange.load_markets()\n    symbols = ['BTC/EUR', 'ETH/EUR']\n    tasks = [\n        asyncio.create_task(exchange.subscribe_order_book(symbols))\n        for exchange in exchanges\n    ]\n    tasks.append(asyncio.create_task(get_results(exchanges, symbols)))\n    for t in tasks:\n        await t\n    for exchange in exchanges:\n        exchange.close()\n\n\nasync def get_results(exchanges, symbols):\n    while True:\n        for exchange in exchanges:\n            for symbol in symbols:\n                if symbol in exchange.symbols:\n                    channel, data = await exchange.result.get()\n                    print(data)\n\n\nif __name__ == \"__main__\":\n    asyncio.run(main())\n```\n\n### Local Order Book\n\nIf you subscribe to an order book channel, cryptoapi will keep a local copy of the order book in the `exchange.order_book` dictionary.\nKeep 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.\nAn example structure of the dictionary is outlined below.\n```python\n{\n    'BTC/USD': {\n        'bids': [[11111, 1.7], ...]             # [price, amount] sorted by price in descending order (best bid first).    \n        'asks': [[11112, 3], ...]               # [price, amount] sorted by price in ascending order (best ask first).\n        'timestamp': 1596729013,                # Unix timestamp for when the book was last updated.\n        'datetime': '2020-08-06T15:50:56.714Z', # iso860 datetime. Computed from the timestamp property.\n        'nonce': 109335233,                     # Exchange-provided nonce. None if not provided.\n    },\n    ...\n}\n```\n\n\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Asynchronous cryptocurrency REST and websocket API with support for multiple exchanges.",
    "version": "0.1.22",
    "split_keywords": [
        "websocket",
        "rest",
        "api",
        "cryptocurrency",
        "exchange",
        "coinbasepro",
        "kraken",
        "bitvavo",
        "bitfinex"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "md5": "eb3bdd112890366074e4aa83a4d7dee2",
                "sha256": "a070ccdf9deee9bc7fa209d4cb56ecff3a43dc52b028b763e89e82a6d55b11e2"
            },
            "downloads": -1,
            "filename": "cryptoapi-0.1.22-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "eb3bdd112890366074e4aa83a4d7dee2",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 14567,
            "upload_time": "2020-08-07T00:27:18",
            "upload_time_iso_8601": "2020-08-07T00:27:18.220063Z",
            "url": "https://files.pythonhosted.org/packages/7d/5b/d9806fa2cc94384954939364662c118773b3076ab45d272c5fa1127b8dfb/cryptoapi-0.1.22-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "md5": "ba2a454c79fa0c69b3f7d6b17722f6d9",
                "sha256": "72d7aedba2aeb4208e53036bdff8c7854ad1f1db96b2a893451c6a398b44380a"
            },
            "downloads": -1,
            "filename": "cryptoapi-0.1.22.tar.gz",
            "has_sig": false,
            "md5_digest": "ba2a454c79fa0c69b3f7d6b17722f6d9",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 14052,
            "upload_time": "2020-08-07T00:27:19",
            "upload_time_iso_8601": "2020-08-07T00:27:19.154125Z",
            "url": "https://files.pythonhosted.org/packages/14/52/dacbe9fbea1102582e1a0d2831c59e28e29ebc2ab532df18423503b55b1c/cryptoapi-0.1.22.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2020-08-07 00:27:19",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": null,
    "github_project": "joshklop",
    "error": "Could not fetch GitHub repository",
    "lcname": "cryptoapi"
}
        
Elapsed time: 0.10327s