tiagosiebler / binance

Node.js & JavaScript SDK for Binance REST APIs & WebSockets, with TypeScript & browser support, integration tests, beautification & more.
MIT License
728 stars 264 forks source link

getting "Unknown order sent" error every time I call cancelOrder #396

Closed capaj closed 5 months ago

capaj commented 5 months ago

I am getting:

{
  code: -2011,
  message: "Unknown order sent.",
  body: {
    code: -2011,
    msg: "Unknown order sent.",
  },
  requestUrl: "https://api.binance.com/api/v3/order?symbol=LTCBTC&orderId=1159416338&timestamp=1707324814066&recvWindow=5000&signature=XXXXXXXXXXXX",
  requestBody: undefined,
  requestOptions: {
    recvWindow: 5000,
    syncIntervalMs: 3600000,
    strictParamValidation: false,
    disableTimeSync: true,
    api_key: undefined,
    api_secret: undefined,
    baseUrl: "https://api.binance.com",
  },

every time I try to cancel a valid order. Order is open in the official binance web client and after I call this it is actually cancelled. So why is that error thrown? For now I just ignore it with a try catch, but why is it even getting thrown?

tiagosiebler commented 5 months ago

It's not the SDK that decides this should be an error. That code and message style response means that the exchange responded with that error in response to your request. Definitely seems weird, if the cancel order request actually worked based on what you see on the website. I would definitely report this to binance.

And just to check a really silly question, are you absolutely certain you're not accidentally calling cancel order twice, so only the second request fails?

If you can easily reproduce this, you could try reaching out to binance in their API community on telegram - it's typically where I ask/report things that seem unclear: https://t.me/binance_api_english

As with any telegram community, don't trust anyone that messages you directly of course (since that happens a lot in these groups sadly).

capaj commented 5 months ago

And just to check a really silly question, are you absolutely certain you're not accidentally calling cancel order twice, so only the second request fails?

That was my first thought as well, sadly no😅

Will put together a tiny reproduction.

capaj commented 5 months ago

Forgot to mention I am using bun as runtime. Will try with nodejs tomorrow

capaj commented 5 months ago

actually I just tried with this code in bun

import { botSettings } from '../botSettings'
import { binanceClient } from './binanceClient'

const res = await binanceClient.cancelOrder({
  symbol: botSettings.symbol,
  orderId: XXXXXXX
})

console.log(res)

and it went through nicely so I suspect it was actually the duplicate call most likely or I called it after the order was filled. Sorry for spamming