-
Notifications
You must be signed in to change notification settings - Fork 133
Open
Description
Question to MEXC Support: .pb WebSocket Channel Data Format
Context
We are integrating the MEXC Spot WebSocket API, specifically the .pb channels (e.g., spot@public.kline.v3.api.pb@BTCUSDT@Min1).
We have tested the official Python demo (link) and analyzed the received messages.
Python Example (with English comments)
import asyncio
import websockets
async def main():
url = "wss://wbs.mexc.com/ws"
async with websockets.connect(url) as ws:
# Subscribe to the .pb kline channel
await ws.send('{"method": "SUBSCRIPTION", "params": ["spot@public.kline.v3.api.pb@BTCUSDT@Min1"]}')
while True:
msg = await ws.recv()
# msg is bytes, not JSON!
if isinstance(msg, bytes):
# Try to decode as UTF-8, ignoring errors
text = msg.decode('utf-8', errors='ignore')
# Print the split string for manual parsing
print(f"RAW: {text.strip().split()}")
else:
print(f"RAW: {msg}")
# There is no protobuf or JSON parsing here!
asyncio.run(main())Our findings
- The data received from the
.pbchannel is not JSON and is received as raw bytes. - We tried to parse the data as protobuf, but there is no official
.protoschema or example in your documentation. - The official Python demo does not use protobuf parsing, but simply decodes the bytes as a string and splits it to extract values.
- We could not find a timestamp (windowstart/windowend) in the received data, only prices and volumes as ASCII strings.
Questions
- Is the
.pbchannel data truly protobuf-encoded, or is it just a custom binary/text format? - If it is protobuf, could you provide the exact
.protoschema and an example of how to properly decode the messages using a protobuf library in Python? - If the recommended way is to parse the data as a string, could you confirm that this is the intended and supported approach?
- Is there a reliable way to extract the candle timestamp (windowstart/windowend) from the binary message, or is it only available in the JSON API?
References
- Official API documentation: K-line Streams
- Official Python demo: spotV3_websocket_python_demo.py
We sincerely do not understand why the channel is called protobuf (.pb) if there is no protobuf schema or decoding in the official documentation or demo. Could you please clarify the intended usage?
Thank you for your help!
shevamytra, aperechnev, GrandF17 and DoganM95
Metadata
Metadata
Assignees
Labels
No labels