Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Binance Testnet user_socket() problem. #1388

Open
ANWB2020 opened this issue Jan 1, 2024 · 0 comments
Open

Binance Testnet user_socket() problem. #1388

ANWB2020 opened this issue Jan 1, 2024 · 0 comments

Comments

@ANWB2020
Copy link

ANWB2020 commented Jan 1, 2024

Binance Python: 1.0.10
Python: 3.10

Hello,

I have published this issue also on Binance Developer., but didn't get answer.

My issue:

I don't get response from user_socket and do not know if my code is right.

I use Python Binance and asyncIO for parallel processing.

I’m expecting from my program:

  • sending an order via order_market_buy() (ok and tested via get_my_trades())
    
  • response from user_socket() after change in balance. (that's not running, I receive nothing)
    

What's wrong with my code? Do you have any suggestions for my following code?

import asyncio
from binance import AsyncClient, BinanceSocketManager
import os
import datetime

api_key = os.environ.get('binance_api_key_test')
api_secret = os.environ.get('binance_api_secret_test')


async def user_socket(client):
    bm = BinanceSocketManager(client)
    ts = bm.user_socket()
    async with ts as tscm:
        while True:
            res = await tscm.recv()
            print("user socket: ", res)


async def set_order_market_buy(symbol, quantity, client):
    await asyncio.sleep(5)  # waiting user_socket
    await client.order_market_buy(
        symbol=symbol,
        quantity=quantity)
    result = await client.get_my_trades(symbol=symbol, limit=1)
    print("last order: ", datetime.datetime.fromtimestamp(result[0]['time']/1000))  # converts trade time in normal date

    await client.close_connection()


async def aux():
    client = await AsyncClient.create(api_key, api_secret)
    client.API_URL = 'https://testnet.binance.vision/api'
    user_socket2 = asyncio.create_task(user_socket(client=client))
    task_order = asyncio.create_task(set_order_market_buy(symbol='BTCUSDT', quantity=0.001, client=client))

    await user_socket2
    await task_order


if __name__ == "__main__":
    asyncio.run(aux())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant