Skip to content

[Feature Request] recent_trades_stream always returns a list even though it only has one item #358

@slokib

Description

@slokib

The recent_trades_stream WebSocket always returns the trade inside a list, even though there is only one trade every time. This makes the code harder to use because I have to loop or index the list just to get one dictionary.

Example of recent trades stream (from documentation):

{
    "topic": "publicTrade.BTCUSDT",
    "type": "snapshot",
    "ts": 1672304486868,
    "data": [
        {
            "T": 1672304486865,
            "s": "BTCUSDT",
            "S": "Buy",
            "v": "0.001",
            "p": "16578.50",
            "L": "PlusTick",
            "i": "20f43950-d8dd-5b31-9112-a178eb6023af",
            "BT": false,
            "seq": 1783284617
        }
    ]
}

I always have to do:

trade = message["data"][0]

Example of ticker data (from the documentation):

{
  "topic": "tickers.BTCUSDT",
  "type": "snapshot",
  "data": {
    "symbol": "BTCUSDT",
    "lastPrice": "66666.60",
    "markPrice": "66666.60",
    "indexPrice": "115418.19",
    "bid1Price": "66666.60",
    "ask1Price": "66666.70"
  }
}

Ticker data is a dictionary, so I can access it directly:

message["data"]["lastPrice"]

Request

It would be nice if PyBit could unwrap the list for recent trades or provide an option, so it works more like ticker data and is easier to access.

Thanks.


Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions