Aio-binance-library - Async library for connecting to the Binance API on Python

Overview

aio-binance-library

Async library for connecting to the Binance API on Python

Python 3.7 License: MIT Aiohttp: 3.8.1 Loguru: 0.5.3 Ujson: 0.5.3 Docstrings: Google

This is a lightweight library that works as a connector to Binance Futures public API

  • Supported APIs:
    • USDT-M Futures `/fapi/*``
    • Futures/Delivery Websocket Market Stream
    • Futures/Delivery User Data Stream
  • Inclusion of examples
  • Response metadata can be displayed

Installation

pip install aio-binance-library

Getting started

REST API

Usage examples:

import asyncio
from aio_binance.futures.usdt import Client 

async def main():
    client = Client()
    res = await client.get_public_time()
    print(res)

    client = Client(key='<api_key>', secret='<api_secret>')

    # Get account information
    res = await client.get_private_account_info()
    print(res)

    # Post a new order
    params = {
        'symbol': 'BTCUSDT',
        'side': 'SELL',
        'type_order': 'LIMIT',
        'time_in_force': 'GTC',
        'quantity': 0.002,
        'price': 59808
    }

    res = await client.create_private_order(**params)
    print(res)

asyncio.run(main())

Please find examples folder to check for more endpoints.

Notes

The methods you need, adheres to a hierarchy

<method>_<availability>_<method_name>

create_private_order()
or
get_public_time()

Methods:

create, get, delete, change, update

Availability:

private - methods where key_api and secret_api are required

public - you can get information without a key

Testnet

You can choose testnet

from aio_binance.futures.usdt import Client

client= Client(testnet=True)

Optional parameters

Parameters can be passed in different formats as in Binance api documents or PEP8 suggests lowercase with words separated by underscores

# Binance api
response = await client.get_private_open_order('BTCUSDT', orderListId=1)

# PEP8
response = await client.get_private_open_order('BTCUSDT', order_list_id=1)

Timeout

timeout is available to be assigned with the number of seconds you find most appropriate to wait for a server response.
Please remember the value as it won't be shown in error message no bytes have been received on the underlying socket for timeout seconds.
By default, timeout=5

from aio_binance.futures.usdt import Client

client= Client(timeout=1)

Response Metadata

The Binance API server provides weight usages in the headers of each response. You can display them by initializing the client with show_limit_usage=True:

from aio_binance.futures.usdt import Client

client = Client(show_limit_usage=True)
res = await client.time()
print(res)

returns:

{'data': {'serverTime': 1647990837551}, 'limit_usage': 40}

You can also display full response metadata to help in debugging:

client = Client(show_header=True)
res = await client.time()
print(res)

returns:

{'data': {'serverTime': 1587990847650}, 'header': {'Context-Type': 'application/json;charset=utf-8', ...}}

User agent

client = Client(agent='name_app')

You can pass the name of your application.

Websocket

This is an example of connecting to multiple streams

import asyncio

from aio_binance.futures.usdt import WsClient


async def callback_event(data: dict):
    print(data)


async def main():

    ws = WsClient()
    stream = [
        ws.stream_liquidation_order(),
        ws.stream_book_ticker(),
        ws.stream_ticker('BTCUSDT')
    ]
    res = await asyncio.gather(*stream)
    await ws.subscription_streams(res, callback_event)

asyncio.run(main())

More websocket examples are available in the examples folder

Note

Stream methods start with the word stream Example: stream_<name_method>

Subscribing to multiple streams: subscription_streams()

Heartbeat

Once connected, the websocket server sends a ping frame every 3 minutes and requires a response pong frame back within a 5 minutes period. This package handles the pong responses automatically.

You might also like...
A modern,feature-rich, and async ready API wrapper for Discord written in Python

discord.io A modern, easy to use, feature-rich, and async ready API wrapper for Discord written in Python. Key Features Modern Pythonic API using asyn

An async python wrapper to interact with the Steam API and its CMs

steam.py A modern, easy to use, and async ready package to interact with the Steam API. Heavily inspired by discord.py and borrowing functionality fro

An async-ready Python wrapper around FerrisChat's API.

FerrisWheel An async-ready Python wrapper around FerrisChat's API. Installation Instructions Linux: $ python3.9 -m pip install -U ferriswheel Python 3

A modern, easy to use, feature-rich, and async ready API wrapper for Discord written in Python.

disfork A modern, easy to use, feature-rich, and async ready API wrapper for Discord written in Python. Key Features Modern Pythonic API using async a

A python API for BSCScan (Binance Smart Chain Explorer), available on PyPI.

bscscan-python A complete Python API for BscScan.com, available on PyPI. Powered by BscScan.com APIs. This is a gently modified fork of the etherscan-

Trading through Binance's API using Python & sqlite

pycrypt Automate trading crypto using Python to pull data from Binance's API and analyse trends. May or may not consistently lose money but oh well it

McTrade is a bot exploiting Binance API, open source! built in python !

Open Source Crypto Trading Bot using Binance API Report Bug · Request Feature Table of Contents About The Project Built With Getting Started Prerequis

An unofficial Python wrapper for the 'Binance exchange REST API'

Welcome to binex_f v0.1.0 many interfaces are heavily used by myself in product environment, the websocket is reliable (re)connected. Latest version:

Async client API for the Telegram Group Calls
Async client API for the Telegram Group Calls

PyTgCalls This project allow to make Telegram group call with MTProto Api using Pyrogram and WebRTC, this is possible thanks to the power of NodeJS's

Owner
GRinvest
GRinvest
A Bot to Upload files to Many Cloud services. Powered by Telethon.

oVo MultiUpload V1.0 👀 A Bot to Upload files to Many Cloud services. Powered by Telethon _ 🎯 Follow me and star this repo for more telegram bots. @H

32 Dec 30, 2022
Discord bot for user notes.

Noter A discord bot for handling notes for users. Want to keep track of things about your discord users? Then this bot is for you! Links DB Browser fo

Ori 2 Jun 05, 2022
Telegram bot for downloading covid-19 vaccine certificate

cowin-certificate-bot This is the source code of @cowincertbot, A telegram bot inspired by the whatsapp bot implementation of indian government for co

ArUn Pt 30 Oct 07, 2022
Token-gate Notion pages

This is a Next.js project bootstrapped with create-next-app. Getting Started First, run the development server: npm run dev # or yarn dev Open http://

John 8 Oct 13, 2022
Start multiple bots using one script. VK RAID BOTNET

MultiRaidBotnet Start multiple bots using one script. VK RAID BOTNET Русский launcher.py - главный скрипт, запускающий весь ботнет config.py - в нём х

2 Jul 22, 2022
TuShare is a utility for crawling historical data of China stocks

TuShare Tushare Pro版已发布,请访问新的官网了解和查询数据接口! https://tushare.pro TuShare是实现对股票/期货等金融数据从数据采集、清洗加工 到 数据存储过程的工具,满足金融量化分析师和学习数据分析的人在数据获取方面的需求,它的特点是数据覆盖范围广,接口

挖地兔 11.9k Dec 30, 2022
The Official Dropbox API V2 SDK for Python

The offical Dropbox SDK for Python. Documentation can be found on Read The Docs. Installation Create an app via the Developer Console. Install via pip

Dropbox 828 Jan 05, 2023
A bot written in Python to automate attending classes on MyClass (Codetantra).

codetantrabot This is python program to attend class on myclass(codetantra) Prerequisites You should have Python3 and Pip installed on your system Run

Aniket Kumar 1 Feb 08, 2022
A Simple and User-Friendly Google Collab Notebook with UI to transfer your data from Mega to Google Drive.

Mega to Google Drive (UI Added! 😊 ) A Simple and User-Friendly Google Collab Notebook with UI to transfer your data from Mega to Google Drive. ⚙️ How

Dr.Caduceus 18 Aug 16, 2022
An open source raffle bot made to increase the chance of winning limited sneaker raffles by automating entries.

🚀 SyneziaRaffles An open source raffle bot made to increase the chance of winning limited sneaker raffles by automating entries. 🏄‍♂️ Quick Start Pr

Alexis M. 29 Dec 22, 2022
Telegram anime bot that uses Anilist API

Telegram Bot Repo Capable of fetching the following Info via Anilist API inspired from AniFluid and Nepgear Anime Airing Manga Character Scheduled Top

Lucky Jain 71 Jan 03, 2023
Discord Mafia Game Bot using nextcord

Mafia-Bot Discord Mafia Game Bot using nextcord Features Mafia Game Game Replays Installation Run the following command to install required modules: p

Nian 6 Nov 19, 2022
Repository for the IPvSeeYou talk at Black Hat 2021

IPvSeeYou Geolocation Lookup Tool Overview IPvSeeYou.py is a tool to assist with geolocating EUI-64 IPv6 hosts. It takes as input an EUI-64-derived MA

57 Nov 08, 2022
✨ A Telegram mirror/leech bot By SparkXcloud Group ✨

SparkXcloud-Gdrive-MirrorBot SparkXcloud-Gdrive-MirrorBot is a multipurpose Telegram Bot writen in Python for mirroring files on the Internet to our b

119 Oct 23, 2022
An information scroller Twitter trends, news, weather for raspberry pi and Pimoroni Unicorn Hat Mini and Scroll Phat HD.

uticker An information scroller Twitter trends, news, weather for raspberry pi and Pimoroni Unicorn Hat Mini and Scroll Phat HD. Features include: Twi

Tansu Şenyurt 1 Nov 28, 2021
Simple contact bot for telegram, written in python.

🔗 | Install Install the requirements with pip install -r requirements.txt 📋 | Setup Get your token from BotFather Get your UserId with Nicegram or w

Stehack 3 Dec 10, 2022
Smilecreator4 - This site is for people who want to hack or want to learn it!

smilecreator4 This site is for people who want to hack or want to learn it! Furthermore, this program does not work without turning off Antivirus or W

1 Jan 04, 2022
NekoRobot-2 - Neko is An Anime themed advance Telegram group management bot.

NekoRobot A modular telegram Python bot running on python3 with an sqlalchemy, mongodb database. ╒═══「 Status 」 Maintained Support Group Included Free

Lovely Boy 19 Nov 12, 2022
“ HOLA HUMANS 👋 I'M DAISYX 2.0 „ LATEST VERSION OF DAISYX.. Source Code of @Daisyxbot

DaisyX 2.0 A Powerful, Smart And Simple Group Manager ... Written with AioGram , Pyrogram and Telethon... The first AioGram based modified groupmanage

TeamDaisyX 153 Dec 06, 2022
Companion "receiver" to matrix-appservice-webhooks for [matrix].

Matrix Webhook Receiver Companion "receiver" to matrix-appservice-webhooks for [matrix]. The purpose of this app is to listen for generic webhook mess

Kim Brose 13 Sep 29, 2022