$value_max = (int) $argv[1];
$value_min = $value_max;
if (count($argv) > 2) {
    $value_min = $argv[2];
}
$value_step = 1;
if (count($argv) > 3) {
    $value_step = $argv[3];
}
$yahoo = yahoo_api_usdbrl();
$buy = $yahoo[0];
$sell = $yahoo[1];
$best_buy = find_best_rate($pairs_buy, $value_min, $value_max, $value_step, true);
$best_sell = find_best_rate($pairs_sell, $value_min, $value_max, $value_step, true);
$best_brl = find_best_rate($pairs_arbitrage_brl, $value_min, $value_max, $value_step, true);
$best_usd = find_best_rate($pairs_arbitrage_usd, $value_min, $value_max, $value_step, true);
//print_r($results);
//print_r($best);
print "BRL => BTC => USD (" . $best_buy['origin']['name'] . " => " . $best_buy['destination']['name'] . ")\n";
print $best_buy['origin']['results']['initial'] . " BRL => " . number_format($best_buy['destination']['results']['initial'], 8) . " BTC => " . number_format($best_buy['destination']['results']['bought'], 2) . " USD\n";
$vs_yahoo = $best_buy['rate_no_withdrawal'] / $yahoo[0] * 100 - 100;
$vs_yahoo = number_format($vs_yahoo, 2);
$sign = '';
if ($vs_yahoo > 0) {
    $sign = '+';
}
print number_format($best_buy['rate_no_withdrawal'], 4) . " (Buy) yahoo {$sign} {$vs_yahoo}%\n";
print number_format($best_buy['rate'], 4) . " (Buy and withdraw)\n";
print "\n";
print "USD => BTC => BRL (" . $best_sell['origin']['name'] . " => " . $best_sell['destination']['name'] . ")\n";
print $best_sell['origin']['results']['initial'] . " USD => " . number_format($best_sell['destination']['results']['initial'], 8) . " BTC => " . number_format($best_sell['destination']['results']['bought'], 2) . " BRL\n";
        array_push($pairs_arbitrage_usd, array($usd1, $usd2));
    }
}
$value_max = 10000;
if (count($argv) > 1) {
    $value_max = (int) $argv[1];
}
$value_min = $value_max;
if (count($argv) > 2) {
    $value_min = $argv[2];
}
$value_step = 10;
if (count($argv) > 3) {
    $value_step = $argv[3];
}
$best_brl = find_best_rate($pairs_arbitrage_brl, $value_min, $value_max, $value_step, true);
//$best_usd = find_best_rate($pairs_arbitrage_usd, $value_min, $value_max, $value_step, false);
date_default_timezone_set('America/Sao_Paulo');
$arb_log = "/tmp/arbitrage.log";
/* open trade log*/
$fh = fopen($arb_log, 'a+') or die("can't open file");
function print_log($tolog)
{
    global $fh;
    fwrite($fh, date('Y-m-d H:i:s', time()) . " - " . $tolog . "\n");
    print date('Y-m-d H:i:s', time()) . " - " . $tolog . "\n";
}
if ($best_brl['rate_no_withdrawal'] < 1.0) {
    print_log("BRL => BTC => BRL (" . $best_brl['origin']['name'] . " => " . $best_brl['destination']['name'] . ")");
    print_log($best_brl['origin']['results']['initial'] . " BRL => " . $best_brl['destination']['results']['initial'] . " BTC => " . $best_brl['destination']['results']['bought'] . " BRL");
    print_log(1.0 / $best_brl['rate_no_withdrawal'] . " (Sell)");
$value_max = (int) $argv[1];
$value_min = $value_max;
if (count($argv) > 2) {
    $value_min = $argv[2];
}
$value_step = 1;
if (count($argv) > 3) {
    $value_step = $argv[3];
}
$yahoo = yahoo_api_eurbrl();
$buy = $yahoo[0];
$sell = $yahoo[1];
$best_buy = find_best_rate($pairs_buy, $value_min, $value_max, $value_step, true);
$best_sell = find_best_rate($pairs_sell, $value_min, $value_max, $value_step, true);
$best_brl = find_best_rate($pairs_arbitrage_brl, $value_min, $value_max, $value_step, true);
$best_eur = find_best_rate($pairs_arbitrage_eur, $value_min, $value_max, $value_step, true);
//print_r($results);
//print_r($best);
print "BRL => BTC => EUR (" . $best_buy['origin']['name'] . " => " . $best_buy['destination']['name'] . ")\n";
print $best_buy['origin']['results']['initial'] . " BRL => " . number_format($best_buy['destination']['results']['initial'], 8) . " BTC => " . number_format($best_buy['destination']['results']['bought'], 2) . " EUR\n";
$vs_yahoo = $best_buy['rate_no_withdrawal'] / $yahoo[0] * 100 - 100;
$vs_yahoo = number_format($vs_yahoo, 2);
$sign = '';
if ($vs_yahoo > 0) {
    $sign = '+';
}
print number_format($best_buy['rate_no_withdrawal'], 4) . " (Buy) yahoo {$sign} {$vs_yahoo}%\n";
print number_format($best_buy['rate'], 4) . " (Buy and withdraw)\n";
print "\n";
print "EUR => BTC => BRL (" . $best_sell['origin']['name'] . " => " . $best_sell['destination']['name'] . ")\n";
print $best_sell['origin']['results']['initial'] . " EUR => " . number_format($best_sell['destination']['results']['initial'], 8) . " BTC => " . number_format($best_sell['destination']['results']['bought'], 2) . " BRL\n";