Search code examples
apicryptocurrencybinance

How to get account information using binance api?


I'm trying to get my account information using Binance api.

curl request :

curl -H "X-MBX-APIKEY: " -X POST 'https://api.binance.com/api/v3/account' -d 'recvWindow=5000&timestamp=12345643&signature=8KhePoYVPdnw2T4Y38Yvurvr3U5Q59MYqvtg6kepFoMn9m3PvEnGeVjpV0Lmc5ab'

I get this

Not Found

Probably I am not creating HMAC signature properly.


Solution

  • Tested example in bash:

    #!/bin/bash
    
    ####API
    APIKEY="XXXXXXXXXXXXXXXXyour api key here""
    APISECRET="XXXXXXXXXXXXyour api secret here"
    
    RECVWINDOW=5000 # 5 seconds
    
    ####GET ACCOUNT BALACE
    
    TM=$(( $(date -u +%s) *1000))
    
    GET_BALANCE_QUERY="recvWindow=$RECVWINDOW&timestamp=$TM"
    
    GET_BALANCE_SIG=$(echo -n "$GET_BALANCE_QUERY" | openssl dgst -sha256 -hmac $APISECRET)
    
    echo $GET_BALANCE_SIG
    GET_BALANCE_SIG="$(echo $GET_BALANCE_SIG | cut -f2 -d" ")"
    echo $GET_BALANCE_SIG
    
    curl -H "X-MBX-APIKEY: $APIKEY" -X GET "https://api.binance.com/api/v3/account?recvWindow=$RECVWINDOW&timestamp=$TM&signature=$GET_BALANCE_SIG" | jq
    

    =