When I place a buy order for 1 unit of cryptocurrency, when it fills I will actually receive 1 - fee
units of that currency (say 0.9985 assuming the base maker fee). However, when listening to the trade_updates
stream, I’ll get a response like
{
"stream": "trade_updates",
"data": {
"event": "fill",
"order": {
...,
"filled_qty": "1",
"qty": "1",
},
...,
"position_qty": "0.9985",
"qty": "1",
}
}
The position_qty
field tells me how much total of the cryptocurrency I have at the end of the trade, but not how much I received as a result of the trade. If I had 10 of the currency before the trade filled, the position_qty
would instead be 10.9985
.
I’m building an application that will in some circumstances place an immediate limit sell after a buy fills. For that, I need to know exactly how much of the currency I actually received. Placing a sell for the quantity listed in either of the qty
fields or the filled_qty
field will (of course) get the order rejected because I’m trying to sell more than I have. Using position_qty
works if I didn’t have any to begin with, but results in an invalid value if I started with a nonzero position (e.g. I bought the same cryptocurrency using both USD and USDC at around the same time).
Is there a way that I’m missing to see the exact quantity of cryptocurrency that I actually received from a given trade? (Of course I could try to calculate it myself either by manually calculating the fee I expect or keeping track of my existing positions before and after each fill, but those are prone to rounding errors and race conditions.)