YES that fixes it thanks!
It was the Bitcointalk forum that inspired us to create Bitcointalksearch.org - Bitcointalk is an excellent site that should be the default page for anybody dealing in cryptocurrency, since it is a virtual gold-mine of data. However, our experience and user feedback led us create our site; Bitcointalk's search is slow, and difficult to get the results you need, because you need to log in first to find anything useful - furthermore, there are rate limiters for their search functionality.
The aim of our project is to create a faster website that yields more results and faster without having to create an account and eliminate the need to log in - your personal data, therefore, will never be in jeopardy since we are not asking for any of your data and you don't need to provide them to use our site with all of its capabilities.
We created this website with the sole purpose of users being able to search quickly and efficiently in the field of cryptocurrency so they will have access to the latest and most accurate information and thereby assisting the crypto-community at large.
X = 20
price BTC sum
8.85212 1.1325 1.1
8.86147 0.0136 1.1
8.88159 1.5413 2.7
8.88234 25.0000 27.7
in this example, the ask price for the spread would be 8.88234
X = 30
price BTC sum
8.85150 1.1325 1.1
8.85212 1.1325 2.3
8.88159 1.5413 3.8
8.88234 25.0000 28.8
8.88362 0.0192 28.8
8.89000 8.8900 37.7
X = 50
sum BTC price
10.2 10.2245 8.67497
20.4 10.2249 8.67466
80.4 59.9540 8.64670
140.4 59.9524 8.64615
154.2 13.8541 8.64570
require("settings.php");
if(INTERSANGOAPIKEY==""){
echo "You didn't supply your api key
";
kill;
}
for($i=0; $i<2; $i++){
$currentfunds=getfunds();
echo "Coins in account ".$currentfunds."
";
if($currentfunds > MINAMOUNTOFBTC){
$ticker=json_decode(request("https://intersango.com/api/ticker.php?currency_pair_id=2"), true);
$ask=$ticker['sell'];
$bid=$ticker['buy'];
if($bid-$ask>=0 && ($bid-$ask)>=SPREAD){
$size=$currentfunds*(PERCENTTOTRADE/100);
$midspread=($bid-$ask)/2;
echo "Order size ".$size."
";
placeorder($size,$midspread);
echo "Placed order for ".$size." for ".$midspread."
";
}else{
echo "Spread was negative
";
}
}else{
cancelAllOrders();
echo "Canceled all orders "."
";
}
}
function getAcountid(){
$data=array('api_key'=>INTERSANGOAPIKEY);
$accounts=json_decode(request('https://intersango.com/api/authenticated/v0.1/listAccounts.php',$data),true);
return $accounts[0]['id'];
}
function getfunds(){
$data=array('api_key'=>INTERSANGOAPIKEY);
$accounts=json_decode(request('https://intersango.com/api/authenticated/v0.1/listAccounts.php',$data),true);
for($i=0; $i<sizeof($accounts); $i++){
if($accounts[$i]['currency_id']==1)
return $accounts[$i]['balance'];
}
return null;
}
function placeorder($quantity, $rate){
$data=array('api_key'=>INTERSANGOAPIKEY);
$data['account_id']=getAcountid();
$data['selling']=true;
$data['type']='gtc';
$data['quantity']=$quantity;
$data['rate']=$rate;
$data['base_account_id']='';
$data['quote_account_id']='';
request('https://intersango.com/api/authenticated/v0.1/placeLimitOrder.php', $data);
}
function cancelAllOrders(){
$data=array('api_key'=>INTERSANGOAPIKEY);
$data['account_id']=getAcountid();
$orders=json_decode(request('https://intersango.com/api/authenticated/v0.1/listOrders.php', $data));
unset($data['filter']);
for($i=0; $i<count($orders); $i++){
$data['order_id']=$orders[$i]['id'];
request('https://intersango.com/api/authenticated/v0.1/requestCancelOrder.php', $data);
}
}
function request($url, $postdata=null){
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch,CURLOPT_CONNECTTIMEOUT, 30);
if($postdata!=null){
curl_setopt($ch,CURLOPT_POST, count($postdata));
$fields_string;
foreach($postdata as $key=>$value) {
$fields_string .= $key.'='.$value.'&';
}
rtrim($fields_string,'&');
curl_setopt($ch, CURLOPT_POSTFIELDS, $fields_string);
}
$return=curl_exec($ch);
curl_close($ch);
return $return;
}
?>
require("settings.php");
if(MTGOXSECRET=="" || MTGOXAPIKEY==""){
echo "You didn't supply your api key
";
kill;
}
for($i=0; $i<2; $i++){
$currentfunds=getfunds();
echo "Coins in account ".$currentfunds."
";
if($currentfunds > MINAMOUNTOFBTC){
$ticker=mtgox_query('1/BTCEUR/ticker');
$ask=$ticker['return']['sell']['value'];
$bid=$ticker['return']['buy']['value'];
if($bid-$ask>=0 && ($bid-$ask)>=SPREAD){
$size=$currentfunds*(PERCENTTOTRADE/100);
$midspread=($bid-$ask)/2;
echo "Order size ".$size."
";
submitorder('ask', $midspread, $size);
echo "Placed order for ".$size." for ".$midspread."
";
}else{
echo "Spread was negative
";
}
}else{
cancelAllOrders();
echo "Canceled all orders "."
";
}
}
function getfunds(){
$temp=mtgox_query('0/getFunds.php');
return $temp['btcs'];
}
function cancelAllOrders(){
$orders=mtgox_query('1/generic/private/orders', array('type'=>'1', 'status'=>'1'));
for($i=0; $i<count($orders['return']); $i++){
mtgox_query('0/cancelOrder.php', array('oid'=>$order['return'][$i]['oid'], 'type'=>'1'));
}
}
function submitorder($type, $price, $amount){
mtgox_query("1/BTCEUR/private/order/add", array('type'=>$type,'amount_int'=>$amount,'price_int'=>$price));
}
function mtgox_query($path, array $req = array()) {
// generate a nonce as microtime, with as-string handling to avoid problems with 32bits systems
$mt = explode(' ', microtime());
$req['nonce'] = $mt[1].substr($mt[0], 2, 6);
// generate the POST data string
$post_data = http_build_query($req, '', '&');
// generate the extra headers
$headers = array(
'Rest-Key: '.MTGOXAPIKEY,
'Rest-Sign: '.base64_encode(hash_hmac('sha512', $post_data, base64_decode(MTGOXSECRET), true)),
);
// 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; MtGox PHP client; '.php_uname('s').'; PHP/'.phpversion().')');
}
curl_setopt($ch, CURLOPT_URL, 'https://mtgox.com/api/'.$path);
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;
}
?>
define("SPREAD",10); // THIS DETAIL IS WHAT MAKES IT DIFFICULT
define("PERCENTTOTRADE",1); //Percent of the current ammount to trade
define("MINAMOUNTOFBTC",1); //this would be the minimum amount of btc in the acount before a trade could take place
// THIS SHOULD BE: "THE MINIMUM SIZE OF EACH ORDER"
//mtgox login information
define("MTGOXAPIKEY","--");
define("MTGOXSECRET","--");
//interango api key
define("INTERSANGOAPIKEY","--");
?>