Advertisement
Guest User

Untitled

a guest
Aug 14th, 2014
243
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.34 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://api.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. $result = api_query("getinfo");
  45.  
  46. //$result = api_query("getmarkets");
  47.  
  48. //$result = api_query("mytransactions");
  49.  
  50. //$result = api_query("markettrades", array("marketid" => 26));
  51.  
  52. //$result = api_query("marketorders", array("marketid" => 26));
  53.  
  54. //$result = api_query("mytrades", array("marketid" => 26, "limit" => 1000));
  55.  
  56. //$result = api_query("allmytrades");
  57.  
  58. //$result = api_query("myorders", array("marketid" => 26));
  59.  
  60. //$result = api_query("allmyorders");
  61.  
  62. //$result = api_query("createorder", array("marketid" => 26, "ordertype" => "Sell", "quantity" => 1000, "price" => 0.00031000));
  63.  
  64. //$result = api_query("cancelorder", array("orderid" => 139567));
  65.  
  66. $result = api_query("calculatefees", array("ordertype" => 'Buy', 'quantity' => 1000, 'price' => '0.005'));
  67.  
  68. echo "<pre>".print_r($result, true)."</pre>";
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement