BTCMarkets / API

API
119 stars 30 forks source link

Market order price incorrect #199

Closed micant closed 3 years ago

micant commented 3 years ago

env: node api: v3

When placing a market buy or sell order via api the price property returned is, often but not always, incorrect. The trades associated with the order either don't match the order price, or don't average to equal the order price. When calculating the cost (price * volume) of a trade, this has caused some incorrect calculations at my end.

Should the order price be disregarded and underlying trade prices be used instead? Is this by design or an issue with the API - or am I getting something wrong?

Appreciate your help, thanks.

Example order price - $45796.45 trade price - $45634.03

fetch order:

{
    orderId: '7046562735',
    marketId: 'BTC-AUD',
    side: 'Ask',
    type: 'Market',
    creationTime: '2021-06-12T09:45:55.607000Z',
    price: '45796.45',
    amount: '0.03510048',
    openAmount: '0',
    status: 'Fully Matched'
  }

fetch trade:

{
    id: '6568239521',
    marketId: 'BTC-AUD',
    timestamp: '2021-06-12T09:45:55.613000Z',
    price: '45634.03',
    amount: '0.03510048',
    side: 'Ask',
    orderId: '7046562735',
    liquidityType: 'Taker'
  }
micant commented 3 years ago

Bump. Any help with this issue?

I've worked around this by requesting trades associated with the order and running calculations from there.

martin-nginio commented 3 years ago

Hi @micant

Thanks for your message and sorry for the delay in response.

The price in an order record is an instruction to execute an order if that price is available. For market orders this may be different at the time of execution (e.g. compared to time that a client initiates the request).

Even for limit orders the execution price might be different due to multiple executions and in some cases the market has better price (in the case of a buy, the order may execute lower if there are available orders) compared to price in the order.

So in all cases, the price in order is an instruction to execute whereas the actual order execution is in trade record and an order may have multiple trade records with different prices.

So depending on your use case trade records can be used to determine actual order executions if actual prices are needed.

I hope this helps.

Regards, Martin