Title: Need help with btc-e api Post by: elvencrown on December 26, 2012, 10:03:29 AM I am trying to use btc-e's api to echo out the last trade on the btc/usd pair, using php. This is what I have done so far. Can anyone tell me how to make this work? Thanks.
<?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.ru/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; } $query = btce_query("2/btc_usd/ticker"); $btc_last = ("".$cur_avg=$query['ticker']['last']."\n"); echo $btc_last; ?> Title: Re: Need help with btc-e api Post by: SAC on December 26, 2012, 06:13:00 PM You are using the pubic api when getting ticker it does not need all that validation stuff a simple get will do it for you. An example of doing it I found in python below as you can see easy to do.
Code:
Which gives a result like this when run for ltc/btc just change the pair to what you want then parse the json output to get the final result wanted. Code:
Title: Re: Need help with btc-e api Post by: RyNinDaCleM on December 26, 2012, 08:35:48 PM This is a snippet from my BTC-e data feed in sig (Shameless plug :P).
This code requires the use of a couple additional includes, and cURL to be compiled with SSL support. Code: FILE *headerfile= 0; Title: Re: Need help with btc-e api Post by: elvencrown on December 26, 2012, 11:22:31 PM You are using the pubic api when getting ticker it does not need all that validation stuff a simple get will do it for you. An example of doing it I found in python below as you can see easy to do. Code:
Which gives a result like this when run for ltc/btc just change the pair to what you want then parse the json output to get the final result wanted. Code:
I really need something that works in php, because i've never used python before. Thanks for your help anyway. Title: Re: Need help with btc-e api Post by: elvencrown on December 26, 2012, 11:24:48 PM This is a snippet from my BTC-e data feed in sig (Shameless plug :P). This code requires the use of a couple additional includes, and cURL to be compiled with SSL support. Code: FILE *headerfile= 0; How would I use this to echo out the last trade on the btc/usd pair? Title: Re: Need help with btc-e api Post by: RyNinDaCleM on December 27, 2012, 05:30:02 AM How would I use this to echo out the last trade on the btc/usd pair? YGPM! Title: Re: Need help with btc-e api Post by: LeChatNoir on April 12, 2013, 04:51:44 PM Hi, is anyone else having problems today using API from BTCe for automatic trading?
They keep knocking me out of data feed every 5 minutes, then i have to wait for half an hour before the server start to give response to my requests. 5 minutes later i'm off again! Everything has been working well until today, i can't understand the reasons of this issue ??? It's curious that if i try to access https://btc-e.com/api/2/btc_usd/depth from mozilla everything works fine, everytime i refresh the page. If i send a request to download the string at the same address via my webClient in VB.NET it works only for a very short period of time let's say 5 minutes then their server stop responding to me. Title: Re: Need help with btc-e api Post by: JVarhol on January 12, 2014, 12:25:36 AM I was working on this when we decided to switch our code to python, hope it helps
Code: <head> I designed it to automatically reload every 2min, what it will do is get btc USD data ltc USD data and btc ltc data and display last buy and sell prices for all three. Modify it all you want. If you need any help just let me know. Like what you see? Feel free to donate BTC to 1JtxTAtnda5wcJJj78UkN2QwsUBEesmHAN JVarhol |