Bug: UserDataStreamEventsResponse can not perform model_validate_json correctly
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức phù hợp với người mới
- 65/100
Hướng nghiên cứu
Bắt đầu trong common/src/binance_common/websocket.py, tại phần xử lý đăng ký stream, sau đó kiểm tra UserDataStreamEventsResponse và OrderTradeUpdate. Tái hiện vấn đề bằng JSON được cung cấp và lệnh gọi model_validate_json. Hoàn tất khi payload ORDER_TRADE_UPDATE được xác thực thành mô hình sự kiện như mong đợi thay vì để actual_instance không được thiết lập.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Description:
UserDataStreamEventsResponse can't serialize data properly, and this makes DerivativesTradingUsdsFuturesWebSocketStreams.user_data not working as expected.
Steps to reproduce:
import asyncio
import os
import logging
from binance_sdk_derivatives_trading_usds_futures.derivatives_trading_usds_futures import (
DerivativesTradingUsdsFutures,
DERIVATIVES_TRADING_USDS_FUTURES_WS_STREAMS_PROD_URL,
ConfigurationWebSocketStreams,
)
# Configure logging
logging.basicConfig(level=logging.INFO)
# Create configuration for the WebSocket Streams
configuration_ws_streams = ConfigurationWebSocketStreams(
stream_url=os.getenv(
"STREAM_URL", DERIVATIVES_TRADING_USDS_FUTURES_WS_STREAMS_PROD_URL
)
)
# Initialize DerivativesTradingUsdsFutures client
client = DerivativesTradingUsdsFutures(config_ws_streams=configuration_ws_streams)
async def run(listen_key):
conn = None
try:
conn = await client.websocket_streams.create_connection()
user_data_stream = await conn.user_data(listenKey=listen_key)
user_data_stream.on("message", lambda x: print(f'{x}'))
while True:
await asyncio.sleep(0)
except Exception as e:
logging.error(e, exc_info=True)
finally:
if conn:
await conn.close_connection(close_session=True)
Which gives outputs:
oneof_schema_1_validator=None oneof_schema_2_validator=None oneof_schema_3_validator=None oneof_schema_4_validator=None oneof_schema_5_validator=None oneof_schema_6_validator=None oneof_schema_7_validator=None oneof_schema_8_validator=None oneof_schema_9_validator=None actual_instance=None one_of_schemas={'StrategyUpdate', 'ConditionalOrderTriggerReject', 'MarginCall', 'Listenkeyexpired', 'TradeLite', 'GridUpdate', 'OrderTradeUpdate', 'AccountConfigUpdate', 'AccountUpdate'} discriminator_value_class_map={}
Possible root cause:
Stream subscriptions are handled by here, but seems UserDataStreamEventsResponse can not perform model_validate_json properly:
In [4]: json.dumps(d)
Out[4]: '{"e": "ORDER_TRADE_UPDATE", "E": 1568879465651, "T": 1568879465650, "o": {"s": "BTCUSDT", "c": "TEST", "S": "SELL", "o": "TRAILING_STOP_MARKET", "f": "GTC", "q": "0.001", "p": "0", "ap": "0", "sp": "7103.04", "x": "NEW", "X": "NEW", "i": 8886774, "l": "0", "z": "0", "L": "0", "N": "USDT", "n": "0", "T": 1568879465650, "t": 0, "b": "0", "a": "9.91", "m": false, "R": false, "wt": "CONTRACT_PRICE", "ot": "TRAILING_STOP_MARKET", "ps": "LONG", "cp": false, "AP": "7476.89", "cr": "5.0", "pP": false, "si": 0, "ss": 0, "rp": "0", "V": "EXPIRE_TAKER", "pm": "OPPONENT", "gtd": 0}}'
In [5]: OrderTradeUpdate.model_validate(d)
Out[5]: OrderTradeUpdate(E=1568879465651, T=1568879465650, o=OrderTradeUpdateO(s='BTCUSDT', c='TEST', S='SELL', o='TRAILING_STOP_MARKET', f='GTC', q='0.001', p='0', ap='0', sp='7103.04', x='NEW', X='NEW', i=8886774, l='0', z='0', L='0', N='USDT', n='0', T=1568879465650, t=0, b='0', a='9.91', m=False, R=False, wt='CONTRACT_PRICE', ot='TRAILING_STOP_MARKET', ps='LONG', cp=False, AP='7476.89', cr='5.0', pP=False, si=0, ss=0, rp='0', V='EXPIRE_TAKER', pm='OPPONENT', gtd=0, additional_properties={}), additional_properties={})
In [6]: UserDataStreamEventsResponse.model_validate_json(json.dumps(d))
Out[6]: UserDataStreamEventsResponse(oneof_schema_1_validator=None, oneof_schema_2_validator=None, oneof_schema_3_validator=None, oneof_schema_4_validator=None, oneof_schema_5_validator=None, oneof_schema_6_validator=None, oneof_schema_7_validator=None, oneof_schema_8_validator=None, oneof_schema_9_validator=None, actual_instance=None, one_of_schemas={'AccountConfigUpdate', 'MarginCall', 'Listenkeyexpired', 'AccountUpdate', 'StrategyUpdate', 'ConditionalOrderTriggerReject', 'TradeLite', 'OrderTradeUpdate', 'GridUpdate'}, discriminator_value_class_map={})
- Ngôn ngữ chính
- Python
- Star
- 2.9k
- Fork
- 699
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Chuẩn bị môi trường
Chúng tôi chưa kiểm tra các tệp thiết lập môi trường của dự án này. Hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của binance/binance-connector-python
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
binance/binance-connector-python#514 · 1 bình luận ·
-
Answered
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 64/100
binance/binance-connector-python#502 · 3 bình luận ·
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 68/100
binance/binance-connector-python#553 · 2 bình luận ·
-
Answered
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 68/100
binance/binance-connector-python#513 · 2 bình luận ·
-
Answered
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 56/100
binance/binance-connector-python#512 · 1 bình luận ·
Tất cả issue của binance/binance-connector-python
Issue tương tự
-
documentation
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
kristofdegrave/homeassistant-smart-charging#1413 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
nasa/earthdata-varinfo#113 ·
-
curriculum documentation quality
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
githubnext/gh-aw-workshop#3849 ·
Maintainer thường phản hồi trong vòng 2 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 90/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
Maintainer thường phản hồi trong vòng 1 ngày