Finding the price for market orders

If I placed a market order from RESTful API, how do I find out how much the filled price was?

For spot, let’s say place the market order via POST /api/v3/order, the return json will look something like this:

{
    "symbol": "BNBUSDT",
    "orderId": 168,
    "orderListId": -1,
    "clientOrderId": "xxxx",
    "transactTime": 1590967624991,
    "price": "0.00000000", // original price from client, market order
    "origQty": "11.00000000",
    "executedQty": "11.00000000",
    "cummulativeQuoteQty": "220.00000000",
    "status": "FILLED",
    "timeInForce": "GTC",
    "type": "MARKET",
    "side": "BUY",
    "fills": [
        {
            "price": "20.00000000", // filled price
            "qty": "1.00000000",
            "commission": "0.00000000",
            "commissionAsset": "BNB",
            "tradeId": 109
        },
        {
            "price": "20.00000000",
            "qty": "1.00000000",
            "commission": "0.00000000",
            "commissionAsset": "BNB",
            "tradeId": 110
        },
        {
            "price": "20.00000000",
            "qty": "9.00000000",
            "commission": "0.00000000",
            "commissionAsset": "BNB",
            "tradeId": 111
        }
    ]
}

The price in the fills from response data will give the matched price on each trades. The price may not be the same depending on the time of the fill.

This can also be found via the USER_DATA websocket, in the executionReport, there is a L field also returns the filled price.

{
    "e": "executionReport",
    "E": 1590967624994,
    "s": "BNBUSDT",
    "c": "2uD5fKxrgPpKxG3kxuuNNu",
    "S": "SELL",
    "o": "LIMIT",
    "f": "GTC",
    "q": "10.00000000",
    "p": "20.00000000",
    "P": "0.00000000",
    "F": "1.00000000",
    "g": -1,
    "C": "",
    "x": "TRADE",
    "X": "PARTIALLY_FILLED",
    "r": "NONE",
    "i": 166,
    "l": "1.00000000",
    "z": "1.00000000",
    "L": "20.00000000", // filed price
    "n": "0.00000000",
    "N": "USDT",
    "T": 1590967624991,
    "t": 110,
    "I": 424,
    "w": false,
    "m": true,
    "M": true,
    "O": 1590580465764,
    "Z": "20.00000000",
    "Y": "20.00000000",
    "Q": "0.00000000"
}

In futures, it’s a little different. In the endpoint POST /fapi/v1/order, for the parameter newOrderRespType:

  • if set to ACK, the API server will return the response immedicately after the order is “accepted” even it’s a market order. For example the response could be like:
{
    "orderId": 2413122813,
    "symbol": "BTCUSDT",
    "status": "NEW",
    "clientOrderId": "35wZAHMuvMSgmKKnTOA8Yy",
    "price": "0",
    "avgPrice": "0.00000",
    "origQty": "1",
    "executedQty": "0",
    "cumQty": "0",
    "cumQuote": "0",
    "timeInForce": "GTC",
    "type": "MARKET",
    "reduceOnly": false,
    "closePosition": false,
    "side": "BUY",
    "positionSide": "BOTH",
    "stopPrice": "0",
    "workingType": "CONTRACT_PRICE",
    "origType": "MARKET",
    "updateTime": 1590968491388
}

From the websocket connection, server will push 2 messages:


# first message
{
    "e": "ORDER_TRADE_UPDATE",
    "T": 1590968491388,
    "E": 1590968491390,
    "o": {
        "s": "BTCUSDT",
        "c": "35wZAHMuvMSgmKKnTOA8Yy",
        "S": "BUY",
        "o": "MARKET",
        "f": "GTC",
        "q": "1",
        "p": "0",
        "ap": "0",
        "sp": "0",
        "x": "NEW",
        "X": "NEW",
        "i": 2413122813,
        "l": "0",
        "z": "0",
        "L": "0", // it's 0 here
        "T": 1590968491388,
        "t": 0,
        "b": "0",
        "a": "0",
        "m": false,
        "R": false,
        "wt": "CONTRACT_PRICE",
        "ot": "MARKET",
        "ps": "BOTH",
        "cp": false
    }
}

# second one
{
    "e": "ORDER_TRADE_UPDATE",
    "T": 1590968491388,
    "E": 1590968491390,
    "o": {
        "s": "BTCUSDT",
        "c": "35wZAHMuvMSgmKKnTOA8Yy",
        "S": "BUY",
        "o": "MARKET",
        "f": "GTC",
        "q": "1",
        "p": "0",
        "ap": "9402.88000",
        "sp": "0",
        "x": "TRADE",
        "X": "FILLED",
        "i": 2413122813,
        "l": "1",
        "z": "1",
        "L": "9402.88", // the filled price
        "n": "3.76115199",
        "N": "USDT",
        "T": 1590968491388,
        "t": 133344561,
        "b": "0",
        "a": "0",
        "m": false,
        "R": false,
        "wt": "CONTRACT_PRICE",
        "ot": "MARKET",
        "ps": "BOTH",
        "cp": false
    }
}

The second message with FILLED status tells the matching price.

  • if set to RESULT, this endpoint acts similar like the spot one. It returns the FILLED status with avgPrice instantly. e.g.
{
    "orderId": 2413175154,
    "symbol": "BTCUSDT",
    "status": "FILLED",
    "clientOrderId": "Lp12Nq0OoBYTF7zyqZGl3n",
    "price": "0",
    "avgPrice": "9452.71000", // avg filled price
    "origQty": "1",
    "executedQty": "1",
    "cumQty": "1",
    "cumQuote": "9452.71000",
    "timeInForce": "GTC",
    "type": "MARKET",
    "reduceOnly": false,
    "closePosition": false,
    "side": "BUY",
    "positionSide": "BOTH",
    "stopPrice": "0",
    "workingType": "CONTRACT_PRICE",
    "origType": "MARKET",
    "updateTime": 1590969041003
}

and there will be only one message from websocket connection:

{
    "e": "ORDER_TRADE_UPDATE",
    "T": 1590969041003,
    "E": 1590969041006,
    "o": {
        "s": "BTCUSDT",
        "c": "Lp12Nq0OoBYTF7zyqZGl3n",
        "S": "BUY",
        "o": "MARKET",
        "f": "GTC",
        "q": "1",
        "p": "0",
        "ap": "9452.71000", // avg price
        "sp": "0",
        "x": "TRADE",
        "X": "FILLED",
        "i": 2413175154,
        "l": "1",
        "z": "1",
        "L": "9452.71", // last filled price
        "n": "3.78108399",
        "N": "USDT",
        "T": 1590969041003,
        "t": 133350643,
        "b": "0",
        "a": "0",
        "m": false,
        "R": false,
        "wt": "CONTRACT_PRICE",
        "ot": "MARKET",
        "ps": "BOTH",
        "cp": false
    }
}