2weiX (OP)
Legendary
Offline
Activity: 2058
Merit: 1005
this space intentionally left blank
|
|
July 27, 2012, 11:58:34 AM Last edit: August 02, 2012, 04:42:07 PM by 2weiX |
|
i need a very simple intersango bot, preferrably on php basis which i can run from my webserver. this is what it needs to do in my own little pseudocode. variables $tradeable_amount // desired size at orderbook depth $btc_in_account // number of btc in account $percentage // which percentage of all btc in account should each order be $midspread // the calculated midspread $mintrade //minimum order size
calculate_the_spread (this is to disregard the little bitty orders that influence the order book) take the bid price at which the cumulated amount of bid sizes exceeds $tradeable_amount take the ask price at which the cumulated amount of ask sizes exceeds $tradeable_amount $midspread = (bid+ask)/2
sell calculate_the_spread; if $btc_in_account < $mintrade then $ordersize = $btc_in_account else $ordersize = roundup(3rd decimal;$btc_in_account*$percentage/100) place_order($ordersize;$midspread) exit script;
check_account are there bitcoins in the account? yes -> sell; no -> if there are any orders present, cancel_all_orders then exit script;
main check_account;
|
|
|
|
BCB
CTG
VIP
Legendary
Offline
Activity: 1078
Merit: 1002
BCJ
|
|
July 27, 2012, 12:15:37 PM |
|
What would you like it to do?
|
|
|
|
2weiX (OP)
Legendary
Offline
Activity: 2058
Merit: 1005
this space intentionally left blank
|
|
July 27, 2012, 02:54:15 PM |
|
thinking about it, it should support mtgox (€ only) too. it should be in a php file that i can call via cron every x minutes. simple algo: - calculate spread (bid and ask should be where X bitcoins are tradeable cumulatively, so I can ignore the 0.14471 and 0.4675 BTC orders)
- check "is there BTC balance in the account"
- yes --> create sell order for 1% of balance, put it in midspread
- no --> cancel all orders
think that should be doable for a reasonable amount of BTC. any takers?[/list]
|
|
|
|
2weiX (OP)
Legendary
Offline
Activity: 2058
Merit: 1005
this space intentionally left blank
|
|
July 28, 2012, 08:27:27 PM |
|
already have someone working on it. how much would you want for your bot and what are the features?
|
|
|
|
unclemantis
Member
Offline
Activity: 98
Merit: 10
(:firstbits => "1mantis")
|
|
July 29, 2012, 02:02:44 AM |
|
Does it NEED to be in PHP? I can build one in Ruby for 200 BTC
|
|
|
|
TECSHARE
In memoriam
Legendary
Offline
Activity: 3318
Merit: 2008
First Exclusion Ever
|
|
July 29, 2012, 03:27:26 PM |
|
Does it NEED to be in PHP? I can build one in Ruby for 200 BTC
Sure you just don't want a car instead?
|
|
|
|
2weiX (OP)
Legendary
Offline
Activity: 2058
Merit: 1005
this space intentionally left blank
|
|
July 31, 2012, 12:21:10 PM |
|
okay, one member of the forums is working on this and almost has it finished, but if you want to go ahead and send me your ideas, that's cool - if you send me a working php script then the 5 BTC bounty is yours. this has no influence on the reward fow user gweedo, who is already nearly done. I want to call this script via cron to sell my BTC if I should need to. This is what it should do, this pseudocode SHOULD be understandeable, please post general questions in this thread. variables $tradeable_amount // desired size at orderbook depth $btc_in_account // number of btc in account $percentage // which percentage of all btc in account should each order be $midspread // the calculated midspread $mintrade //minimum order size
calculate_the_spread (this is to disregard the little bitty orders that influence the order book) take the bid price at which a cumulated amount of bid size exceeds $tradeable_amount take the ask price at which a cumulated amount of ask size exceeds $tradeable_amount $midspread = (bid+ask)/2
sell calculate_the_spread; if $btc_in_account < $mintrade then $ordersize = $btc_in_account else $ordersize = roundup(3rd decimal;$btc_in_account*$percentage/100) place_order($ordersize;$midspread) exit script;
check_account are there bitcoins in the account? yes -> sell; no -> if there are any orders present, cancel_all_orders then exit script;
main check_account;
|
|
|
|
2weiX (OP)
Legendary
Offline
Activity: 2058
Merit: 1005
this space intentionally left blank
|
|
August 02, 2012, 04:39:53 PM Last edit: August 02, 2012, 06:30:32 PM by 2weiX |
|
...
|
|
|
|
drudgeboat
Newbie
Offline
Activity: 25
Merit: 0
|
|
August 02, 2012, 10:30:19 PM |
|
are you still looking for people? I thought you said you had a guy working on it already and was almost done?
|
|
|
|
2weiX (OP)
Legendary
Offline
Activity: 2058
Merit: 1005
this space intentionally left blank
|
|
August 03, 2012, 02:50:46 PM |
|
yes....
the one member i have workin on it seems very confident he will be able to deliver by monday.
i do, however, still accept submissions. the first (other than the member workin on it) to submit a working (!) bot for both sites receives a bounty.
bounty is 5 BTC.
|
|
|
|
2weiX (OP)
Legendary
Offline
Activity: 2058
Merit: 1005
this space intentionally left blank
|
|
August 03, 2012, 05:14:24 PM |
|
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 <?php require("settings.php"); if(INTERSANGOAPIKEY==""){ echo "You didn't supply your api key<br />"; kill; } for($i=0; $i<2; $i++){ $currentfunds=getfunds(); echo "Coins in account ".$currentfunds."<br />"; 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."<br />"; placeorder($size,$midspread); echo "Placed order for ".$size." for ".$midspread."<br />"; }else{ echo "Spread was negative<br />"; } }else{ cancelAllOrders(); echo "Canceled all orders "."<br />"; } } 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 <?php require("settings.php"); if(MTGOXSECRET=="" || MTGOXAPIKEY==""){ echo "You didn't supply your api key<br />"; kill; } for($i=0; $i<2; $i++){ $currentfunds=getfunds(); echo "Coins in account ".$currentfunds."<br />"; 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."<br />"; submitorder('ask', $midspread, $size); echo "Placed order for ".$size." for ".$midspread."<br />"; }else{ echo "Spread was negative<br />"; } }else{ cancelAllOrders(); echo "Canceled all orders "."<br />"; } }
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 <?php 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","--");
?>
|
|
|
|
2weiX (OP)
Legendary
Offline
Activity: 2058
Merit: 1005
this space intentionally left blank
|
|
August 03, 2012, 05:23:13 PM |
|
also tipped the member 4 BTC for his troubles.
|
|
|
|
mr_gant
Newbie
Offline
Activity: 18
Merit: 0
|
|
August 06, 2012, 06:57:52 AM |
|
bounty is 5 BTC. Software for bounty is a great way to get low quality software from inexperienced devs who can't do any better. Not the greatest idea for automated financial software.
|
|
|
|
2weiX (OP)
Legendary
Offline
Activity: 2058
Merit: 1005
this space intentionally left blank
|
|
August 06, 2012, 01:54:20 PM |
|
while that is true, i laid out what i want in pseudocode pretty clearly and i also tried to make clear exactly how i want the spread to be calculated.
the last couple of things (including two programming tasks) i had made for bounties worked out pretty well.
the biggest problem is members with a limited understanding of the english language just diving head-in and doing *something* instead of asking first.
i dont want a moneymaking monster... i just need to sell close to VWAP, shouldnt be too hard.
|
|
|
|
mattmcegg
Newbie
Offline
Activity: 27
Merit: 0
|
|
April 18, 2013, 05:46:42 PM |
|
this code is no longer working for me, but it was for a long time... is anyone else using the API with this code?
did gox make changes to their API to prevent DDOS/HFT?
|
|
|
|
BCB
CTG
VIP
Legendary
Offline
Activity: 1078
Merit: 1002
BCJ
|
|
April 18, 2013, 08:38:35 PM |
|
change the end point to data.mtgox.com/api
|
|
|
|
mattmcegg
Newbie
Offline
Activity: 27
Merit: 0
|
|
April 22, 2013, 04:53:53 PM |
|
change the end point to data.mtgox.com/api
YES that fixes it thanks!
|
|
|
|
|