Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function btce_query($method, array $req = array()) {
- // API settings
- $key = ''; // your API-key
- $secret = ''; // 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; BTCE PHP client; '.php_uname('s').'; PHP/'.phpversion().')');
- }
- curl_setopt($ch, CURLOPT_URL, 'https://btc-e.com/tapi/');
- 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;
- }
- $result = btce_query("getInfo");
- echo "Bitcoins:";
- echo "\n";
- echo "".print_r($result['return']['funds']['btc'])."";
- echo "\n";
- echo "USD:";
- echo "\n";
- echo "".print_r($result['return']['funds']['usd'])."";
- echo "\n";
- echo "High: $high";
- echo "\n";
- echo "Low: $low";
- echo "\n";
- echo "Last: $last";
- echo "\n";
- if ($result['return']['funds']['btc'] > .1)
- {
- $sell = btce_query("Trade", array("pair" => "btc_usd", "type" => "sell", "amount" => .998, "rate" => "Price you want to sell at.)); //sell 1 BTC @ $1 less than high.
- echo "<pre>".print_r($sell, true)."</pre>";
- }
- else
- {
- echo "No Bitcoins to trade at this time.";
- }
- echo "\n";
- if ($result['return']['funds']['usd'] > .1 * $last)
- {
- $buy = btce_query("Trade", array("pair" => "btc_usd", "type" => "buy", "amount" => 1, "rate" => "Price you want to buy at.)); //buy 1 BTC @ $3 less than high.
- echo "<pre>".print_r($buy, true)."</pre>";
- }
- else
- {
- echo "No USD to trade at this time.";
- }
- echo "\n";
- $orders = btce_query("OrderList");
- echo "".print_r($orders['return'], 1)."";
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement