problem with sockets and $hmac - 21/12/17 12:25 AM
hello, I'm trying to connect to an api, from a house of virtual currencies, I have collected information from other old posts, but even so, I have an error and I can not read anything from the server, if someone could what could be the failure ... I do not know what else to try .. I put the code.
the error that comes out is :
* Invalid parameters: $hmac
it also does not show any information from the server
here https://poloniex.com/support/api/ the web comes information of the api, and some examples in other languages, but I can not adapt it.
Code:
alias btc { var %sockname = btc. $+ $nonce echo -s %sockname sockopen -e %sockname poloniex.com 443 } on *:sockopen:btc.*:{ var %api_key = apikey var %secret = secret var %nonce = $nonce var %data = method=getInfo&nonce= $+ %nonce var %sign = $hmac(sha512,%secret,%data,512) var %a = sockwrite -n $sockname %a POST /tradingApi HTTP/1.0 %a Key: %api_key %a Sign: %sign %a Content-Type: application/x-www-form-urlencoded %a Host: poloniex.com %a Content-Length: $len(%data) %a Connection: keep-alive %a $+($crlf,%data) } alias sha512 return $dll(sha2.dll,sha512,$calc($2) $1) alias hmac { if (!$1) || ($2 == $null) || ($3 == $null) { return } var %size = $iif($4,$calc($4 / 4),64) bunset &key &h1 &h1_hash &h2 if ($len($2) > %size) { bset &key 1 $regsubex($($+($,$1,$chr(40),$2,$chr(41)),2),/(..)/g,$base(\1,16,10) $+ $chr(32)) } else { bset -t &key 1 $2 } var %x = 1 while (%x <= %size) { var %c = $iif($bvar(&key,%x),$v1,0) bset &h1 %x $xor(54,%c) bset &h2 %x $xor(92,%c) inc %x } bset -t &h1 $calc($bvar(&h1,0)+1) $3 bset &h1_hash 1 $regsubex($($+($,$1,$chr(40),&h1,$chr(44),1,$chr(41)),2),/(..)/g,$base(\1,16,10) $+ $chr(32)) bset &h2 $calc($bvar(&h2,0)+1) $bvar(&h1_hash,1-) return $($+($,$1,$chr(40),&h2,$chr(44),1,$chr(41)),2) echo $($+($,$1,$chr(40),&h2,$chr(44),1,$chr(41)),2) } on *:sockread:btc.*:{ var %header, %read if ($sock($sockname).mark != header.finished) { sockread %header while (%header != $null) { echo -ag %header sockread %header } if ($sockbr) sockmark $sockname header.finished } if ($sock($sockname).mark == header.finished) { sockread -f %read while ($sockbr) { if (%read != $null) echo -ag %read sockread -f %read } } } alias nonce { if (!%nonce) set -u1 %nonce $ctime $+ $calc($ticks % 10000) else inc %nonce return %nonce }
the error that comes out is :
* Invalid parameters: $hmac
it also does not show any information from the server
here https://poloniex.com/support/api/ the web comes information of the api, and some examples in other languages, but I can not adapt it.