-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbrl_to_usd_comparator.php
131 lines (115 loc) · 5.42 KB
/
brl_to_usd_comparator.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
<?php
/*
* Copyright (c) 2015 Girino Vey.
*
* This software is licenced under Girino's Anarchist License.
*
* Permission to use this software, modify and distribute it, or parts of
* it, is granted to everyone who wishes provided that the conditions
* in the Girino's Anarchist License are met. Please read it on the link
* bellow.
*
* The full license is available at: http://girino.org/license
*/
require_once 'GenericAPI.php';
require_once 'ExchangeAPIs.php';
function usage() {
print "Usage: " . $argv[0] . " <maxamount> [<min amount>=10]";
}
// Code bellow this comment is what you need to change in order to do whatever you want.
$foxbit = array( new FoxBitOrderbook(), new FoxbitFeeCalculator(), 'BRL', 'FOX' );
$b2u = array( new B2UOrderbook(), new B2UFeeCalculator(), 'BRL', 'B2U' );
$mbtc = array( new MBTCOrderbook(), new MBTCFeeCalculator(), 'BRL', 'MBTC' );
$negocie = array( new NegocieCoinsOrderbook(), new NegocieCoinsFeeCalculator(), 'BRL', 'NEGOCIE' );
$basebit = array( new BasebitOrderbook(), new BasebitFeeCalculator(), 'BRL', 'BASEBIT' );
$flowbtc = array( new FlowBTCOrderbook(), new FlowBTCFeeCalculator(), 'BRL', 'FLOW' );
$bitinka = array( new BitinkaOrderbook(), new BitinkaFeeCalculator(), 'BRL', 'BITINKA' );
$bitfinex = array( new BitFinexOrderbook(), new BitFinexFeeCalculator(), 'USD', 'BITFINEX' );
$coinbase = array( new CoinbaseOrderbook(), new CoinbaseFeeCalculator(), 'USD', 'COINBASE' );
$kraken = array( new KrakenOrderbook(), new KrakenFeeCalculator(), 'USD', 'KRAKEN' );
$bitstamp = array( new BitstampOrderbook(), new BitstampFeeCalculator(), 'USD', 'BITSTAMP' );
$btce = array( new BtceOrderbook(), new BtceFeeCalculator(), 'USD', 'BTC-E' );
$okcoin = array( new OKCoinOrderbook(), new OKCoinFeeCalculator(), 'USD', 'OKCOIN' );
$brls = array($foxbit, $b2u, $mbtc, $negocie, $flowbtc, $bitinka);
$usds = array($bitfinex, $coinbase, $kraken, $bitstamp, $btce, $okcoin);
$pairs_buy = array();
$pairs_sell = array();
$pairs_arbitrage_brl = array();
$pairs_arbitrage_usd = array();
// BRL -> USD
foreach ($brls as $brl) {
foreach ($usds as $usd) {
array_push($pairs_buy, array($brl, $usd));
}
}
// USD -> BRL
foreach ($brls as $brl) {
foreach ($usds as $usd) {
array_push($pairs_sell, array($usd, $brl));
}
}
// BRL -> BRL
foreach ($brls as $brl1) {
foreach ($brls as $brl2) {
array_push($pairs_arbitrage_brl, array($brl1, $brl2));
}
}
// USD -> USD
foreach ($usds as $usd1) {
foreach ($usds as $usd2) {
array_push($pairs_arbitrage_usd, array($usd1, $usd2));
}
}
if (count($argv) <= 1) {
usage();
exit;
}
$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";
$vs_yahoo = (1.0/$best_sell['rate_no_withdrawal']) / $yahoo[1] * 100 - 100;
$vs_yahoo = number_format($vs_yahoo, 2);
$sign = '';
if ( $vs_yahoo > 0 ) $sign = '+';
print number_format(1.0/$best_sell['rate_no_withdrawal'],4) . " (Sell) yahoo $sign $vs_yahoo%\n";
print number_format(1.0/$best_sell['rate'],4) . " (Sell and withdraw)\n";
print "\n";
print "BRL => USD (Yahoo Finance - no bank fees considered)\n";
print $yahoo[0] . " (Buy) / " . $yahoo[1] . " (Sell)\n";
print "\n";
print "BRL => BTC => BRL (" . $best_brl['origin']['name'] . " => ". $best_brl['destination']['name'] . ")\n";
print $best_brl['origin']['results']['initial'] . " BRL => " . $best_brl['destination']['results']['initial'] . " BTC => " . $best_brl['destination']['results']['bought'] . " BRL\n";
print 1.0/$best_brl['rate_no_withdrawal'] . " (Sell)\n";
print 1.0/$best_brl['rate'] . " (Sell and withdraw)\n";
print "\n";
print "USD => BTC => USD (" . $best_usd['origin']['name'] . " => ". $best_usd['destination']['name'] . ")\n";
print $best_usd['origin']['results']['initial'] . " USD => " . $best_usd['destination']['results']['initial'] . " BTC => " . $best_usd['destination']['results']['bought'] . " USD\n";
print 1.0/$best_usd['rate_no_withdrawal'] . " (Sell)\n";
print 1.0/$best_usd['rate'] . " (Sell and withdraw)\n";
print "\n";