-
Notifications
You must be signed in to change notification settings - Fork 671
Description
测试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.