Need a unique gift idea?
A Pastebin account makes a great Christmas gift
SHARE
TWEET

TerraChange Trade API

a guest Mar 24th, 2018 153 Never
Upgrade to PRO!
ENDING IN00days00hours00mins00secs
 
  1. <?php
  2. function terrachange_query($method, array $req = array()) {
  3.         // API settings
  4.         $key = ''; // your API-key
  5.         $secret = ''; // your Secret-key
  6.  
  7.         $req['method'] = $method;
  8.         $mt = explode(' ', microtime());
  9.         $req['nonce'] = $mt[1];
  10.        
  11.         // generate the POST data string
  12.         $post_data = http_build_query($req, '', '&');
  13.  
  14.         $sign = hash_hmac('sha512', $post_data, $secret);
  15.  
  16.         // generate the extra headers
  17.         $headers = array(
  18.             'Sign: '.$sign,
  19.             'Key: '.$key,
  20.         );
  21.  
  22.         // our curl handle (initialize if required)
  23.         static $ch = null;
  24.         if (is_null($ch)) {
  25.                 $ch = curl_init();
  26.                 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  27.                 curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; BTCE PHP client; '.php_uname('s').'; PHP/'.phpversion().')');
  28.         }
  29.         curl_setopt($ch, CURLOPT_URL, 'https://terrachange.me/v1/tapi/');
  30.         curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
  31.         curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
  32.         curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
  33.  
  34.         // run the query
  35.         $res = curl_exec($ch);
  36.         if ($res === false) throw new Exception('Could not get reply: '.curl_error($ch));
  37.         $dec = json_decode($res, true);
  38.         if (!$dec) throw new Exception('Invalid data received, please make sure connection is working and requested API exists');
  39.         return $dec;
  40. }
  41.  
  42. $result = terrachange_query('getInfo');
  43. //$result = terrachange_query('Trade', array('pair' => 'WEXBTC_QIWIRUB', 'type' => 'buy', 'amount' => 1, 'rate' => 700000)); //buy 1 WEX BTC @ 700 000 QIWI RUB
  44.  
  45. var_dump($result);
  46. ?>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top