pybotters


Namepybotters JSON
Version 1.1.1 PyPI version JSON
download
home_pageNone
SummaryAn advanced API client for python crypto bot traders
upload_time2024-05-04 14:14:32
maintainerNone
docs_urlNone
authorNone
requires_python>=3.8
licenseNone
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)
[![codecov](https://codecov.io/gh/pybotters/pybotters/graph/badge.svg?token=ARR29R726W)](https://codecov.io/gh/pybotters/pybotters)
[![Documentation Status](https://readthedocs.org/projects/pybotters/badge/?version=latest)](https://pybotters.readthedocs.io/ja/latest/?badge=latest)
[![Hatch project](https://img.shields.io/badge/%F0%9F%A5%9A-Hatch-4051b5.svg)](https://github.com/pypa/hatch)
[![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) |
| Bybit | โœ… | โœ… | [Link](https://bybit-exchange.github.io/docs/v5/intro) |
| Binance | โœ… | โœ… | [Link](https://binance-docs.github.io/apidocs/spot/en/) |
| OKX | โœ… | โœ… | [Link](https://www.okx.com/docs-v5/en/) |
| Phemex | โœ… | โœ… | [Link](https://phemex-docs.github.io/) |
| Bitget | โœ… | โœ… | [Link](https://bitgetlimited.github.io/apidoc/en/mix/) |
| 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.8+

## ๐Ÿ”ง 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
```

## ๐Ÿ“ 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.8",
    "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/29/68/00d88067860aa54ddfc7fadbb3883e76de9fd0067d6be79001bc2398bb7c/pybotters-1.1.1.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[![codecov](https://codecov.io/gh/pybotters/pybotters/graph/badge.svg?token=ARR29R726W)](https://codecov.io/gh/pybotters/pybotters)\n[![Documentation Status](https://readthedocs.org/projects/pybotters/badge/?version=latest)](https://pybotters.readthedocs.io/ja/latest/?badge=latest)\n[![Hatch project](https://img.shields.io/badge/%F0%9F%A5%9A-Hatch-4051b5.svg)](https://github.com/pypa/hatch)\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| Bybit | \u2705 | \u2705 | [Link](https://bybit-exchange.github.io/docs/v5/intro) |\n| Binance | \u2705 | \u2705 | [Link](https://binance-docs.github.io/apidocs/spot/en/) |\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://bitgetlimited.github.io/apidoc/en/mix/) |\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.8+\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## \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": null,
    "summary": "An advanced API client for python crypto bot traders",
    "version": "1.1.1",
    "project_urls": {
        "Documentation": "https://pybotters.readthedocs.io/ja/stable/",
        "Repository": "https://github.com/pybotters/pybotters"
    },
    "split_keywords": [
        "aiohttp",
        " crypto",
        " exchange",
        " trading"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "83a6b3a1e1ce525d881445489ceef1016cc799648791620ab69a2c02c258b99e",
                "md5": "34f220a559e82cd595f7a71ee7c86d9c",
                "sha256": "ba188382adc28fe379578fc81af2f80f751263a7039e629eac2a946fdd512bad"
            },
            "downloads": -1,
            "filename": "pybotters-1.1.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "34f220a559e82cd595f7a71ee7c86d9c",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 55258,
            "upload_time": "2024-05-04T14:13:55",
            "upload_time_iso_8601": "2024-05-04T14:13:55.543861Z",
            "url": "https://files.pythonhosted.org/packages/83/a6/b3a1e1ce525d881445489ceef1016cc799648791620ab69a2c02c258b99e/pybotters-1.1.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "296800d88067860aa54ddfc7fadbb3883e76de9fd0067d6be79001bc2398bb7c",
                "md5": "90ce05d262ad303eaf77c1f96f6a7f36",
                "sha256": "74a47b52c5ad4387f368716082c6098e9a34fa5e771cc50928770c89bacff23d"
            },
            "downloads": -1,
            "filename": "pybotters-1.1.1.tar.gz",
            "has_sig": false,
            "md5_digest": "90ce05d262ad303eaf77c1f96f6a7f36",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 165736,
            "upload_time": "2024-05-04T14:14:32",
            "upload_time_iso_8601": "2024-05-04T14:14:32.594269Z",
            "url": "https://files.pythonhosted.org/packages/29/68/00d88067860aa54ddfc7fadbb3883e76de9fd0067d6be79001bc2398bb7c/pybotters-1.1.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-05-04 14:14: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.27491s