Bitcoin Forum
July 18, 2024, 11:18:02 AM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Cryptsy API usage PROBLEM (help needed)  (Read 1469 times)
stas (OP)
Sr. Member
****
Offline Offline

Activity: 420
Merit: 250



View Profile
March 04, 2014, 07:00:53 AM
 #1

Hi,

I have used the php code in crypsy-api site.
When i try to get "marketorders" or any other operation that requests authentication.

i have generated public/private key using my user at crypsy
and added them to the code.

What am i doing wrong?

the reault is:
<pre>Array
(
    [success] => 0
    [error] => Unable to Authorize Request - Check Your Post Data
)
</pre>

the function i use:

function api_query($method, array $req = array()) {
    // API settings
    $key = '[Trust me i have filled it]'; // your API-key
    $secret = '[Trust me i have filled it]'; // your Secret-key

    $req['method'] = $method;
    $mt = explode(' ', microtime());
    $req['nonce'] = $mt[1];
    
    // generate the POST data string
    $post_data = http_build_query($req, '', '&');

    $sign = hash_hmac("sha512", $post_data, $secret);

    // generate the extra headers
    $headers = array(
            'Sign: '.$sign,
            'Key: '.$key,
    );

    // our curl handle (initialize if required)
    static $ch = null;
    if (is_null($ch)) {
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; Cryptsy API PHP client; '.php_uname('s').'; PHP/'.phpversion().')');
    }
    print('Mozilla/4.0 (compatible; Cryptsy API PHP client; '.php_uname('s').'; PHP/'.phpversion().')');
    curl_setopt($ch, CURLOPT_URL, 'https://api.cryptsy.com/api');
    curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);

    // run the query
    $res = curl_exec($ch);

    if ($res === false) throw new Exception('Could not get reply: '.curl_error($ch));
    $dec = json_decode($res, true);
    if (!$dec) throw new Exception('Invalid data received, please make sure connection is working and requested API exists');
    return $dec;
}

the api call:

$result = api_query("marketorders", array("marketid" => 3));




Thanks:)

stas (OP)
Sr. Member
****
Offline Offline

Activity: 420
Merit: 250



View Profile
March 04, 2014, 09:22:53 AM
 #2

up

stas (OP)
Sr. Member
****
Offline Offline

Activity: 420
Merit: 250



View Profile
March 04, 2014, 01:55:54 PM
 #3

up

stas (OP)
Sr. Member
****
Offline Offline

Activity: 420
Merit: 250



View Profile
March 05, 2014, 10:57:23 AM
 #4

up

dfriedmann
Newbie
*
Offline Offline

Activity: 2
Merit: 0


View Profile
March 11, 2014, 01:28:45 AM
 #5

Hi, I came across the same issue.
On the cryptsy settings page, make sure you click on the "API Enabled/Disabled" switch.
It's disabled by default and not easily noticed.
chilly2k
Legendary
*
Offline Offline

Activity: 1007
Merit: 1000


View Profile
July 08, 2014, 01:32:06 PM
 #6


    Did you ever get this working? 

   I think your problem is in the array your passing in.  If you put a var_dump for the post_data just after you build it, I think you'll see it's not what your expecting. 

I believe (without checking at all), that the array your passing in will have a key(index) of marketid and a value of 3.  not the index 0 and value "marketid => 3" your expecting.  I don't remember if you need marketid in quotes on the call or not, if yes, then maybe wrap the whole thing in single quotes, and if no, then move the double quote end, from right after marketid to after the 3. 

          Good luck  Bob   

Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!