jaggedsoft / node-binance-api

Node Binance API is an asynchronous node.js library for the Binance API designed to be easy to use.
MIT License
1.58k stars 768 forks source link

Randomly "Signature for this request is not valid." #783

Open VenkatTeja opened 2 years ago

VenkatTeja commented 2 years ago

Hi Team, My client is getting this error sometimes randomly when the bot tries to cancel an order. Seems to be running fine on my local machine. My and my client API keys are all right. I checked this FAQ, I think am doing everything right: link

2021-12-25T22:25:12.208Z info: cancel order - {"orderId":"8389765512835593780","symbol":"ETHUSDT","direction":"buy"}
2021-12-25T22:25:12.443Z info: cancel order - {"code":-1022,"msg":"Signature for this request is not valid."}

The client is running on a Microsoft configured VM machine. Is there something I can check on their end to figure out what exactly is going wrong? It's not failing always. just sometimes.

My code:


const binance = new Binance().options({
    APIKEY: env.BINANCE_API_KEY,
    APISECRET: env.BINANCE_API_SECRET,
    useServerTime: true,
    recvWindow: 60000,
    verbose: true,
    test: utils.isTest()
});

async cancelOrder(orderId, retry = 0) {
        utils.logger.info(`cancel order - ${JSON.stringify({orderId, ...this.logInfo()})}`)
        if(!orderId)
            return;
        let order;
        try {
            order = await binance.futuresCancel(this.symbol, {orderId})
        } catch(err) {
            utils.logger.warn(`Error cancelling order - retry #${retry} - ${JSON.stringify(this.logInfo())}`)
            utils.logger.error(err)
            if(retry < 3) {
                utils.logger.info('Trying again...')
                return this.cancelOrder(orderId, retry + 1)
            } else {
                throw err;
            }
        }
        utils.logger.info(`cancel order - ${JSON.stringify(order)}`)
        iif(order.status) {
            if(order.status!='CANCELED') {
                throw new Error("order couldn't be canceled")
            }
        } else {
            if(order.msg=='Unknown order sent.') {
                utils.logger.info('order may be already canceled')
                return;
            }
            throw new Error("order cancel issue") // <-- reaching till here due to response as {"code":-1022,"msg":"Signature for this request is not valid."}
        }
}