Code Monkey home page Code Monkey logo

PyPI PyPI - Python Version PyPI - License Downloads

CI publish codecov Documentation Status Hatch project Ruff

GitHub Repo stars GitHub forks Discord GitHub Sponsor

pybotters

pybotters logo

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

๐Ÿ“Œ Description

pybotters is a Python library for ไปฎๆƒณ้€š่ฒจ botter (crypto bot traders).

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.
  • โœจ 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.
    • Discord community.

๐Ÿฆ Exchanges

Name API auth DataStore Exchange API docs
bitFlyer โœ… โœ… Link
GMO Coin โœ… โœ… Link
bitbank โœ… โœ… Link
Coincheck โœ… โœ… Link
Bybit โœ… โœ… Link
Binance โœ… โœ… Link
OKX โœ… โœ… Link
Phemex โœ… โœ… Link
Bitget โœ… โœ… Link
MEXC โœ… No support Link
KuCoin โœ… โœ… Link
BitMEX โœ… โœ… Link

๐Ÿ Requires

Python 3.8+

๐Ÿ”ง Installation

From PyPI (stable version):

pip install pybotters

From GitHub (latest version):

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.

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.

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

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

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

X:

X (formerly Twitter) Follow

Discord:

Discord Widget

pybotters's Projects

pybotters doesnโ€™t have any public repositories yet.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.