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
:lock: Python 2.7/3.X client for HashiCorp Vault

hvac HashiCorp Vault API client for Python 3.x Tested against the latest release, HEAD ref, and 3 previous minor versions (counting back from the late

hvac 1k Dec 29, 2022
Quickly and efficiently delete your entire tweet history with the help of your Twitter archive without worrying about the pointless 3200 tweet limit imposed by Twitter.

Twitter Nuke Quickly and efficiently delete your entire tweet history with the help of your Twitter archive without worrying about the puny and pointl

Mayur Bhoi 73 Dec 12, 2022
A telegram bot for generate fake details. Written in python using telethon

FakeDataGenerator A telegram bot for generate fake details. Written in python using telethon. Mandatory variables API_HASH Get it from my telegram.org

Oxidised-Man 6 Dec 19, 2021
Python3 based bittrex rest api wrapper

bittrex-rest-api This open source project was created to give an understanding of the Bittrex Rest API v1.1/v3.0 in pearl language. The sample file sh

4 Nov 15, 2022
Changes your desktop wallpaper based on the weather.

WallPaperChanger ๐Ÿ–ผ๏ธ Description โ›ˆ๏ธ This Python script changes your desktop wallpaper based on the weather. Cloning ๐ŸŒ€ $ git clone https://github.com/

Clarence Yang 74 Nov 29, 2022
Unofficial WebApp for WhatsApp Web created in PyQt6

Unofficial WebApp for WhatsApp Web created in PyQt6 using PyQt6-WebEngine

Rafael Tosta Santos 126 Dec 20, 2022
Recommended AWS CDK project structure for Python applications

Recommended AWS CDK project structure for Python applications The project implements a user management backend component that uses Amazon API Gateway,

AWS Samples 110 Jan 06, 2023
๐Ÿค– Fast and simple bot to transform links from Amazon into a nice post with your referral link in Telegram ๐Ÿ›’

AmazonBot ๐Ÿค– Fast and simple bot to transform links from Amazon into a nice post with your referral link in Telegram ๐Ÿ›’ Prerequisites You need Python

Alternative Profit 3 Dec 25, 2022
A simple script that loads and hot-reloads cogs when you save any changes

DiscordBot-HotReload A simple script that loads and hot-reloads cogs when you save any changes Usage @bot.event async def on_ready(): from HotRelo

2 Jan 14, 2022
่‡ช็”จ็›ดๆ’ญๆบ้›†ๅˆ๏ผŒ้™„ๅธฆๆฃ€ๆต‹ไธŽๅˆ†็ฑปๅŠŸ่ƒฝใ€‚

myiptv ่‡ช็”จ็›ดๆ’ญๆบ้›†ๅˆ๏ผŒ้™„ๅธฆๆฃ€ๆต‹ไธŽๅˆ†็ฑปๅŠŸ่ƒฝใ€‚ ไธบๅ•ฅๆž TLDR: ๅคช้—ฒไบ†ใ€‚ ่‡ชๅทฑๆœ‰ๆ”ถ้›†็›ดๆ’ญๆบ็š„็ˆฑๅฅฝ๏ผŒๅ’Œๅฝ•ๅˆถ็›ดๆ’ญๆบ็š„้œ€ๆฑ‚ใ€‚ ไธ€ไบ›่ฝฏไปถ่‡ชๅธฆ็š„็›ดๆ’ญๆบๅคช่ฟ‡้šพ็”จใ€‚ ็ฝ‘ไธŠ็Žฐๆœ‰็š„็›ดๆ’ญๆบๅคชๆ‚๏ผŒไธ”็ผบไนๆฃ€ๆต‹ใ€‚ ไธ€ไบ›ๅคงๆบ็ผบไนๆŒ็ปญๆ›ดๆ–ฐ๏ผŒๅฆ‚ iptv-orgใ€‚ ไฝฟ็”จๆŒ‡ๅ—ไธŽ TODO ๆฏๆฌก่ฟ›่กŒๅคงๆ›ดๆ–ฐๅŽ้ƒฝไผš่ฟ›่กŒไธ€ๆฌก rel

abc1763613206 171 Dec 11, 2022
Find rare users in discord servers

BadgeScraper Find rare users in discord servers How to use Replace the guild_id, server_id and token by the values you wanna use If you never used dis

20 Dec 09, 2022
A pdisk uploader bot written in Python

Pdisk Uploader Bot ๐Ÿ”ฅ Upload on Pdisk by Url, File and also by direct forward post from other channel... Features Post to Post Conversion Url Upload D

Paritosh Kumar 33 Oct 21, 2022
Scrape the Twitter Frontend API without authentication.

Twitter Scraper ๐Ÿ‡ฐ๐Ÿ‡ท Read Korean Version Twitter's API is annoying to work with, and has lots of limitations โ€” luckily their frontend (JavaScript) has

BuฤŸra ฤฐลŸgรผzar 3.4k Jan 08, 2023
fair-test is a library to build and deploy FAIR metrics tests APIs supporting the specifications used by the FAIRMetrics working group.

โ˜‘๏ธ FAIR test fair-test is a library to build and deploy FAIR metrics tests APIs supporting the specifications used by the FAIRMetrics working group. I

Maastricht University IDS 6 Oct 30, 2022
Slack bot for monitoring your Metaflow flows!

Metaflowbot - Slack Bot for your Metaflow flows! Metaflowbot makes it fun and easy to monitor your Metaflow runs, past and present. Imagine starting a

Outerbounds 21 Dec 07, 2022
Sail is a free CLI tool to deploy, manage and scale WordPress applications in the DigitalOcean cloud.

Deploy WordPress to DigitalOcean with Sail Sail is a free CLI tool to deploy, manage and scale WordPress applications in the DigitalOcean cloud. Conte

Konstantin Kovshenin 159 Dec 12, 2022
Python library for the Stripe API.

Stripe Python Library The Stripe Python library provides convenient access to the Stripe API from applications written in the Python language. It incl

Stripe 1.3k Jan 03, 2023
โšก ส‘ษ  แƒชฦกษฌ Is One Of The Fastest & Smoothest Bot On Telegram Based on Telethon โšก

ใ€Žส‘ษ  แƒชฦกษฌใ€ โšก ส‘ษ  แƒชฦกษฌ Is One Of The Fastest & Smoothest Bot On Telegram Based on Telethon โšก Status Of Bot Telegram ๐Ÿช Dั”ฯโ„“ฮฟฮณ ฯ„ฮฟ ะฝั”ัฮฟฮบฯ… Variables APP_ID =

ส‘ษ‘ส‘ษ“ษฆษ‘ษช 0 Feb 12, 2022
Dns-Client-Server - Dns Client Server For Python

Dns-client-server DNS Server: supporting all types of queries and replies. Shoul

Nishant Badgujar 1 Feb 15, 2022