Free bitcoin trading bot download for Cex.io

This is a free bitcoin script that I have developed to help me trade virtual currencies on cex.io and to make profit. It works if you set it up correctly. I am sharing it with you.

You can download the source code of the trading bot here:

Download cexio bot v1.6

This article explains how the algorithm of the bot works: Bitcoin trading by using bots

How to install the trading bot

trade.php

This script is for trading bitcoins, litecoins, darkcoins and any other virtual currency on cex.io. You have to replace “USERNAME”, “APIKEY” and “APISECRET” with your the ones you have on cex.io. This script needs the library “cexapi.class.php”.

<?php
/**
 * Author: Boyan Yankov
 * Email : boian_iankov@abv.bg
 * PayPal: boian_iankov@abv.bg
 * feel free to donate
 */
?>
<html>
<head>
 <title>CEX.IO Trading Bot v.1.6</title>
 <meta http-equiv="refresh" content="600"><!-- auto refresh every few minutes -->
</head>
<body>
<a href="trade.php" target="">Retry orders</a><br />
<a href="orders.php" target="_blank">List active orders</a><br /><br />
<?php
 // Include Cex.io PHP API
 include_once("cexapi.class.php");
 // Create API Object
 $api = new cexapi("USERNAME", "APIKEY", "APISECRET");
 //Set globals
 $trade_amount = 1.50;
 $minimum_profit_percent = 1.00;
 $minimum_avg_profit_percent = 0.60;
 $logfile = 'log';
 //trade sequence operaion definition
 //array('<FROM CURRECNY>', '<TO CURRECNY>', '<OPERATION>', '<CURRECNY PAIR>', '<+/- % TOLERANCE>')
 $trade_sequences = array();
 $trade_sequences[] = array(
 array('LTC', 'BTC', 'sell', 'LTC/BTC', -0.02),
 array('BTC', 'DRK', 'buy', 'DRK/BTC', +0.06),
 array('DRK', 'LTC', 'sell', 'DRK/LTC', -0.13),
 );
 $trade_sequences[] = array(
 array('LTC', 'DRK', 'buy', 'DRK/LTC', +0.13),
 array('DRK', 'BTC', 'sell', 'DRK/BTC', -0.06),
 array('BTC', 'LTC', 'buy', 'LTC/BTC', +0.02),
 );
 $trade_sequences[] = array(
 array('LTC', 'BTC', 'sell', 'LTC/BTC', -0.02),
 array('BTC', 'MEC', 'buy', 'MEC/BTC', +0.07),
 array('MEC', 'LTC', 'sell', 'MEC/LTC', -0.10),
 );
 $trade_sequences[] = array(
 array('LTC', 'MEC', 'buy', 'MEC/LTC', +0.10),
 array('MEC', 'BTC', 'sell', 'MEC/BTC', -0.07),
 array('BTC', 'LTC', 'buy', 'LTC/BTC', +0.02),
 );
 /*
 $trade_sequences[] = array(
 array('GHS', 'BTC', 'sell', 'GHS/BTC', -0.02),
 array('BTC', 'LTC', 'buy', 'LTC/BTC', +0.02),
 array('LTC', 'GHS', 'buy', 'GHS/LTC', +0.26),
 );
 $trade_sequences[] = array(
 array('GHS', 'LTC', 'sell', 'GHS/LTC', -0.26),
 array('LTC', 'BTC', 'sell', 'LTC/BTC', -0.02),
 array('BTC', 'GHS', 'buy', 'GHS/BTC', +0.02),
 );
 */
 function getPrice($pair = 'LTC/BTC', $time_interval = '-30 minutes'){
 global $api;
 global $logfile;
 echo 'Getting prices for '.$pair.' for the time interval '.$time_interval.'... ';
 $history = $api->trade_history(1, $pair);
 echo 'Sending request...<br />';
 $count = 0;
 $price_sum = 0;
 foreach ($history as $deal){
 //skip old trades
 if ($deal['date'] < strtotime($time_interval))
 continue;
 $count++;
 if ($count == 1)
 $price['last'] = $deal['price'];
 $price_sum += $deal['price'];
 }
 if ($count == 0){
 writeLog($logfile, 'Error! Not enough data for pair '.$pair.' for the "'.$time_interval.'" interval!'.PHP_EOL);
 die('Error! Not enough data for pair '.$pair.' for the "'.$time_interval.'" interval!');
 }
 $price['precision_points'] = $count;
 $price['average'] = $price_sum/$count;
 return $price;
 }
 function simulateTrade($prices, $trade_sequence, $initial_amount, $trade_sequence, $price_type='last'){
 echo 'Starting trade simulation using '.$price_type.' price...<br />';
 echo 'Parsing sequence: <br />';
 $amount = $initial_amount;
 echo 'Initial amount: '.$initial_amount.'<br />';
 echo 'Operations: ';
 foreach ($trade_sequence as $trade_rule){
 $pair = $trade_rule[3];
 $amount_before_trade = $amount;
 if ($trade_rule[2] == 'buy')
 $amount = $amount / $prices[$pair][$price_type];
 elseif ($trade_rule[2] == 'sell')
 $amount = $amount * $prices[$pair][$price_type];
 echo number_format($amount_before_trade, 8).' '.$trade_rule[0].' to '.number_format($amount, 8).' '.$trade_rule[1].'; ';
 }
 echo '<br />';
 $profit = $amount-$initial_amount;
 $tax = 3 * 0.002 * $initial_amount;
 $tolerance = ( ( abs($trade_sequence[0][4]) + abs($trade_sequence[1][4]) + abs($trade_sequence[2][4]) ) / 100 ) * $initial_amount;
 $net_profit = $profit - $tax - $tolerance;
 $net_profit_percent = $net_profit / $initial_amount * 100;
 echo 'Profit: '.number_format($profit, 8).'; ';
 echo 'Tax loss: '.number_format($tax, 8).'; ';
 echo 'Tolerance loss: '.number_format($tolerance, 8).'; ';
 echo 'Net profit: '.number_format($net_profit, 8).'; <br />';
 echo 'Net profit, %: '.number_format($net_profit_percent, 2).'<br />';
 echo '<br />';
 return $net_profit_percent;
 }
 function startTrade($prices, $trade_sequence, $trade_amount){
 global $api;
 echo 'Placing order...<br /><br />';
 foreach ($trade_sequence as $trade_rule){
 $pair = $trade_rule[3];
 $current_trade_amount = recalculateAmount($pair, $prices, $trade_amount);
 //add tolerance to price
 $tolerance_percent = $trade_rule[4];
 $corrected_price = $prices[$pair]['last'] + $prices[$pair]['last'] * ($tolerance_percent / 100);
 $corrected_price = number_format($corrected_price, 8);
 echo 'Order details ('.$trade_rule[0].' to '.$trade_rule[1].'): '.$trade_rule[2].' amount: '.$current_trade_amount.' '.$amount_calculation_currency.', price: '.$prices[$pair]['last'].' '.', corrected price: '.$corrected_price.' '.$pair.'<br />';
 echo 'Sending request...<br />';
 $order_result = $api->place_order($trade_rule[2], $current_trade_amount, $corrected_price, $pair);
 echo 'Order result: ';
 var_dump($order_result);
 echo '<br />';
 echo '<br />';
 //wait for a few seconds before the next operation
 sleep(5);
 }
 }
 function recalculateAmount($pair, $prices, $trade_amount){
 //recalculates the amount from the base currency to the trade currency
 //formulas for base currency for USD - comment the unnecessery!
 /*
 if ($pair == 'BTC/USD'){
 $amount_calculation_currency = 'BTC/USD';
 $operation_calculation_currency = 'div';
 }
 if ($pair == 'LTC/BTC'){
 $amount_calculation_currency = 'LTC/USD';
 $operation_calculation_currency = 'div';
 }
 if ($pair == 'LTC/USD'){
 $amount_calculation_currency = 'LTC/USD';
 $operation_calculation_currency = 'div';
 }
 */
 /*
 //formulas for base currency for GHS - comment the unnecessery!
 if ($pair == 'GHS/BTC'){
 $amount_calculation_currency = 'GHS/BTC';
 $operation_calculation_currency = 'non';
 }
 if ($pair == 'LTC/BTC'){
 $amount_calculation_currency = 'GHS/LTC';
 $operation_calculation_currency = 'mul';
 }
 if ($pair == 'GHS/LTC'){
 $amount_calculation_currency = 'GHS/LTC';
 $operation_calculation_currency = 'non';
 }
 */
 //formulas for base currency for LTC - comment the unnecessery!
 if ($pair == 'LTC/BTC'){
 $amount_calculation_currency = 'LTC/BTC';
 $operation_calculation_currency = 'non';
 }
 if ($pair == 'DRK/BTC'){
 $amount_calculation_currency = 'DRK/LTC';
 $operation_calculation_currency = 'div';
 }
 if ($pair == 'DRK/LTC'){
 $amount_calculation_currency = 'DRK/LTC';
 $operation_calculation_currency = 'div';
 }
 if ($pair == 'MEC/BTC'){
 $amount_calculation_currency = 'MEC/LTC';
 $operation_calculation_currency = 'div';
 }
 if ($pair == 'MEC/LTC'){
 $amount_calculation_currency = 'MEC/LTC';
 $operation_calculation_currency = 'div';
 }
 //calculate the amount for the current trade in the target currency
 if ($operation_calculation_currency == 'div'){
 $current_trade_amount = number_format($trade_amount / $prices[$amount_calculation_currency]['last'], 8);
 } elseif ($operation_calculation_currency == 'mul'){
 $current_trade_amount = number_format($trade_amount * $prices[$amount_calculation_currency]['last'], 8);
 } else {
 $current_trade_amount = number_format($trade_amount, 8);
 }
 return $current_trade_amount;
 }
 function writeLog($logfile, $message){
 //writting to log
 $fp = fopen($logfile, 'a');
 fwrite($fp, $message);
 //echo $fp.$message.'trade logged!';
 fclose($fp);
 }
 echo 'Starting script on '.date('m/d/Y h:i:s a', time()).'<br /><br />';
 writeLog($logfile, 'Starting script on '.date('m/d/Y h:i:s a', time()).PHP_EOL);
 //comment out unnecessary queries to reduce load
 $prices['LTC/BTC'] = getPrice('LTC/BTC', '-15 minutes');
 $prices['DRK/BTC'] = getPrice('DRK/BTC', '-30 minutes');
 $prices['DRK/LTC'] = getPrice('DRK/LTC', '-60 minutes');
 $prices['MEC/BTC'] = getPrice('MEC/BTC', '-60 minutes');
 $prices['MEC/LTC'] = getPrice('MEC/LTC', '-60 minutes');
 //$prices['GHS/LTC'] = getPrice('GHS/LTC', '-15 minutes');
 //$prices['LTC/USD'] = getPrice('LTC/USD', '-240 minutes');
 //$prices['GHS/BTC'] = getPrice('GHS/BTC', '-10 minutes');
 //$prices['BTC/USD'] = getPrice('BTC/USD', '-60 minutes');
 echo '<br />';
 echo 'Prices: ';
 var_dump($prices);
 echo '<br /><br />';
 echo 'Trade seqences dump: ';
 var_dump($trade_sequences);
 echo '<br /><br />';
 foreach ($trade_sequences as $trade_sequence){
 $net_profit_percent_last = simulateTrade($prices, $trade_sequence, $trade_amount, $trade_sequence, 'last');
 $net_profit_percent_average = simulateTrade($prices, $trade_sequence, $trade_amount, $trade_sequence, 'average');
 if ($net_profit_percent_last >= $minimum_profit_percent and $net_profit_percent_average >= $minimum_avg_profit_percent){
 startTrade($prices, $trade_sequence, $trade_amount);
 writeLog($logfile, 'Trading on '.date('m/d/Y h:i:s a', time()).PHP_EOL);
 } else {
 echo 'Skipping order...<br /><br />';
 }
 }
?>
<body>
<html>

orders.php

This script provides a web interface to view and manage your active trading orders – manually, from the script. You have to replace “USERNAME”, “APIKEY” and “APISECRET” with your the ones you have on cex.io. This script needs the library “cexapi.class.php”.

<?php
/**
 * Author: Boyan Yankov
 * Email : boian_iankov@abv.bg
 * PayPal: boian_iankov@abv.bg
 * feel free to donate
 */
?>
<html>
<head>
 <title>CEX.IO Active Orders</title>
 <meta http-equiv="refresh" content="600"><!-- auto refresh every few minutes -->
</head>
<body>
<a href="orders.php">Refresh list</a><br /><br />
<?php
 // Include Cex.io PHP API
 include_once("cexapi.class.php");
 // Create API Object
 //fill in username, api_key, api_secret
 $api = new cexapi("USERNAME", "APIKEY", "APISECRET");
 if (isset($_GET['cancel'])){
 echo 'Canceling order...'.$_GET['cancel'].'<br />';
 echo 'Result: ';
 var_dump($api->cancel_order($_GET['cancel']));
 echo '<br /><br />';
 }
 echo 'Listing orders...<br />';
 $orders = array();
 //comment out unnecessary queries to reduce load
 $orders = array_merge($orders, $api->open_orders($couple = 'BTC/USD'));
 $orders = array_merge($orders, $api->open_orders($couple = 'LTC/BTC'));
 $orders = array_merge($orders, $api->open_orders($couple = 'LTC/USD'));
 $orders = array_merge($orders, $api->open_orders($couple = 'GHS/BTC'));
 $orders = array_merge($orders, $api->open_orders($couple = 'GHS/LTC'));
 $orders = array_merge($orders, $api->open_orders($couple = 'DRK/BTC'));
 $orders = array_merge($orders, $api->open_orders($couple = 'DRK/LTC'));
 $orders = array_merge($orders, $api->open_orders($couple = 'MEC/BTC'));
 $orders = array_merge($orders, $api->open_orders($couple = 'MEC/LTC'));
 echo '<table border="1">';
 echo '
 <tr>
 <th>ID</th>
 <th>Time</th>
 <th>Type</th>
 <th>Price</th>
 <th>Amount</th>
 <th>Pending Amount</th>
 <th>Cancel</th>
 </tr>
 ';
 foreach ($orders as $order){
 echo '<tr>';
 echo '<td>'.$order['id'].'</td>';
 echo '<td>'.date('Y-m-d H:i:s', substr($order['time'], 0, 10)).' ('.$order['time'].')</td>';
 echo '<td>'.$order['type'].'</td>';
 echo '<td>'.$order['price'].'</td>';
 echo '<td>'.$order['amount'].'</td>';
 echo '<td>'.$order['pending'].'</td>';
 echo '<td><a href="?cancel='.$order['id'].'">Cancel</a></td>';
 echo '</tr >';
 }
 echo
 '</table>';
?>
<body>
<html>

cron.php

This script is for automatic trading. If you want to trade virtual currencies automatically, you have to set us this script to get loaded with a cron job.

<?php
/**
 * Author: Boyan Yankov
 * Email : boian_iankov@abv.bg
 * PayPal: boian_iankov@abv.bg
 * feel free to donate
 */
?>
<?php
require('trade.php');
?>

This code is provided with absolutely no warranty of any kind and with no support – use it at your own risk.

Leave a Reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload CAPTCHA.