-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbrl_plus_fee.php
85 lines (77 loc) · 3.29 KB
/
brl_plus_fee.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
<?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);
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];
}
function find_rate($exchange, $min, $max, $step=1, $oper = 'asks') {
$best_rate = 10e99;
$cmp = strcmp($oper, 'asks');
if ($cmp != 0) $best_rate = 1.0/$best_rate;
$best = array();
$currency_pair = array($exchange[2], 'BTC');
$book_from = $exchange[0];
$fee_from = $exchange[1];
for ($value = $min; $value <= $max; $value+=$step) {
$bought = getValueOrders($value, $currency_pair, $book_from, $fee_from, $oper);
$rate = $bought['initial'] / $bought['withdrawn'];
if ($bought !== false && $rate > 0) {
if ((($cmp == 0) && ($rate < $best_rate))
|| (($cmp != 0) && (1.0/$rate < 1.0/$best_rate))) {
$best = $bought;
$best_rate = $rate;
}
}
if ($bought === false) {
//print "Broken at $value\n";
break;
}
}
return array($best_rate, $best);
}
foreach ($brls as $brl) {
$ret = find_rate($brl, $value_min, $value_max, $value_step);
print $brl[3] . " => " . $ret[0] . " for " . $brl[2] . " " . $ret[1]['initial'] . "\n";
$ret = find_rate($brl, $value_min, $value_max, $value_step, 'bids');
print $brl[3] . " => " . $ret[0] . " for " . $brl[2] . " " . $ret[1]['initial'] . "\n";
}