BUG: allOrders API returns price=0 for all market orders

As title.

Here’s a sample:

$ ./bi GET allOrders symbol=XRPDOWNUSDT | tail -n 1 | jq '.' | grep -C12 MARKET
--
  },
  {
    "symbol": "XRPDOWNUSDT",
    "orderId": 126268443,
    "orderListId": -1,
    "clientOrderId": "and_9c511cb9a39945f2b6ae00ad41689acd",
    "price": "0.00000000",
    "origQty": "390043.43000000",
    "executedQty": "390043.43000000",
    "cummulativeQuoteQty": "6199.99990455",
    "status": "FILLED",
    "timeInForce": "GTC",
    "type": "MARKET",
    "side": "BUY",
    "stopPrice": "0.00000000",
    "icebergQty": "0.00000000",
    "time": 1621516337077,
    "updateTime": 1621516337077,
    "isWorking": true,
    "origQuoteOrderQty": "6200.00000000"
  },
  {
    "symbol": "XRPDOWNUSDT",
    "orderId": 126270115,
    "orderListId": -1,
--
  },
  {
    "symbol": "XRPDOWNUSDT",
    "orderId": 130553768,
    "orderListId": -1,
    "clientOrderId": "and_1e4295d2e9aa49a69739c289df714002",
    "price": "0.00000000",
    "origQty": "357598.50000000",
    "executedQty": "357598.50000000",
    "cummulativeQuoteQty": "6799.99995521",
    "status": "FILLED",
    "timeInForce": "GTC",
    "type": "MARKET",
    "side": "BUY",
    "stopPrice": "0.00000000",
    "icebergQty": "0.00000000",
    "time": 1621604685980,
    "updateTime": 1621604685980,
    "isWorking": true,
    "origQuoteOrderQty": "6800.00000000"
  },
  {
    "symbol": "XRPDOWNUSDT",
    "orderId": 130557032,
    "orderListId": -1,
--
  },
  {
    "symbol": "XRPDOWNUSDT",
    "orderId": 133018781,
    "orderListId": -1,
    "clientOrderId": "and_bec5961147704b8cac4dd1e85179d8e8",
    "price": "0.00000000",
    "origQty": "340406.87000000",
    "executedQty": "340406.87000000",
    "cummulativeQuoteQty": "8799.99974535",
    "status": "FILLED",
    "timeInForce": "GTC",
    "type": "MARKET",
    "side": "BUY",
    "stopPrice": "0.00000000",
    "icebergQty": "0.00000000",
    "time": 1621673143063,
    "updateTime": 1621673143063,
    "isWorking": true,
    "origQuoteOrderQty": "8800.00000000"
  },
  {
    "symbol": "XRPDOWNUSDT",
    "orderId": 133019648,
    "orderListId": -1,
--
  },
  {
    "symbol": "XRPDOWNUSDT",
    "orderId": 133126983,
    "orderListId": -1,
    "clientOrderId": "and_6382cc7fc8f847f7b9481cc8b38eca4a",
    "price": "0.00000000",
    "origQty": "456512.40000000",
    "executedQty": "456512.40000000",
    "cummulativeQuoteQty": "11999.99983893",
    "status": "FILLED",
    "timeInForce": "GTC",
    "type": "MARKET",
    "side": "BUY",
    "stopPrice": "0.00000000",
    "icebergQty": "0.00000000",
    "time": 1621677749496,
    "updateTime": 1621677749496,
    "isWorking": true,
    "origQuoteOrderQty": "12000.00000000"
  },
  {
    "symbol": "XRPDOWNUSDT",
    "orderId": 133127954,
    "orderListId": -1,

where ./bi is a zsh script to do the signature etc:

#!/usr/bin/zsh
METH=$1
API=$2
STAMP=`curl -s 'https://api.binance.com/api/v3/time' | jq '.serverTime'`
QS="$3&timestamp=$STAMP"
PUB=`cat ../binance.ling.pub`
KEY=`cat ../binance.ling.key`
SIG=`echo -n $QS | openssl dgst -sha256 -hmac $KEY | cut -d ' ' -f 2`
URL="https://api.binance.com/api/v3/$API?$QS&signature=$SIG"
echo $URL
curl -X $METH -H "X-MBX-APIKEY: $PUB" $URL

That’s a bit late isn’t it. I’m not trying to receive orders posted to the rest api but to the UI

Not a bug, the price field is listed as 0 because for Market orders you don’t need to input price when creating the order.

So how do I know what price the order fulfilled at?

When posting new MARKET order, send “newOrderRespType=FULL” to receive “fills” in the response. Within “fills” you’ll find the executed price, if there’s more than 1 trade, you need to calculate the average price locally.

What if the order is not filled by the time the API response will have been generated? What if the status is PARTIAL?

MARKET orders complete immediately. They end up either FILLED if filled completely, or EXPIRED in the rare case when you consume all available liquidity.

1 Like

Will the trades api behave more sensibly?

This bit about setting newOrderRespType=FULL is worth discussing. Suppose you’d made FULL the default and invited people to set newOrderRespType=EMPTY to set the price field to zero if they want that. How many people would do so?

It seems to me that if you wanted to see zeros in that field, you wouldn’t need to read it at all, cos you can already calculate the value of zero, so it would do you no harm if it had something useful in there, like the price.

This would not confuse many people because after all the field is called “price”, which for most people would be a dead giveaway that any non-zero value that surprisingly popped up there would be a price.

So it turns out that you’ve gone to all the trouble of implementing a useless flag, setting the default wrong, documenting it and answering threads like this from people who have already lost a lot of time tracing their wrong calculations down to this bug, just because…

In fact you haven’t even solved the problem, because the allOrders API is about orders which have already been placed, mostly using the UI where this flag isn’t present, nor should be.

Because what? Wouldn’t it have been easier just to admit that it was a mistake, fix it, and move on? We all make mistakes, you know. Even me. It’s really not that shameful. But this contortion into increasingly ridiculous opinions to avoid losing face does you no favours.

This is by no means the only thread where you do so. There’s also constipation about making symbol optional in this endpoint and I didn’t even bother starting a discussion about limit=500/1000 cos I just can’t be bothered to lead a horse to water when it would rather die of thirst than admit that it didn’t know where the water was.

1 Like