so it turns out that one member quit because i obviously didnt make it clear enough what i wanted and how i want it.
so, any takers?
i will provide ftp access to my server so you can test it.
i will also provide you with my API credentials (with the necessary permissions and very few BTC) so you can make sure it really does what it should.
the tricky point was the spread calculation, it seems.
so say you go to
http://bitcoin.clarkmoody.com/and you look at the column "sum"
i want the bot to use the bid order as bid side of the spread where "sum > x"
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
in this example, the ask price for the spread would be 8.89000
since this is the price where I can trade X bitcoins.
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
in this example the bid price for the bot would be 8.64670 since that is where I can trade 50 Bitcoins.
the intersango code
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;
}
?>
the mtgox code
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;
}
?>
the api-settings code
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","--");
?>