Devo utilizzare delle API ma qualcosa non funziona. Come tradurreste questo esempio PHP in B4J:
<?
$apiKey="a869b1547c56c5ce37ee9acfd92de8b8c8ca7df6";
$apiSecret="732a65b7abed7991d7229188d7b97a8c54d3149f";
$url="https://api.therocktrading.com/v1/balances";
$nonce=microtime(true)*10000;
$signature=hash_hmac("sha512",$nonce.$url,$apiSecret);
$headers=array(
"Content-Type: application/json",
"X-TRT-KEY: ".$apiKey,
"X-TRT-SIGN: ".$signature,
"X-TRT-NONCE: ".$nonce
);
$ch=curl_init();
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_HTTPHEADER,$headers);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
$callResult=curl_exec($ch);
curl_close($ch);
$result=json_decode($callResult,true);
print_r($result);
?>
La mia versione:
Dim job_GetInfo As HttpJob
Dim API_Key, API_Secret, API_Signed As String
Dim Post_URL, Post_Data As String
Dim Byte_Conv As ByteConverter
Dim Nonce As String
Post_URL = "https://api.therocktrading.com/v1/balances"
API_Key = "a869b1547c56c5ce37ee9acfd92de8b8c8ca7df6"
API_Secret = "732a65b7abed7991d7229188d7b97a8c54d3149f"
Nonce=DateTime.Now/1000
Post_Data = "apikey=" & API_Key & "&nonce=" & Nonce
Dim Sign() As Byte = HashHmac(Nonce & Post_URL , API_Secret)
API_Signed = Byte_Conv.HexFromBytes(Sign) 'convert to HEX
API_Signed = API_Signed.ToLowerCase
job_GetInfo.Initialize("job_GetInfo", Me)
job_GetInfo.Download(Post_URL)
job_GetInfo.GetRequest().SetHeader("Content-Type","application/json")
job_GetInfo.GetRequest().SetHeader("X-TRT-KEY",API_Key)
job_GetInfo.GetRequest().SetHeader("X-TRT-SIGN",API_Signed)
job_GetInfo.GetRequest().SetHeader("X-TRT-NONCE",Nonce)
Response:
ResponseError. Reason: Unauthorized, Response: {"errors":[{"message":"Not Authorized","code":"01"}]}
Grazie
<?
$apiKey="a869b1547c56c5ce37ee9acfd92de8b8c8ca7df6";
$apiSecret="732a65b7abed7991d7229188d7b97a8c54d3149f";
$url="https://api.therocktrading.com/v1/balances";
$nonce=microtime(true)*10000;
$signature=hash_hmac("sha512",$nonce.$url,$apiSecret);
$headers=array(
"Content-Type: application/json",
"X-TRT-KEY: ".$apiKey,
"X-TRT-SIGN: ".$signature,
"X-TRT-NONCE: ".$nonce
);
$ch=curl_init();
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_HTTPHEADER,$headers);
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
$callResult=curl_exec($ch);
curl_close($ch);
$result=json_decode($callResult,true);
print_r($result);
?>
La mia versione:
Dim job_GetInfo As HttpJob
Dim API_Key, API_Secret, API_Signed As String
Dim Post_URL, Post_Data As String
Dim Byte_Conv As ByteConverter
Dim Nonce As String
Post_URL = "https://api.therocktrading.com/v1/balances"
API_Key = "a869b1547c56c5ce37ee9acfd92de8b8c8ca7df6"
API_Secret = "732a65b7abed7991d7229188d7b97a8c54d3149f"
Nonce=DateTime.Now/1000
Post_Data = "apikey=" & API_Key & "&nonce=" & Nonce
Dim Sign() As Byte = HashHmac(Nonce & Post_URL , API_Secret)
API_Signed = Byte_Conv.HexFromBytes(Sign) 'convert to HEX
API_Signed = API_Signed.ToLowerCase
job_GetInfo.Initialize("job_GetInfo", Me)
job_GetInfo.Download(Post_URL)
job_GetInfo.GetRequest().SetHeader("Content-Type","application/json")
job_GetInfo.GetRequest().SetHeader("X-TRT-KEY",API_Key)
job_GetInfo.GetRequest().SetHeader("X-TRT-SIGN",API_Signed)
job_GetInfo.GetRequest().SetHeader("X-TRT-NONCE",Nonce)
Response:
ResponseError. Reason: Unauthorized, Response: {"errors":[{"message":"Not Authorized","code":"01"}]}
Grazie
Last edited: