binance-connector-python icon indicating copy to clipboard operation
binance-connector-python copied to clipboard

在ucloud云主机,用ubuntu22.04的OS,拉取k线失败

Open VizXu opened this issue 9 months ago • 2 comments

测试demo用的是example中的,如下: import asyncio import os import logging

from binance_sdk_spot.spot import Spot, SPOT_WS_API_PROD_URL, ConfigurationWebSocketAPI

from binance_sdk_spot.websocket_api.models import KlinesIntervalEnum

Configure logging

logging.basicConfig(level=logging.INFO)

Create configuration for the WebSocket API

configuration_ws_api = ConfigurationWebSocketAPI( api_key=os.getenv("API_KEY", ""), api_secret=os.getenv("API_SECRET", ""), stream_url=os.getenv("STREAM_URL", SPOT_WS_API_PROD_URL), )

Initialize Spot client

client = Spot(config_ws_api=configuration_ws_api)

async def klines(): connection = None try: connection = await client.websocket_api.create_connection()

    response = await connection.klines(
        symbol="BNBUSDT",
        interval=KlinesIntervalEnum["INTERVAL_1s"].value,
    )

    rate_limits = response.rate_limits
    logging.info(f"klines() rate limits: {rate_limits}")

    data = response.data()
    logging.info(f"klines() response: {data}")

except Exception as e:
    logging.error(f"klines() error: {e}")
finally:
    if connection:
        await connection.close_connection(close_session=True)

if name == "main": asyncio.run(klines())

失败日志: INFO:root:Connecting to wss://ws-api.binance.com:443/ws-api/v3 with proxy None INFO:root:Establishing Websocket connection with id 3b3fd9f4-bfc2-4b1a-9ea3-9f1184eb39cf to: wss://ws-api.binance.com:443/ws-api/v3 INFO:root:Sending message to WebSocket 3b3fd9f4-bfc2-4b1a-9ea3-9f1184eb39cf: {'method': 'klines', 'params': {'symbol': 'BNBUSDT', 'interval': '1s'}, 'id': 'fb74304c-3637-4953-807e-5a68e95406ca'} INFO:root:klines() rate limits: [WebsocketApiRateLimit(rateLimitType='REQUEST_WEIGHT', interval='MINUTE', intervalNum=1, limit=6000, count=4)] ERROR:root:klines() error: type object 'str' has no attribute 'is_array' INFO:root:WebSocket 3b3fd9f4-bfc2-4b1a-9ea3-9f1184eb39cf closed.

VizXu avatar Feb 24 '26 17:02 VizXu

Hey @VizXu, Thank you for reporting this issue. It has been resolved in release v7.2.0. Please give it a try and feel free to open a new issue if you encounter any problems.

alplabin avatar Feb 25 '26 10:02 alplabin

Hey @VizXu, I will close this issue. If you encounter any new issue, feel free to open a new github issue.

alplabin avatar Apr 27 '26 02:04 alplabin