Binance API- Passing Security (Header or body)

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
scriptomundo
Posts: 44
Joined: 08 Nov 2021, 23:40

Re: Binance API- Passing Security (Header or body)

Post by scriptomundo » 19 Jan 2022, 08:21

Thanks bigtime @gregster

Class act. Will be donating to the AHK Foundation.

Taras
Posts: 4
Joined: 08 Jul 2022, 03:04

Re: Binance API- Passing Security (Header or body)

Post by Taras » 08 Jul 2022, 03:12

Hello everyone!
Unfortunately, I don't know English well enough to understand the messages in this thread.

I already have working Autohotkey code for "WinHttp.WinHttpRequest.5.1" request on one crypto exchange and now I need to create the same one for Binance.

I would be grateful if someone would post a working code on Autohotkey with a request for Binance, for example, to create an order or another.

Taras
Posts: 4
Joined: 08 Jul 2022, 03:04

Re: Binance API- Passing Security (Header or body)

Post by Taras » 08 Jul 2022, 07:04

I try this code but the answer is:
"{"code":-1104,"msg":"Not all sent parameters were read; read '2' parameter(s) but was sent '3'."}"

if you do it like this:
url := "https://api.binance.com/api/v3/account?" postdata "&signature=" sign

then the answer comes:
{"code":-1104,"msg":"Not all sent parameters were read; read '1' parameter(s) but was sent '2'."}

Why can't binance read the parameter?

Code: Select all

oHTTP:=ComObjCreate("WinHttp.WinHttpRequest.5.1")	
apikey := 
secret := 

timestamp := A_NowUTC
timestamp -= 19700101000000, s
timestamp := timestamp * 1000 + A_MSec

postdata := "TimeStamp=" timestamp
sign := LC_HMAC(secret, postdata, "sha256")

url := "https://api.binance.com/api/v3/account?" postdata "&recvWindow=60000&signature=" sign

oHTTP.Open("GET", URL , False)	//Post request
oHTTP.SetRequestHeader("X-MBX-APIKEY", apikey)
oHTTP.SetRequestHeader("Sign", sign)
oHTTP.Send()	//Send POST request

msgbox, %response%
Last edited by gregster on 08 Jul 2022, 08:09, edited 1 time in total.

Taras
Posts: 4
Joined: 08 Jul 2022, 03:04

Re: Binance API- Passing Security (Header or body)

Post by Taras » 10 Jul 2022, 11:11

I managed to solve the problem, the script worked when I replaced

Code: Select all

postdata := "TimeStamp=" timestamp
to

Code: Select all

postdata := "timestamp=" timestamp
Here is the working code for the GET request:

Code: Select all

apikey := 
secret := 

oHTTP:=ComObjCreate("WinHttp.WinHttpRequest.5.1")	

timestamp := A_NowUTC
timestamp -= 19700101000000, s
timestamp := timestamp * 1000 + A_MSec
postdata := "timestamp=" timestamp
sign := LC_HMAC(secret, timestamp, "sha256")

url := "https://api.binance.com/api/v3/account?" timestamp "&signature=" sign

oHTTP.Open("GET", URL , 0)	//Post request
oHTTP.SetRequestHeader("X-MBX-APIKEY", apikey)
oHTTP.SetRequestHeader("Sign", sign)
oHTTP.Send()	//Send POST request
response := oHTTP.ResponseText
msgbox, %response%
But the POST request does not work yet, I will be grateful for a working example.

Post Reply

Return to “Ask for Help (v1)”