I can not understand how to make requests where there is a signature. Here is the main function that sends requests:

protected function query($method, $v, $m, $params = []){ $url = "https://api.binance.com/api/v".$v; $url .= '/' . $method; if (!empty($params)) { $url .= "?" . http_build_query($params); } $client = new Client([ 'base_uri' => $url ]); $result = $client ->request($m); return json_decode($result->getBody()); } 

Here is a link to their documentation https://github.com/binance-exchange/binance-official-api-docs/blob/master/rest-api.md

and there is an example:

First action

 [linux]$ echo -n "symbol=LTCBTC&side=BUY&type=LIMIT&timeInForce=GTC&quantity=1&price=0.1&recvWindow=5000&timestamp=1499827319559" | openssl dgst -sha256 -hmac "NhqPtmdSJYdKjVHjA7PZj4Mge3R5YNiP1e3UZjInClVN65XAbvqqM6A7H5fATj0j" (stdin)= c8db56825ae71d6d79447849e617115f4a920fa2acdcab2b053c4b2838bd6b71 

The second

 (HMAC SHA256) [linux]$ curl -H "X-MBX-APIKEY: vmPUZE6mv9SD5VNHk4HlWFsOr6aKE2zvsw0MuIgwCIPy6utIco14y7Ju91duEh8A" -X POST 'https://api.binance.com/api/v3/order?symbol=LTCBTC&side=BUY&type=LIMIT&timeInForce=GTC&quantity=1&price=0.1&recvWindow=5000&timestamp=1499827319559&signature=c8db56825ae71d6d79447849e617115f4a920fa2acdcab2b053c4b2838bd6b71' 

I do not understand how it turns out stdin and where to pass on the example of my function

1 answer 1

It's simple:

 echo hash_hmac( 'sha256', 'symbol=LTCBTC&side=BUY&type=LIMIT&timeInForce=GTC&quantity=1&price=0.1&recvWindow=5000&timestamp=1499827319559', 'NhqPtmdSJYdKjVHjA7PZj4Mge3R5YNiP1e3UZjInClVN65XAbvqqM6A7H5fATj0j'); 

Result:

 c8db56825ae71d6d79447849e617115f4a920fa2acdcab2b053c4b2838bd6b71 

I do not know what Client with you, but X-MBX-APIKEY is sent in the http header, signature=c8d... in the GET parameter.

  • I copied, pasted and I got a different result: from prntscr.com/kjw3p7 - pandal
  • @pandal there for some reason the ampersand turned into another character, I fixed it, now it should be ok - Zergatul
  • Could you help me deal with queries using the example of a query to the account data, I get this link: api.binance.com/api/v3/… 401 error. For http requests I use GuzzleHttp, $ Client - its class. I form a request like this prntscr.com/kk7mv7 (for screenshots, characters are limited). Or is everything right with me, and the error just because I use not my api, but the one that they showed in the documentation? - pandal
  • @pandal I think it should not work with the keys that are shown in the examples. You must try with the correct keys. - Zergatul
  • And the truth is, there are no errors with my keys, thank you - pandal