Skip to content

.pb WebSocket Channel Data Format #106

@koshak01

Description

@koshak01

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 .pb channel is not JSON and is received as raw bytes.
  • We tried to parse the data as protobuf, but there is no official .proto schema 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

  1. Is the .pb channel data truly protobuf-encoded, or is it just a custom binary/text format?
  2. If it is protobuf, could you provide the exact .proto schema and an example of how to properly decode the messages using a protobuf library in Python?
  3. If the recommended way is to parse the data as a string, could you confirm that this is the intended and supported approach?
  4. 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


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!

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