forked from fedaykinofdune/CryptsyTools
/
tool.php
156 lines (153 loc) · 10 KB
/
tool.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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
<?php
/* Copyright (C) 2013 Johnny "usTrUcX" joaogarcia@gmail.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. */
include 'cryptsy.php';
function compareMarkets($id0, $id1, $id2){
$market_0=getTopOrders($id0);
$market_1=getTopOrders($id1);
$market_2=getTopOrders($id2);
if($market_0['buy_volume_total']<$market_1['sell_volume_total']&&$market_0['buy_volume']<
$market_2['sell_volume']){
//market 0
echo $market_0['market_name']." is the lower volume with: ".$market_0['buy_volume'].$market_0['market_name_primary']." .";
//first order
echo "<br>Trying ".$market_0['market_name']." order: Sell ".$market_0['buy_volume'].$market_0['market_name_primary']." for: ".$market_0['buy_price']." .";
$amount_to_sell=$market_0['buy_volume'];
$initial_investment=$amount_to_sell;
echo "<br>I can Sell: ".$amount_to_sell.$market_0['market_name_primary']." .";
$fee_calc=api_query("calculatefees", array("ordertype" => 'Sell', 'quantity' => $amount_to_sell, 'price' => $market_0['buy_price']));
$market_0_total=$fee_calc['return']['net'];
echo "<br>This sucker gave me only: ".$market_0_total.$market_0['market_name_secondary']." moving on.";
//second order
echo "<br>Trying ".$market_1['market_name']." order: Buy ".$market_0_total.$market_1['market_name_secondary']." worth of: ".$market_1['market_name_primary']." .";
$amount_to_buy=$market_0_total/$market_1['sell_price'];
$amount_to_buy=$amount_to_buy-($amount_to_buy*0.002);
echo "<br>I can Buy: ".$amount_to_buy.$market_1['market_name_primary']." .";
$fee_calc=api_query("calculatefees", array("ordertype" => 'Buy', 'quantity' => $amount_to_buy, 'price' => $market_1['sell_price']));
$market_1_total=$fee_calc['return']['net'];
echo "<br>This sucker charged me: ".$market_1_total.$market_1['market_name_secondary']." moving on.";
//third order
echo "<br>Trying ".$market_2['market_name']." order: Buy ".$amount_to_buy.$market_2['market_name_secondary']." worth of: ".$market_2['market_name_primary']." .";
$amount_to_buy=$amount_to_buy/$market_2['sell_price'];
$amount_to_buy=$amount_to_buy-($amount_to_buy*0.002);
echo "<br>I can Buy: ".$amount_to_buy.$market_2['market_name_primary']." .";
$fee_calc=api_query("calculatefees", array("ordertype" => 'Buy', 'quantity' => $amount_to_buy, 'price' => $market_2['sell_price']));
$market_2_total=$fee_calc['return']['net'];
echo "<br>This sucker charged me: ".$market_2_total.$market_2['market_name_secondary']." finished.";
echo "<br>I ended up with: ".$amount_to_buy.$market_2['market_name_primary']." from the starting: ".$initial_investment.$market_0['market_name_primary']." .";
if($initial_investment>$amount_to_buy){
echo "<br>Theres no profit here: ".($amount_to_buy-$initial_investment).$market_2['market_name_primary']." from the initial: ".$initial_investment.$market_0['market_name_primary']." .";
}else{
echo "<br>Theres ".($amount_to_buy-$initial_investment).$market_2['market_name_primary']." profit here from the initial: ".$initial_investment.$market_0['market_name_primary']." investment.";
}
}else if($market_1['sell_volume_total']<$market_0['buy_volume_total']&&$market_1['sell_volume']<$market_2['sell_volume_total']){
//market 1
echo $market_1['market_name']." is the lower volume with: ".$market_1['sell_volume_total'].$market_1['market_name_secondary']." .";
//first order
echo "<br>Trying ".$market_0['market_name']." order: Sell ".$market_1['sell_volume_total'].$market_1['market_name_secondary']." worth of: ".$market_0['market_name_primary']." .";
$amount_to_sell=$market_1['sell_volume_total']/$market_0['buy_price'];
$amount_to_sell=$amount_to_sell+($amount_to_sell*0.003);
$initial_investment=$amount_to_sell;
echo "<br>I can Sell: ".$amount_to_sell.$market_0['market_name_primary']." .";
$fee_calc=api_query("calculatefees", array("ordertype" => 'Sell', 'quantity' => $amount_to_sell, 'price' => $market_0['buy_price']));
$market_0_total=$fee_calc['return']['net'];
echo "<br>This sucker gave me only: ".$market_0_total.$market_0['market_name_secondary']." moving on.";
//second order
echo "<br>Trying ".$market_1['market_name']." order: Buy ".$market_0_total.$market_1['market_name_secondary']." worth of: ".$market_1['market_name_primary']." .";
$amount_to_buy=$market_0_total/$market_1['sell_price'];
$amount_to_buy=$amount_to_buy-($amount_to_buy*0.002);
echo "<br>I can Buy: ".$amount_to_buy.$market_1['market_name_primary']." .";
$fee_calc=api_query("calculatefees", array("ordertype" => 'Buy', 'quantity' => $amount_to_buy, 'price' => $market_1['sell_price']));
$market_1_total=$fee_calc['return']['net'];
echo "<br>This sucker charged me: ".$market_1_total.$market_1['market_name_secondary']." moving on.";
//third order
echo "<br>Trying ".$market_2['market_name']." order: Buy ".$amount_to_buy.$market_2['market_name_secondary']." worth of: ".$market_2['market_name_primary']." .";
$amount_to_buy=$amount_to_buy/$market_2['sell_price'];
$amount_to_buy=$amount_to_buy-($amount_to_buy*0.002);
echo "<br>I can Buy: ".$amount_to_buy.$market_2['market_name_primary']." .";
$fee_calc=api_query("calculatefees", array("ordertype" => 'Buy', 'quantity' => $amount_to_buy, 'price' => $market_2['sell_price']));
$market_2_total=$fee_calc['return']['net'];
echo "<br>This sucker charged me: ".$market_2_total.$market_2['market_name_secondary']." finished.";
echo "<br>I ended up with: ".$amount_to_buy.$market_2['market_name_primary']." from the starting: ".$initial_investment.$market_0['market_name_primary']." .";
if($initial_investment>$amount_to_buy){
echo "<br>Theres no profit here: ".($amount_to_buy-$initial_investment).$market_2['market_name_primary']." from the initial: ".$initial_investment.$market_0['market_name_primary']." .";
}else{
echo "<br>Theres ".($amount_to_buy-$initial_investment).$market_2['market_name_primary']." profit here from the initial: ".$initial_investment.$market_0['market_name_primary']." investment.";
}
}else if($market_2['sell_volume_total']<$market_1['sell_volume']&&$market_2['sell_volume']<$market_0['buy_volume']){
//market 2
echo $market_2['market_name']." is the lower volume with: ".$market_2['sell_volume'].$market_2['market_name_primary']." .";
//first order
$initial_investment=$market_2['sell_volume'];
echo "<br>Trying ".$market_0['market_name']." order: Sell ".$market_2['sell_volume'].$market_2['market_name_primary']." .";
$fee_calc=api_query("calculatefees", array("ordertype" => 'Sell', 'quantity' => $market_2['sell_volume'], 'price' => $market_0['buy_price']));
$market_0_total=$fee_calc['return']['net'];
echo "<br>This sucker gave me only: ".$market_0_total.$market_0['market_name_secondary']." moving on.";
//second order
echo "<br>Trying ".$market_1['market_name']." order: Buy ".$market_0_total.$market_1['market_name_secondary']." worth of: ".$market_1['market_name_primary']." .";
$amount_to_buy=$market_0_total/$market_1['sell_price'];
$amount_to_buy=$amount_to_buy-($amount_to_buy*0.002);
echo "<br>I can Buy: ".$amount_to_buy.$market_1['market_name_primary']." .";
$fee_calc=api_query("calculatefees", array("ordertype" => 'Buy', 'quantity' => $amount_to_buy, 'price' => $market_1['sell_price']));
$market_1_total=$fee_calc['return']['net'];
echo "<br>This sucker charged me: : ".$market_1_total.$market_1['market_name_primary']." moving on.";
//third order
echo "<br>Trying ".$market_2['market_name']." order: Buy ".$amount_to_buy.$market_2['market_name_secondary']." worth of: ".$market_2['market_name_primary']." .";
$amount_to_buy=$amount_to_buy/$market_2['sell_price'];
$amount_to_buy=$amount_to_buy-($amount_to_buy*0.002);
echo "<br>I ended up with: ".$amount_to_buy.$market_2['market_name_primary']." from the starting: ".$initial_investment.$market_0['market_name_primary']." .";
if($initial_investment>$amount_to_buy){
echo "<br>Theres no profit here: ".($amount_to_buy-$initial_investment).$market_2['market_name_primary']." from the initial: ".$initial_investment.$market_0['market_name_primary']." .";
}else{
echo "<br>Theres ".($amount_to_buy-$initial_investment).$market_2['market_name_primary']." profit here from the initial: ".$initial_investment.$market_0['market_name_primary']." investment.";
}
}
}
function getTopOrders($marketid){
//return top order and price for given market
$orders = array();
$result = api_query("marketorders", array("marketid" => $marketid));
$orders['market_name']=coinName($marketid);
$orders['market_name_primary']=coinPrimaryName($marketid);
$orders['market_name_secondary']=coinSecondaryName($marketid);
$orders['sell_price'] = $result['return']['sellorders'][0]['sellprice'];
$orders['sell_volume'] = $result['return']['sellorders'][0]['quantity'];
$orders['sell_volume_total'] = $result['return']['sellorders'][0]['total'];
$orders['buy_price'] = $result['return']['buyorders'][0]['buyprice'];
$orders['buy_volume'] = $result['return']['buyorders'][0]['quantity'];
$orders['buy_volume_total'] = $result['return']['buyorders'][0]['total'];
return $orders;
}
function coinName($id){
$markets = api_query("getmarkets");
foreach($markets["return"] as $market){
if($market["marketid"]==$id){
return $market["label"];
}
}
}
function coinPrimaryName($id){
$markets = api_query("getmarkets");
foreach($markets["return"] as $market){
if($market["marketid"]==$id){
return $market['primary_currency_code'];
}
}
}
function coinSecondaryName($id){
$markets = api_query("getmarkets");
foreach($markets["return"] as $market){
if($market["marketid"]==$id){
return $market['secondary_currency_code'];
}
}
}