-1

i try to translate in Ring language this string of curl (it work, i tested) curl -H "X-MBX-APIKEY: ----MY API KEY HERE----" -X POST 'https://api.binance.com/api/v3/order' -d 'symbol=LTCBTC&side=BUY&type=LIMIT&timeInForce=GTC&quantity=1&price=0.1&recvWindow=5000&timestamp=1499827319559&signature=c8db56825ae71d6d79447849e617115f4a920fa2acdcab2b053c4b2838bd6b71'

but the script return me always {"code":-2014,"msg":"API-key format invalid."}

Load "libcurl.ring"
Load "guilib.ring"
load "stdlib.ring"


my_api_key = "---API KEY HERE ---"
my_part = "symbol=LTCBTC&side=BUY&type=LIMIT&timeInForce=GTC&quantity=1&price=0.1&recvWindow=5000&timestamp=1499827319559&signature=c8db56825ae71d6d79447849e617115f4a920fa2acdcab2b053c4b2838bd6b71"
my_URL= "https://api.binance.com/api/v3/order"
userAgent = "Mozilla/5.0 (Windows NT 5.1; rv:31.0) Gecko/20100101 Firefox/31.0"
        curl = curl_easy_init()
        curl_easy_setopt(curl, CURLOPT_POST, 1)
        curl_easy_setopt(curl, CURLOPT_USERAGENT, userAgent)
        curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, FALSE)
        curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 2)
        # Header
        mylist = curl_slist_append(null,'accept-encoding: *')
        mylist = curl_slist_append(mylist,'authorization: X-MBX-APIKEY: ' + my_api_key )
        mylist = curl_slist_append(mylist,'connection: close')
        mylist = curl_slist_append(mylist,'content-length: ' + len(my_part) )
        mylist = curl_slist_append(mylist,'content-type: application/json')
        curl_easy_setopt(curl, CURLOPT_HTTPHEADER, mylist)
        # Website
        curl_easy_setopt(curl, CURLOPT_URL, my_URL)
        # Body
        curl_easy_setopt(curl, CURLOPT_POSTFIELDS,my_part )
        cOutput = curl_easy_perform(curl)   ```

thanks at  all 

1 Answers1

0
  1. symbol=LTCBTC&side=BUY&... is not JSON, this is x-www-form-urlencoded data.
  2. You do not set Content-Type in the curl invocation, but set it in the code. Try to omit this (default content type is application/x-www-form-urlencoded).
  3. Try to call curl with the command option --libcurl, you will get the code corresponding to the command invocation.
273K
  • 29,503
  • 10
  • 41
  • 64