pybotters


Namepybotters JSON
Version 1.6.0 PyPI version JSON
download
home_pageNone
SummaryAn advanced API client for python crypto bot traders
upload_time2024-11-23 23:59:32
maintainerNone
docs_urlNone
authorNone
requires_python>=3.9
licenseMIT
keywords aiohttp crypto exchange trading
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            [
  ![PyPI](https://img.shields.io/pypi/v/pybotters)
  ![PyPI - Python Version](https://img.shields.io/pypi/pyversions/pybotters)
  ![PyPI - License](https://img.shields.io/pypi/l/pybotters)
](https://pypi.org/project/pybotters/)
[![Downloads](https://static.pepy.tech/badge/pybotters)](https://pepy.tech/project/pybotters)

[![CI](https://github.com/pybotters/pybotters/actions/workflows/ci.yml/badge.svg)](https://github.com/pybotters/pybotters/actions/workflows/ci.yml)
[![publish](https://github.com/pybotters/pybotters/actions/workflows/publish.yml/badge.svg)](https://github.com/pybotters/pybotters/actions/workflows/publish.yml)
[![Documentation Status](https://readthedocs.org/projects/pybotters/badge/?version=latest)](https://pybotters.readthedocs.io/ja/latest/?badge=latest)
[![uv](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/uv/main/assets/badge/v0.json)](https://github.com/astral-sh/uv)
[![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)

[![GitHub Repo stars](https://img.shields.io/github/stars/pybotters/pybotters?style=social)](https://github.com/pybotters/pybotters/stargazers)
[![GitHub forks](https://img.shields.io/github/forks/pybotters/pybotters?style=social)](https://github.com/pybotters/pybotters/network/members)
[![Discord](https://img.shields.io/discord/832651305155297331?label=Discord&logo=discord&style=social)](https://discord.com/invite/CxuWSX9U69)
[![GitHub Sponsor](https://img.shields.io/badge/Sponsor-%E2%9D%A4-%23db61a2.svg?&logo=github&logoColor=181717&&style=flat-square&labelColor=white)](https://github.com/sponsors/MtkN1)


# pybotters

![pybotters logo](https://raw.githubusercontent.com/pybotters/pybotters/main/docs/logo_150.png)

An advanced API client for python botters. This project is in Japanese.

## ๐Ÿ“Œ Description

`pybotters` is a Python library for [ไปฎๆƒณ้€š่ฒจ botter (crypto bot traders)](https://medium.com/perpdex/botter-the-crypto-bot-trader-in-japan-2f5f2a65856f).

This library is an **HTTP and WebSocket API client**.
It has the following features, making it useful for developing a trading bot.

## ๐Ÿš€ Features

- โœจ HTTP / WebSocket Client
    - **Automatic authentication** for private APIs.
    - WebSocket **automatic reconnection** and **automatic heartbeat**.
    - A client based on [`aiohttp`](https://docs.aiohttp.org/).
- โœจ DataStore
    - WebSocket message data handler.
    - **Processing of differential data** such as order book updates
    - **High-speed data processing** and querying
- โœจ Other Experiences
    - Support for type hints.
    - Asynchronous programming using [`asyncio`](https://docs.python.org/ja/3/library/asyncio.html).
    - Discord community.

## ๐Ÿฆ Exchanges

| Name | API auth | DataStore | Exchange API docs |
| --- | --- | --- | --- |
| bitFlyer | โœ… | โœ… | [Link](https://lightning.bitflyer.com/docs) |
| GMO Coin | โœ… | โœ… | [Link](https://api.coin.z.com/docs/) |
| bitbank | โœ… | โœ… | [Link](https://github.com/bitbankinc/bitbank-api-docs) |
| Coincheck | โœ… | โœ… | [Link](https://coincheck.com/ja/documents/exchange/api) |
| OKJ | โœ… | Not yet | [Link](https://dev.okcoin.jp/en/) |
| BitTrade | โœ… | Not yet | [Link](https://api-doc.bittrade.co.jp/) |
| Bybit | โœ… | โœ… | [Link](https://bybit-exchange.github.io/docs/v5/intro) |
| Binance | โœ… | โœ… | [Link](https://developers.binance.com/docs/binance-spot-api-docs/CHANGELOG) |
| OKX | โœ… | โœ… | [Link](https://www.okx.com/docs-v5/en/) |
| Phemex | โœ… | โœ… | [Link](https://phemex-docs.github.io/) |
| Bitget | โœ… | โœ… | [Link](https://www.bitget.com/api-doc/common/intro) |
| MEXC | โœ… | No support | [Link](https://mexcdevelop.github.io/apidocs/spot_v3_en/) |
| KuCoin | โœ… | โœ… | [Link](https://www.kucoin.com/docs/beginners/introduction) |
| BitMEX | โœ… | โœ… | [Link](https://www.bitmex.com/app/apiOverview) |

## ๐Ÿ Requires

Python 3.9+

## ๐Ÿ”ง Installation

From [PyPI](https://pypi.org/project/pybotters/) (stable version):

```sh
pip install pybotters
```

From [GitHub](https://github.com/pybotters/pybotters) (latest version):

```sh
pip install git+https://github.com/pybotters/pybotters.git
```

## โš ๏ธ Compatibility warning

pybotters is planning a completely new code base v2. It is recommended to specify version less than 2.0 (`pybotters<2.0`) when specifying it as a dependency.

> [!IMPORTANT]
> The roadmap is here: [pybotters/pybotters#248](https://github.com/pybotters/pybotters/issues/248)


## ๐Ÿ“ Usage

Example of bitFlyer API:

### HTTP API

New interface from version 1.0: **Fetch API**.

More simple request/response.

```py
import asyncio

import pybotters

apis = {
    "bitflyer": ["YOUER_BITFLYER_API_KEY", "YOUER_BITFLYER_API_SECRET"],
}


async def main():
    async with pybotters.Client(
        apis=apis, base_url="https://api.bitflyer.com"
    ) as client:
        # Fetch balance
        r = await client.fetch("GET", "/v1/me/getbalance")

        print(r.response.status, r.response.reason, r.response.url)
        print(r.data)

        # Create order
        CREATE_ORDER = False  # Set to `True` if you are trying to create an order.
        if CREATE_ORDER:
            r = await client.fetch(
                "POST",
                "/v1/me/sendchildorder",
                data={
                    "product_code": "BTC_JPY",
                    "child_order_type": "MARKET",
                    "side": "BUY",
                    "size": 0.001,
                },
            )

            print(r.response.status, r.response.reason, r.response.url)
            print(r.data)


asyncio.run(main())
```

aiohttp-based API.

```python
import asyncio

import pybotters

apis = {
    "bitflyer": ["YOUER_BITFLYER_API_KEY", "YOUER_BITFLYER_API_SECRET"],
}


async def main():
    async with pybotters.Client(
        apis=apis, base_url="https://api.bitflyer.com"
    ) as client:
        # Fetch balance
        async with client.get("/v1/me/getbalance") as resp:
            data = await resp.json()

        print(resp.status, resp.reason)
        print(data)

        # Create order
        CREATE_ORDER = False  # Set to `True` if you are trying to create an order.
        if CREATE_ORDER:
            async with client.post(
                "/v1/me/sendchildorder",
                data={
                    "product_code": "BTC_JPY",
                    "child_order_type": "MARKET",
                    "side": "BUY",
                    "size": 0.001,
                },
            ) as resp:
                data = await resp.json()

            print(data)


asyncio.run(main())
```

### WebSocket API

```python
import asyncio

import pybotters


async def main():
    async with pybotters.Client() as client:
        # Create a Queue
        wsqueue = pybotters.WebSocketQueue()

        # Connect to WebSocket and subscribe to Ticker
        await client.ws_connect(
            "wss://ws.lightstream.bitflyer.com/json-rpc",
            send_json={
                "method": "subscribe",
                "params": {"channel": "lightning_ticker_BTC_JPY"},
            },
            hdlr_json=wsqueue.onmessage,
        )

        # Iterate message (Ctrl+C to break)
        async for msg in wsqueue:
            print(msg)


try:
    asyncio.run(main())
except KeyboardInterrupt:
    pass
```

### DataStore

```py
import asyncio

import pybotters


async def main():
    async with pybotters.Client() as client:
        # Create DataStore
        store = pybotters.bitFlyerDataStore()

        # Connect to WebSocket and subscribe to Board
        await client.ws_connect(
            "wss://ws.lightstream.bitflyer.com/json-rpc",
            send_json=[
                {
                    "method": "subscribe",
                    "params": {"channel": "lightning_board_snapshot_BTC_JPY"},
                },
                {
                    "method": "subscribe",
                    "params": {"channel": "lightning_board_BTC_JPY"},
                },
            ],
            hdlr_json=store.onmessage,
        )

        # Watch for the best prices on Board. (Ctrl+C to break)
        with store.board.watch() as stream:
            async for change in stream:
                board = store.board.sorted(limit=2)
                print(board)


try:
    asyncio.run(main())
except KeyboardInterrupt:
    pass
```

## ๐Ÿ“– Documentation

๐Ÿ”— https://pybotters.readthedocs.io/ja/stable/ (Japanese)

## ๐Ÿ—ฝ License

MIT

## ๐Ÿ’– Author

Please sponsor me!:

[![GitHub Sponsor](https://img.shields.io/badge/Sponsor-%E2%9D%A4-%23db61a2.svg?&logo=github&logoColor=181717&&style=flat-square&labelColor=white)](https://github.com/sponsors/MtkN1)

X:

[![X (formerly Twitter) Follow](https://img.shields.io/twitter/follow/MtkN1XBt)](https://twitter.com/MtkN1XBt)

Discord:

[![Discord Widget](https://discord.com/api/guilds/832651305155297331/widget.png?style=banner3)](https://discord.com/invite/CxuWSX9U69)

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "pybotters",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.9",
    "maintainer_email": null,
    "keywords": "aiohttp, crypto, exchange, trading",
    "author": null,
    "author_email": "MtkN1 <51289448+MtkN1@users.noreply.github.com>",
    "download_url": "https://files.pythonhosted.org/packages/61/85/db116212809ef2af8a3093da361c848466cc1110c96c66fa69f88bf51c8f/pybotters-1.6.0.tar.gz",
    "platform": null,
    "description": "[\n  ![PyPI](https://img.shields.io/pypi/v/pybotters)\n  ![PyPI - Python Version](https://img.shields.io/pypi/pyversions/pybotters)\n  ![PyPI - License](https://img.shields.io/pypi/l/pybotters)\n](https://pypi.org/project/pybotters/)\n[![Downloads](https://static.pepy.tech/badge/pybotters)](https://pepy.tech/project/pybotters)\n\n[![CI](https://github.com/pybotters/pybotters/actions/workflows/ci.yml/badge.svg)](https://github.com/pybotters/pybotters/actions/workflows/ci.yml)\n[![publish](https://github.com/pybotters/pybotters/actions/workflows/publish.yml/badge.svg)](https://github.com/pybotters/pybotters/actions/workflows/publish.yml)\n[![Documentation Status](https://readthedocs.org/projects/pybotters/badge/?version=latest)](https://pybotters.readthedocs.io/ja/latest/?badge=latest)\n[![uv](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/uv/main/assets/badge/v0.json)](https://github.com/astral-sh/uv)\n[![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)\n\n[![GitHub Repo stars](https://img.shields.io/github/stars/pybotters/pybotters?style=social)](https://github.com/pybotters/pybotters/stargazers)\n[![GitHub forks](https://img.shields.io/github/forks/pybotters/pybotters?style=social)](https://github.com/pybotters/pybotters/network/members)\n[![Discord](https://img.shields.io/discord/832651305155297331?label=Discord&logo=discord&style=social)](https://discord.com/invite/CxuWSX9U69)\n[![GitHub Sponsor](https://img.shields.io/badge/Sponsor-%E2%9D%A4-%23db61a2.svg?&logo=github&logoColor=181717&&style=flat-square&labelColor=white)](https://github.com/sponsors/MtkN1)\n\n\n# pybotters\n\n![pybotters logo](https://raw.githubusercontent.com/pybotters/pybotters/main/docs/logo_150.png)\n\nAn advanced API client for python botters. This project is in Japanese.\n\n## \ud83d\udccc Description\n\n`pybotters` is a Python library for [\u4eee\u60f3\u901a\u8ca8 botter (crypto bot traders)](https://medium.com/perpdex/botter-the-crypto-bot-trader-in-japan-2f5f2a65856f).\n\nThis library is an **HTTP and WebSocket API client**.\nIt has the following features, making it useful for developing a trading bot.\n\n## \ud83d\ude80 Features\n\n- \u2728 HTTP / WebSocket Client\n    - **Automatic authentication** for private APIs.\n    - WebSocket **automatic reconnection** and **automatic heartbeat**.\n    - A client based on [`aiohttp`](https://docs.aiohttp.org/).\n- \u2728 DataStore\n    - WebSocket message data handler.\n    - **Processing of differential data** such as order book updates\n    - **High-speed data processing** and querying\n- \u2728 Other Experiences\n    - Support for type hints.\n    - Asynchronous programming using [`asyncio`](https://docs.python.org/ja/3/library/asyncio.html).\n    - Discord community.\n\n## \ud83c\udfe6 Exchanges\n\n| Name | API auth | DataStore | Exchange API docs |\n| --- | --- | --- | --- |\n| bitFlyer | \u2705 | \u2705 | [Link](https://lightning.bitflyer.com/docs) |\n| GMO Coin | \u2705 | \u2705 | [Link](https://api.coin.z.com/docs/) |\n| bitbank | \u2705 | \u2705 | [Link](https://github.com/bitbankinc/bitbank-api-docs) |\n| Coincheck | \u2705 | \u2705 | [Link](https://coincheck.com/ja/documents/exchange/api) |\n| OKJ | \u2705 | Not yet | [Link](https://dev.okcoin.jp/en/) |\n| BitTrade | \u2705 | Not yet | [Link](https://api-doc.bittrade.co.jp/) |\n| Bybit | \u2705 | \u2705 | [Link](https://bybit-exchange.github.io/docs/v5/intro) |\n| Binance | \u2705 | \u2705 | [Link](https://developers.binance.com/docs/binance-spot-api-docs/CHANGELOG) |\n| OKX | \u2705 | \u2705 | [Link](https://www.okx.com/docs-v5/en/) |\n| Phemex | \u2705 | \u2705 | [Link](https://phemex-docs.github.io/) |\n| Bitget | \u2705 | \u2705 | [Link](https://www.bitget.com/api-doc/common/intro) |\n| MEXC | \u2705 | No support | [Link](https://mexcdevelop.github.io/apidocs/spot_v3_en/) |\n| KuCoin | \u2705 | \u2705 | [Link](https://www.kucoin.com/docs/beginners/introduction) |\n| BitMEX | \u2705 | \u2705 | [Link](https://www.bitmex.com/app/apiOverview) |\n\n## \ud83d\udc0d Requires\n\nPython 3.9+\n\n## \ud83d\udd27 Installation\n\nFrom [PyPI](https://pypi.org/project/pybotters/) (stable version):\n\n```sh\npip install pybotters\n```\n\nFrom [GitHub](https://github.com/pybotters/pybotters) (latest version):\n\n```sh\npip install git+https://github.com/pybotters/pybotters.git\n```\n\n## \u26a0\ufe0f Compatibility warning\n\npybotters is planning a completely new code base v2. It is recommended to specify version less than 2.0 (`pybotters<2.0`) when specifying it as a dependency.\n\n> [!IMPORTANT]\n> The roadmap is here: [pybotters/pybotters#248](https://github.com/pybotters/pybotters/issues/248)\n\n\n## \ud83d\udcdd Usage\n\nExample of bitFlyer API:\n\n### HTTP API\n\nNew interface from version 1.0: **Fetch API**.\n\nMore simple request/response.\n\n```py\nimport asyncio\n\nimport pybotters\n\napis = {\n    \"bitflyer\": [\"YOUER_BITFLYER_API_KEY\", \"YOUER_BITFLYER_API_SECRET\"],\n}\n\n\nasync def main():\n    async with pybotters.Client(\n        apis=apis, base_url=\"https://api.bitflyer.com\"\n    ) as client:\n        # Fetch balance\n        r = await client.fetch(\"GET\", \"/v1/me/getbalance\")\n\n        print(r.response.status, r.response.reason, r.response.url)\n        print(r.data)\n\n        # Create order\n        CREATE_ORDER = False  # Set to `True` if you are trying to create an order.\n        if CREATE_ORDER:\n            r = await client.fetch(\n                \"POST\",\n                \"/v1/me/sendchildorder\",\n                data={\n                    \"product_code\": \"BTC_JPY\",\n                    \"child_order_type\": \"MARKET\",\n                    \"side\": \"BUY\",\n                    \"size\": 0.001,\n                },\n            )\n\n            print(r.response.status, r.response.reason, r.response.url)\n            print(r.data)\n\n\nasyncio.run(main())\n```\n\naiohttp-based API.\n\n```python\nimport asyncio\n\nimport pybotters\n\napis = {\n    \"bitflyer\": [\"YOUER_BITFLYER_API_KEY\", \"YOUER_BITFLYER_API_SECRET\"],\n}\n\n\nasync def main():\n    async with pybotters.Client(\n        apis=apis, base_url=\"https://api.bitflyer.com\"\n    ) as client:\n        # Fetch balance\n        async with client.get(\"/v1/me/getbalance\") as resp:\n            data = await resp.json()\n\n        print(resp.status, resp.reason)\n        print(data)\n\n        # Create order\n        CREATE_ORDER = False  # Set to `True` if you are trying to create an order.\n        if CREATE_ORDER:\n            async with client.post(\n                \"/v1/me/sendchildorder\",\n                data={\n                    \"product_code\": \"BTC_JPY\",\n                    \"child_order_type\": \"MARKET\",\n                    \"side\": \"BUY\",\n                    \"size\": 0.001,\n                },\n            ) as resp:\n                data = await resp.json()\n\n            print(data)\n\n\nasyncio.run(main())\n```\n\n### WebSocket API\n\n```python\nimport asyncio\n\nimport pybotters\n\n\nasync def main():\n    async with pybotters.Client() as client:\n        # Create a Queue\n        wsqueue = pybotters.WebSocketQueue()\n\n        # Connect to WebSocket and subscribe to Ticker\n        await client.ws_connect(\n            \"wss://ws.lightstream.bitflyer.com/json-rpc\",\n            send_json={\n                \"method\": \"subscribe\",\n                \"params\": {\"channel\": \"lightning_ticker_BTC_JPY\"},\n            },\n            hdlr_json=wsqueue.onmessage,\n        )\n\n        # Iterate message (Ctrl+C to break)\n        async for msg in wsqueue:\n            print(msg)\n\n\ntry:\n    asyncio.run(main())\nexcept KeyboardInterrupt:\n    pass\n```\n\n### DataStore\n\n```py\nimport asyncio\n\nimport pybotters\n\n\nasync def main():\n    async with pybotters.Client() as client:\n        # Create DataStore\n        store = pybotters.bitFlyerDataStore()\n\n        # Connect to WebSocket and subscribe to Board\n        await client.ws_connect(\n            \"wss://ws.lightstream.bitflyer.com/json-rpc\",\n            send_json=[\n                {\n                    \"method\": \"subscribe\",\n                    \"params\": {\"channel\": \"lightning_board_snapshot_BTC_JPY\"},\n                },\n                {\n                    \"method\": \"subscribe\",\n                    \"params\": {\"channel\": \"lightning_board_BTC_JPY\"},\n                },\n            ],\n            hdlr_json=store.onmessage,\n        )\n\n        # Watch for the best prices on Board. (Ctrl+C to break)\n        with store.board.watch() as stream:\n            async for change in stream:\n                board = store.board.sorted(limit=2)\n                print(board)\n\n\ntry:\n    asyncio.run(main())\nexcept KeyboardInterrupt:\n    pass\n```\n\n## \ud83d\udcd6 Documentation\n\n\ud83d\udd17 https://pybotters.readthedocs.io/ja/stable/ (Japanese)\n\n## \ud83d\uddfd License\n\nMIT\n\n## \ud83d\udc96 Author\n\nPlease sponsor me!:\n\n[![GitHub Sponsor](https://img.shields.io/badge/Sponsor-%E2%9D%A4-%23db61a2.svg?&logo=github&logoColor=181717&&style=flat-square&labelColor=white)](https://github.com/sponsors/MtkN1)\n\nX:\n\n[![X (formerly Twitter) Follow](https://img.shields.io/twitter/follow/MtkN1XBt)](https://twitter.com/MtkN1XBt)\n\nDiscord:\n\n[![Discord Widget](https://discord.com/api/guilds/832651305155297331/widget.png?style=banner3)](https://discord.com/invite/CxuWSX9U69)\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "An advanced API client for python crypto bot traders",
    "version": "1.6.0",
    "project_urls": {
        "Documentation": "https://pybotters.readthedocs.io/ja/stable/",
        "Repository": "https://github.com/pybotters/pybotters"
    },
    "split_keywords": [
        "aiohttp",
        " crypto",
        " exchange",
        " trading"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "8c9c731679a7c82aedeae20f9bbbe122b8c91c1f39e0977a091d67b78c062a9b",
                "md5": "9ae0925af7be9b0d4c1c08d732ef7162",
                "sha256": "3d506d8313c861c87bb15df005fd0e7f4f740e3a060233bd80f8326fc0aaae15"
            },
            "downloads": -1,
            "filename": "pybotters-1.6.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "9ae0925af7be9b0d4c1c08d732ef7162",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.9",
            "size": 62658,
            "upload_time": "2024-11-23T23:59:29",
            "upload_time_iso_8601": "2024-11-23T23:59:29.842264Z",
            "url": "https://files.pythonhosted.org/packages/8c/9c/731679a7c82aedeae20f9bbbe122b8c91c1f39e0977a091d67b78c062a9b/pybotters-1.6.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "6185db116212809ef2af8a3093da361c848466cc1110c96c66fa69f88bf51c8f",
                "md5": "29236d3f9081d36324f6c1b34d996582",
                "sha256": "c2560b6a294032e78e7e6b41a6c5a457718f03bfade6c693c9f65a6ed3d3f567"
            },
            "downloads": -1,
            "filename": "pybotters-1.6.0.tar.gz",
            "has_sig": false,
            "md5_digest": "29236d3f9081d36324f6c1b34d996582",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9",
            "size": 177883,
            "upload_time": "2024-11-23T23:59:32",
            "upload_time_iso_8601": "2024-11-23T23:59:32.260165Z",
            "url": "https://files.pythonhosted.org/packages/61/85/db116212809ef2af8a3093da361c848466cc1110c96c66fa69f88bf51c8f/pybotters-1.6.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-11-23 23:59:32",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "pybotters",
    "github_project": "pybotters",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "pybotters"
}
        
Elapsed time: 0.70327s