sammchardy / python-binance

Binance Exchange API python implementation for automated trading
https://python-binance.readthedocs.io/en/latest/
MIT License
6.06k stars 2.21k forks source link

Unclosed client session with insufficient balance #1124

Closed alexromlex closed 2 years ago

alexromlex commented 2 years ago

If BTC deposite low, script get a error like:

Unclosed client session
client_session: <aiohttp.client.ClientSession object at 0x7f733f79f070>
Unclosed connector
connections: ['[(<aiohttp.client_proto.ResponseHandler object at 0x7f733f791880>, 21977.697)]']
connector: <aiohttp.connector.TCPConnector object at 0x7f733f79f0a0>
INFO:     ....... - "POST /api/binance/new_order?symbol_name=BNBBTC&side=BUY&type=LIMIT&quantity=0.01&price=0.01&timeInForce=GTC HTTP/1.1" 400 Bad Request

My code:

import asyncio
from binance import AsyncClient`
BIN_KEY, BIN_SEC = ['...','....']

async def send_order():
    client = await AsyncClient.create(api_key=BIN_KEY, api_secret=BIN_SEC)
    order_resp = await client.create_order(
        symbol='BNBBTC',
        side='BUY',
        type='LIMIT',
        timeInForce='GTC',
        quantity=0.02,
        price=0.01)
    print(order_resp)
    await client.close_connection()
    return order_resp

if __name__ == "__main__":
    loop = asyncio.get_event_loop()
    loop.run_until_complete(send_order())`

If i send a POST request by Postman, it gets responce:

{
    "code": -2010,
    "msg": "Account has insufficient balance for requested action."
}

It will be nice, if binance-python can handle this rerror too

alexromlex commented 2 years ago

I have handled itt with BinanceAPIException