Skip to content

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

@VizXu

Description

@VizXu

测试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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions