Hello guys, i’ve been using the binance api for simple public endpoints and even some signed ones like getting balance or positions from the user. And it worked well until i’ve tried to make a newOrder where it started giving me the same non-sense error.
My code is the following, im using NestJs (NodeJs framework):
At the begining I decrypt the keys which are stored in my database , I double checked the result of the decryption maches with my keys actually and they do , also my api has the futures trading activated and is nothing wrong with it.
Then I make the post request and give some url params, just the needed ones and the signature which is the same method as the other requests I do (the balance signed requests i mentioned before), everything looks fine but when i execute it gives me :
{ code: -2014, msg: ‘API-key format invalid.’ }
My generateBinanceSignature method is the following :
This error message is trying to say the API key in the header is not correct, failed to pass simple format validation. Please double check if it’s the one provided from the account.
This nodejs file has some code that working fine for signature, hope it will be helpful.
You say that the header apiKey es wrong, i’ve just copy-pasted it from my binance account and same error code { code: -2014, msg: ‘API-key format invalid.’ }.
Could it be that for post requests I must send the params on the body? You sended me a GET
Sir we got it.
The “problem” was with my framework and my ignorance to its API, it looks like when I send a post request, the post method accepts different variables and options than de DELETE/GET methods, so instead of sending my public key to the headers I was sending it to the body! WTF. I didn’t know it changes it options order. Look at its interface: https://gyazo.com/39a280b91a596fdac272cc7b7d46308f
Do you see the params of GET and DELETE? thats why they were working to me and not the POST calls not, becasue the second param for a post is the data, the body, and the third one is the config where I place the headers and all the request config if needed.
This just made me lost like 5 hours of my life holy sh**t
Thank you friend, for your time and have a wonderful day.