How to get the total cost of a FILLED order

Hi

How can I get the totals cost including commission of a filled order ?

I assume that the amount that is deducted from my wallet can be linked to a order :slight_smile:

I did read: How to get MARKET order's executed price in SPOT? - #2 by aisling but it’s not 100% clear.

Kind regards
Steen

Use GET /api/v3/myTrades to list trades you’ve done to fill the order, then sum them.

This endpoint returns the details of your trades with counterparties as well as the commissions that you pay the exchange.

For example, here’s an order to MARKET BUY some BTC for USDT with quoteOrderQty=5000.00.

GET /api/v3/order?symbol=BTCUSDT&orderId=6505618 returns a summary of the order, confirming that it’s fully FILLED:

Response
{
  "symbol": "BTCUSDT",
  "orderId": 6505618,
  "orderListId": -1,
  "clientOrderId": "DbEbedtckod2SvnEDSupeG",
  "price": "0.00000000",
  "origQty": "0.08403000",
  "executedQty": "0.08403000",
  "cummulativeQuoteQty": "4999.91598920",
  "status": "FILLED",
  "timeInForce": "GTC",
  "type": "MARKET",
  "side": "BUY",
  "stopPrice": "0.00000000",
  "icebergQty": "0.00000000",
  "time": 1726438360369,
  "updateTime": 1726438360369,
  "isWorking": true,
  "workingTime": 1726438360369,
  "origQuoteOrderQty": "5000.00000000",
  "selfTradePreventionMode": "EXPIRE_MAKER"
}

from which you can see that I’ve paid 4999.91598920 USDT in total (cummulativeQuoteQty) and received 0.08403000 BTC in total (executedQty). However, this doesn’t include the information on commissions, so the actual quantity that I’ve received might be different.

GET /api/v3/myTrades?symbol=BTCUSDT&orderId=6505618 returns more detailed information about the individual trades:

Response
[
  {
    "symbol": "BTCUSDT",
    "id": 1594825,
    "orderId": 6505618,
    "orderListId": -1,
    "price": "59500.01000000",
    "qty": "0.00340000",
    "quoteQty": "202.30003400",
    "commission": "0.00000000",
    "commissionAsset": "BTC",
    "time": 1726438360369,
    "isBuyer": true,
    "isMaker": false,
    "isBestMatch": true
  },
  {
    "symbol": "BTCUSDT",
    "id": 1594826,
    "orderId": 6505618,
    "orderListId": -1,
    "price": "59500.12000000",
    "qty": "0.00757000",
    "quoteQty": "450.41590840",
    "commission": "0.00000000",
    "commissionAsset": "BTC",
    "time": 1726438360369,
    "isBuyer": true,
    "isMaker": false,
    "isBestMatch": true
  },
  {
    "symbol": "BTCUSDT",
    "id": 1594827,
    "orderId": 6505618,
    "orderListId": -1,
    "price": "59501.78000000",
    "qty": "0.07306000",
    "quoteQty": "4347.20004680",
    "commission": "0.00000000",
    "commissionAsset": "BTC",
    "time": 1726438360369,
    "isBuyer": true,
    "isMaker": false,
    "isBestMatch": true
  }
]

Here you can see that I’ve made three trades:

Trade "id" "price" "qty" "quoteQty" "commission"
1594825 59500.01000000 USDT 0.00340000 BTC 202.30003400 USDT 0.00000000 BTC
1594826 59500.12000000 USDT 0.00757000 BTC 450.41590840 USDT 0.00000000 BTC
1594827 59501.78000000 USDT 0.07306000 BTC 4347.20004680 USDT 0.00000000 BTC

Tallying up qty, we get 0.08403000 BTC (same as executedQty). Similarly for quoteQty (which is price × qty), ending up with cummulativeQuoteQty.

If testnet had any commissions (lol) then the commission value would be non-zero :smiley: You sum them up like other quantities and get a total that you’ve paid for the order.

  • Commissions are not included in qty and are deducted separately.
  • Commissions can be paid in BNB if you choose to use the discount. In this case they are deducated from your free BNB balance, if it is sufficient.
  • Otherwise, commissions are deducted from the asset you receive:
    • e.g., if you buy BTC for USDT then commissions are deducted from the BTC you receive from the trade (you actually get less than executedQty)
    • similarly, if you sell BTC for USDT and don’t pay in BNB, then commissions are deducted from USDT that you get (which you get less than cummulativeQuoteQty)
  • Commissions are computed and deducted for each trade individually.