Skip to content
This repository has been archived by the owner on Aug 12, 2024. It is now read-only.

KuCoin order data does NOT contain the correct price #475

Open
hodlerhacks opened this issue Sep 2, 2023 · 0 comments
Open

KuCoin order data does NOT contain the correct price #475

hodlerhacks opened this issue Sep 2, 2023 · 0 comments

Comments

@hodlerhacks
Copy link

hodlerhacks commented Sep 2, 2023

Using CCXT for KuCoin spot trading, I've noticed that the watchOrders() order event data that is received when an order is closed, does NOT contain the actual price at which the order was filled. Example:

I'm creating an order: XRP/USDT limit sell at a price of $0.495 (placing it below the current price on purpose to see what happens)

In the KuCoin order history, I see the order got filled with an average price of $0.49548

The data in the order event only has the price at which I placed the order ($0.495). There is no data, not even in the raw response (info object), that can be used to determine the actual/average price.

Now, since the relevant data is not in the raw response either, I first thought this was a problem on the KuCoin side. However, the API does return the relevant information at one point, see (using verbose logging):

2023-09-02T09:16:52.383Z onMessage {
  topic: '/spotMarket/tradeOrders',
  type: 'message',
  data: {
    clientOid: 'alt-8286ddf0-7513-4353-b9ea-d5ffd4dd59fa',
    filledSize: '12.0806',
    liquidity: 'taker',
    matchPrice: '0.49548',
    matchSize: '12.0806',
    orderId: '64f2fd845f06e40007a0999c',
    orderTime: 1693646212239,
    orderType: 'limit',
    price: '0.495',
    remainSize: '0',
    side: 'sell',
    size: '12.0806',
    status: 'match',
    symbol: 'XRP-USDT',
    tradeId: '4489065443772417',
    ts: '1693646212258000000',
    type: 'match'
  },
  subject: 'orderChange',
  userId: '64a81660d9c628000162442c',
  channelType: 'private'
}
2023-09-02T09:16:52.394Z onMessage {
  topic: '/spotMarket/tradeOrders',
  type: 'message',
  data: {
    clientOid: 'alt-8286ddf0-7513-4353-b9ea-d5ffd4dd59fa',
    filledSize: '12.0806',
    orderId: '64f2fd845f06e40007a0999c',
    orderTime: 1693646212239,
    orderType: 'limit',
    price: '0.495',
    remainFunds: '0',
    remainSize: '0',
    side: 'sell',
    size: '12.0806',
    status: 'done',
    symbol: 'XRP-USDT',
    ts: '1693646212258000000',
    type: 'filled'
  },
  subject: 'orderChange',
  userId: '64a81660d9c628000162442c',
  channelType: 'private'
}

In the first event, you can see the matchPrice, which is the correct price. Interestingly, the matchPrice is no longer visible in the second event. Perhaps that's why things fail?

Also, in the matchPrice is actual visible in the CCXT order data when the order is opened (and immediately filled):

{
  info: {
    clientOid: 'alt-8286ddf0-7513-4353-b9ea-d5ffd4dd59fa',
    filledSize: '12.0806',
    liquidity: 'taker',
    matchPrice: '0.49548',
    matchSize: '12.0806',
    orderId: '64f2fd845f06e40007a0999c',
    orderTime: 1693646212239,
    orderType: 'limit',
    price: '0.495',
    remainSize: '0',
    side: 'sell',
    size: '12.0806',
    status: 'match',
    symbol: 'XRP-USDT',
    tradeId: '4489065443772417',
    ts: '1693646212258000000',
    type: 'match'
  },
  symbol: 'XRP/USDT',
  id: '64f2fd845f06e40007a0999c',
  clientOrderId: 'alt-8286ddf0-7513-4353-b9ea-d5ffd4dd59fa',
  timestamp: 1693646212239,
  datetime: '2023-09-02T09:16:52.239Z',
  lastTradeTimestamp: undefined,
  type: 'limit',
  timeInForce: undefined,
  postOnly: undefined,
  side: 'sell',
  price: 0.495,
  stopPrice: undefined,
  triggerPrice: undefined,
  amount: 12.0806,
  cost: 5.979897,
  average: undefined,
  filled: 12.0806,
  remaining: 0,
  status: 'open',
  fee: undefined,
  trades: [],
  fees: [],
  lastUpdateTimestamp: undefined,
  reduceOnly: undefined,
  takeProfitPrice: undefined,
  stopLossPrice: undefined
}

For completeness, this is the 'closed' event returned by CCXT:

{
  info: {
    clientOid: 'alt-8286ddf0-7513-4353-b9ea-d5ffd4dd59fa',
    filledSize: '12.0806',
    orderId: '64f2fd845f06e40007a0999c',
    orderTime: 1693646212239,
    orderType: 'limit',
    price: '0.495',
    remainFunds: '0',
    remainSize: '0',
    side: 'sell',
    size: '12.0806',
    status: 'done',
    symbol: 'XRP-USDT',
    ts: '1693646212258000000',
    type: 'filled'
  },
  symbol: 'XRP/USDT',
  id: '64f2fd845f06e40007a0999c',
  clientOrderId: 'alt-8286ddf0-7513-4353-b9ea-d5ffd4dd59fa',
  timestamp: 1693646212239,
  datetime: '2023-09-02T09:16:52.239Z',
  lastTradeTimestamp: undefined,
  type: 'limit',
  timeInForce: undefined,
  postOnly: undefined,
  side: 'sell',
  price: 0.495,
  stopPrice: undefined,
  triggerPrice: undefined,
  amount: 12.0806,
  cost: 5.979897,
  average: undefined,
  filled: 12.0806,
  remaining: 0,
  status: 'closed',
  fee: undefined,
  trades: [],
  fees: [],
  lastUpdateTimestamp: undefined,
  reduceOnly: undefined,
  takeProfitPrice: undefined,
  stopLossPrice: undefined
}

Note: also the cost is incorrect, but it seems CCXT calculates that by just multiplying price and filled, so if the price is correct, I would assume cost will be correct as well (?).

Based on the above, it seems to me that the problem is probably (partially) on the KuCoin side, as the relevant data is missing from the 'closed' event.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant