ccxt: UPBIT: Cannot cancel open order using ccxt API

  • OS: Windows 10 Enterprise LTSC v. 1809
  • Programming Language version: Javascript
  • CCXT version: 1.19.94
  • Exchange: UPBIT
  • Method: exchange.fetchOpenOrders(<market>)

Good afternoon, I’m trying to cancel an order on Upbit exchange using ccxt, but I’m getting the following error:

Request: DELETE "https://sg-api.upbit.com/v1/order" {'Authorization': 'Bearer <authorization token>'} body: "{"uuid":"3efae1ab-583a-4b2a-aea9-9783ada85aad"}"

Response: "{"error":{"name":"V1::Exceptions::InvalidQueryPayload","message":"Failed to verify the query of Jwt.","dialog":"client"}}"

My guess is that the API endpoint is incorrect, but so far I haven’t found a solution.

Thanks for helping me out.

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Comments: 20 (11 by maintainers)

Commits related to this issue

Most upvoted comments

@coinaisseur thx for your help debugging it, appreciate your involvement!

Hi @kroitor

Thanks for the latest update. Now the fetchOpenOrders and cancelOrder functions work as expected.

Thanks again for all your help and time spent fixing this issue.

Hi @kroitor

I managed to solve my problem by changin a little bit the sign function in the upbit library. Instead of sending query in plain text, I changed the code to send its hashed form instead:

if (Object.keys(query).length) {
  const hash = crypto.createHash('sha512')
  const queryHash = hash.update(this.urlencode(query), 'utf-8').digest('hex')
  request['query_hash'] = queryHash
}

This is not the most elegant solution, but it works for me for the time being.

Thanks for your help.

Hi @kroitor

I’ve tried again to cancel order after updating ccxt, still to no avail. Here’s the verbose:

fetch:
 upbit DELETE https://sg-api.upbit.com/v1/order?uuid=333b5521-dbc6-4e99-a2c7-ced299fdc763
Request:
 {
  Authorization: 'Bearer <authorization_token>',
  'Content-Type': 'application/json'
}
 {"uuid":"333b5521-dbc6-4e99-a2c7-ced299fdc763"}

handleRestResponse:
 upbit DELETE https://sg-api.upbit.com/v1/order?uuid=333b5521-dbc6-4e99-a2c7-ced299fdc763 401 Unauthorized
Response:
 {
  'Access-Control-Allow-Headers': 'Authorization, Content-Type, Accept, *',
  'Access-Control-Allow-Origin': '*',
  'Cache-Control': 'no-cache',
  Connection: 'close',
  'Content-Encoding': 'gzip',
  'Content-Language': 'en',
  'Content-Type': 'application/json; charset=utf-8',
  Date: 'Wed, 27 Nov 2019 22:26:15 GMT',
  'Remaining-Req': 'group=default; min=899; sec=29',
  Server: 'Finatra',
  'Transfer-Encoding': 'chunked',
  Vary: 'Origin',
  Via: 'kong/1.3.0',
  'X-Kong-Proxy-Latency': '4',
  'X-Kong-Upstream-Latency': '23',
  'X-Request-Id': 'd073886c-7b51-4c8a-88d7-fd3c446aabf7',
  'X-Runtime': '0.010736'
}
 {"error":{"name":"V1::Exceptions::InvalidQueryPayload","message":"Failed to verify the query of Jwt.","dialog":"client"}}

ExchangeError: upbit {"error":{"name":"V1::Exceptions::InvalidQueryPayload","message":"Failed to verify the query of Jwt.","dialog":"client"}}
    at upbit.handleErrors (C:\Users\Administrator\Documents\Node.js\TEST\node_modules\ccxt\js\upbit.js:1522:19)
    at C:\Users\Administrator\Documents\Node.js\TEST\node_modules\ccxt\js\base\Exchange.js:635:18
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
    at async timeout (C:\Users\Administrator\Documents\Node.js\TEST\node_modules\ccxt\js\base\functions\time.js:176:24)
    at async upbit.cancelOrder (C:\Users\Administrator\Documents\Node.js\TEST\node_modules\ccxt\js\upbit.js:902:26)
    at async C:\Users\Administrator\Documents\Node.js\TEST\test.js.js:15:28
    at async main (C:\Users\Administrator\Documents\Node.js\TEST\test.js.js:13:5) {
  constructor: [Function: ExchangeError],
  name: 'ExchangeError'
}

For some reason, there’s a problem with the JSON construct ccxt is sending to the exchange. In the case of fetchOpenOrders, I managed to make it work by changing hostname to ccxsg.upbit.com/api. This didn’t work with cancelOrder though.

I also tested this script on a fresh new Windows server install with latest node.js version (12.13.1) and with latest libraries installed, but it didn’t work.

Thanks for your help.