Bitcoin Forum

Economy => Exchanges => Topic started by: DogWelder on August 23, 2017, 04:46:09 PM



Title: BITTREX API + WAMP Server
Post by: DogWelder on August 23, 2017, 04:46:09 PM
Hi all,

I've been trying to use the Bittrex API on WampServer 3.0.6 x64 (default setting).
I'm using the default example from the Bittrex API page (https://bittrex.com/Home/Api (https://bittrex.com/Home/Api)) but I'm not getting any results (simple php commands work however).

$apikey='blahblahmykey';
$apisecret='blahblahmysecret';
$nonce=time();
$uri='https://bittrex.com/api/v1.1/market/getopenorders?apikey='.$apikey.'&nonce='.$nonce;
$sign=hash_hmac('sha512',$uri,$apisecret);
$ch = curl_init($uri);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('apisign:'.$sign));
$execResult = curl_exec($ch);
$obj = json_decode($execResult);


Can anyone suggest a possible solution or an alternative webserver with which they've had success? Thanks in advance.


Title: Re: BITTREX API + WAMP Server
Post by: poordeveloper on August 23, 2017, 05:16:41 PM
Do you have the json and curl PHP extensions installed?


Title: Re: BITTREX API + WAMP Server
Post by: DogWelder on August 23, 2017, 06:01:03 PM
Do you have the json and curl PHP extensions installed?

Hi! Yes, curl is running (uncommented in php.ini, also ran a simple function to check if enabled). From what I see, the variable $execResult is returned empty.
I have been deleting and making new API keys/secrets in the hopes that there lies the problem, but nothing seems to change.


Title: Re: BITTREX API + WAMP Server
Post by: poordeveloper on August 23, 2017, 06:11:39 PM
Maybe the problem lies on the fact that it's an https request? It's possible curl doesn't trust the server certificate. Add error_reporting(E_ALL); at the start of the script to see what the error is.


Title: Re: BITTREX API + WAMP Server
Post by: DogWelder on August 23, 2017, 06:44:08 PM
Error reporting didn't show anything, but after googling a bit, I found this page: http://unitstep.net/blog/2009/05/05/using-curl-in-php-to-access-https-ssltls-protected-sites/ (http://unitstep.net/blog/2009/05/05/using-curl-in-php-to-access-https-ssltls-protected-sites/).
I used the quick fix (for now) by adding the line:
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
Many thanks for your help!


Title: Re: BITTREX API + WAMP Server
Post by: poordeveloper on August 23, 2017, 06:53:45 PM
Error reporting didn't show anything, but after googling a bit, I found this page: http://unitstep.net/blog/2009/05/05/using-curl-in-php-to-access-https-ssltls-protected-sites/ (http://unitstep.net/blog/2009/05/05/using-curl-in-php-to-access-https-ssltls-protected-sites/).
I used the quick fix (for now) by adding the line:
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
Many thanks for your help!

That's what I told you regarding curl not trusting the server. However I'd be wary of doing so since it makes your script/site open to MITM attacks (intercepting the request to bittrex.com)


Title: Re: BITTREX API + WAMP Server
Post by: DogWelder on August 24, 2017, 07:16:19 PM
Of course, what I meant is that I googled about curl and the server certificates just like you suggested, and found the answer. I'll implement the secure solution as soon as I've finalized the script.
Many thanks again!


Title: Re: BITTREX API + WAMP Server
Post by: irmscher on December 22, 2017, 08:27:16 PM
Hey guys

I was having the same problem, tried to fix it with curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);

Now I'm getting Error 404: We can't seem to find what you're looking for, here's a screenshot:

https://hyfzgg.bl3302.livefilestore.com/y4my6dTFJ4lSTljw0wLyTh370Q07MMleB7jX5QSUaP92Cde5kOrZcpl01-jZZlXdAFwSrx1qinYvKIaSwgZUgRrW-AZggbpcKy_69w7PBi3kffRZ7rSS8OG9mflqNn47BgG2adB4VOqkBDshgWhUPc31id0FgUWWxOXcB_Kcp_oNCqRbmFBZg5tJJ3yYwyp4xj-nq7UYXMgK5rIrDmKVAx3Tw/2017-12-22.png

Here's my code (I'm using WAMP and 7.1.9 php version):

Code:
<?php
$apikey
='myKey';
$apisecret='mySecret';
$nonce=time();
$uri='https://bittrex.com/api/v1.1/market/getbalances?apikey='.$apikey.'&nonce='.$nonce;
$sign=hash_hmac('sha512',$uri,$apisecret);

$ch curl_init($uri);
curl_setopt($chCURLOPT_SSL_VERIFYPEERfalse);
curl_setopt($chCURLOPT_HTTPHEADER, array('apisign:'.$sign));
$execResult curl_exec($ch);
$obj json_decode($execResult);
?>

Any ideas what might be wrong?
Thanks :)