Advertisement
JudeAustin

Five Million

Jan 19th, 2014
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.70 KB | None | 0 0
  1. <?php
  2.  
  3. function api_query($method, array $req = array()) {
  4.         // API settings
  5.         $key = ''; // your API-key
  6.         $secret = ''; // your Secret-key
  7.  
  8.         $req['method'] = $method;
  9.         $mt = explode(' ', microtime());
  10.         $req['nonce'] = $mt[1];
  11.        
  12.         // generate the POST data string
  13.         $post_data = http_build_query($req, '', '&');
  14.  
  15.         $sign = hash_hmac("sha512", $post_data, $secret);
  16.  
  17.         // generate the extra headers
  18.         $headers = array(
  19.                 'Sign: '.$sign,
  20.                 'Key: '.$key,
  21.         );
  22.  
  23.         // our curl handle (initialize if required)
  24.         static $ch = null;
  25.         if (is_null($ch)) {
  26.                 $ch = curl_init();
  27.                 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  28.                 curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; Cryptsy API PHP client; '.php_uname('s').'; PHP/'.phpversion().')');
  29.         }
  30.         curl_setopt($ch, CURLOPT_URL, 'https://www.cryptsy.com/api');
  31.         curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
  32.         curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
  33.         curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
  34.  
  35.         // run the query
  36.         $res = curl_exec($ch);
  37.  
  38.         if ($res === false) throw new Exception('Could not get reply: '.curl_error($ch));
  39.         $dec = json_decode($res, true);
  40.         if (!$dec) throw new Exception('Invalid data received, please make sure connection is working and requested API exists');
  41.         return $dec;
  42. }
  43.  
  44.  
  45. $result = api_query("createorder", array("marketid" => 118, "ordertype" => "Buy", "quantity" => 5000000, "price" => 0.00000001));
  46.  
  47.  
  48. echo "<pre>".print_r($result, true)."</pre>";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement