-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrun.php
218 lines (186 loc) · 8.75 KB
/
run.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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
<?php
$cachetime = 300; //diferença entre o tempo atual e o tempo de ultima modificação dos arquivos de Cache (em segundos)
//puxa as exchanges
//braziliex
//$jsonbraziliex = file_get_contents("https://braziliex.com/api/v1/public/ticker/btc_brl"); //puxa os dados da api
//cache da API
$cache_braziliex = 'braziliex.cache';
if(file_exists($cache_braziliex)) {
if(time() - filemtime($cache_braziliex) > $cachetime) {
// too old , re-fetch
$cache = file_get_contents("https://braziliex.com/api/v1/public/ticker/btc_brl"); //Atualiza o Cache
file_put_contents($cache_braziliex, $cache);
$jsonbraziliex = file_get_contents($cache_braziliex);
} else {
$jsonbraziliex = file_get_contents($cache_braziliex);
}
} else {
// no cache, create one
$cache = file_get_contents("https://braziliex.com/api/v1/public/ticker/btc_brl"); //Cria o Cache
file_put_contents($cache_braziliex, $cache);
$jsonbraziliex = file_get_contents($cache_braziliex);
}
$databrzx = json_decode($jsonbraziliex, true); //decodifica os dados da api
$braziliex_price = $databrzx['last']; //seleciona um valor especifico da api
$braziliex_volume = $databrzx['baseVolume'];
//$braziliex_price = intval($braziliex_price); //transforma em numero
//$braziliex_volume = intval($braziliex_volume);
$varbraziliex = $braziliex_price * $braziliex_volume;
//bitcointrade
//$json_bitcointrade = file_get_contents("https://api.bitcointrade.com.br/v2/public/BRLBTC/ticker");
//cache da API
$cache_bitcointrade = 'bitcoinreade.cache';
if(file_exists($cache_bitcointrade)) {
if(time() - filemtime($cache_bitcointrade) > $cachetime) {
// too old , re-fetch
$cache = file_get_contents("https://api.bitcointrade.com.br/v2/public/BRLBTC/ticker"); //Atualiza o Cache
file_put_contents($cache_bitcointrade, $cache);
$json_bitcointrade = file_get_contents($cache_bitcointrade);
} else {
$json_bitcointrade = file_get_contents($cache_bitcointrade);
}
} else {
// no cache, create one
$cache = file_get_contents("https://api.bitcointrade.com.br/v2/public/BRLBTC/ticker"); //Cria o Cache
file_put_contents($cache_bitcointrade, $cache);
$json_bitcointrade = file_get_contents($cache_bitcointrade);
}
$data_bitcoin_trade = json_decode($json_bitcointrade, true);
$bitcointrade_price = $data_bitcoin_trade['data']['last'];
$bitcointrade_volume = $data_bitcoin_trade['data']['volume'];
//$bitcointrade_price = intval($bitcointrade_price);
//$bitcointrade_volume = intval($bitcointrade_volume);
$varbitcointrade = $bitcointrade_price * $bitcointrade_volume;
//walltime
//$json_walltime = file_get_contents("https://s3.amazonaws.com/data-production-walltime-info/production/dynamic/walltime-info.json");
//cache da API
$cache_walltime = 'walltime.cache';
if(file_exists($cache_walltime)) {
if(time() - filemtime($cache_walltime) > $cachetime) {
// too old , re-fetch
$cache = file_get_contents("https://s3.amazonaws.com/data-production-walltime-info/production/dynamic/walltime-info.json"); //Atualiza o Cache
file_put_contents($cache_walltime, $cache);
$json_walltime = file_get_contents("walltime.cache");
} else {
$json_walltime = file_get_contents("walltime.cache");
}
} else {
// no cache, create one
$cache = file_get_contents("https://s3.amazonaws.com/data-production-walltime-info/production/dynamic/walltime-info.json"); //Cria o Cache
file_put_contents($cache_walltime, $cache);
$json_walltime = file_get_contents("walltime.cache");
}
$datawalltime = json_decode($json_walltime, true);
$walltime_price = $datawalltime['BRL_XBT']['last_inexact'];
$walltime_volume = $datawalltime['BRL_XBT']['quote_volume24h_inexact'];
//$walltime_price = intval($walltime_price);
//$walltime_volume = intval($walltime_volume);
$varwalltime = $walltime_price * $walltime_volume;
//bitcointoyou
//$json_bitcointoyou = file_get_contents("https://www.bitcointoyou.com/api/ticker.aspx");
//cache da API
$cache_bitcointoyou = 'bitcointoyou.cache';
if(file_exists($cache_bitcointoyou)) {
if(time() - filemtime($cache_bitcointoyou) > $cachetime) {
// too old , re-fetch
$cache = file_get_contents("https://back.bitcointoyou.com/API/ticker?pair=BTC_BRLC"); //Atualiza o Cache
file_put_contents($cache_bitcointoyou, $cache);
$json_bitcointoyou = file_get_contents($cache_bitcointoyou);
} else {
$json_bitcointoyou = file_get_contents($cache_bitcointoyou);
}
} else {
// no cache, create one
$cache = file_get_contents("https://back.bitcointoyou.com/API/ticker?pair=BTC_BRLC"); //Cria o Cache
file_put_contents($cache_bitcointoyou, $cache);
$json_bitcointoyou = file_get_contents($cache_bitcointoyou);
}
$databitcointoyou = json_decode($json_bitcointoyou, true);
$bitcointoyou_price = $databitcointoyou['summary']['last'];
$bitcointoyou_volume = $databitcointoyou['summary']['amount'];
//$bitcointoyou_price = intval($bitcointoyou_price);
//$bitcointoyou_volume = intval($bitcointoyou_volume);
$varbitcointoyou = $bitcointoyou_price * $bitcointoyou_volume;
//mercadobitcoin
//$json_mercadobitcoin = file_get_contents("https://www.mercadobitcoin.net/api/btc/ticker/");
//cache da API
$cache_mercadobitcoin = 'mercadobitcoin.cache';
if(file_exists($cache_mercadobitcoin)) {
if(time() - filemtime($cache_mercadobitcoin) > $cachetime) {
// too old , re-fetch
$cache = file_get_contents("https://www.mercadobitcoin.net/api/btc/ticker/"); //Atualiza o Cache
file_put_contents($cache_mercadobitcoin, $cache);
$json_mercadobitcoin = file_get_contents($cache_mercadobitcoin);
} else {
$json_mercadobitcoin = file_get_contents($cache_mercadobitcoin);
}
} else {
// no cache, create one
$cache = file_get_contents("https://www.mercadobitcoin.net/api/btc/ticker/"); //Cria o Cache
file_put_contents($cache_mercadobitcoin, $cache);
$json_mercadobitcoin = file_get_contents($cache_mercadobitcoin);
}
$datamercadobitcoin = json_decode($json_mercadobitcoin, true);
$mercadobitcoin_price = $datamercadobitcoin['ticker']['last'];
$mercadobitcoin_volume = $datamercadobitcoin['ticker']['vol'];
//$mercadobitcoin_price = intval($mercadobitcoin_price);
//$mercadobitcoin_volume = intval($mercadobitcoin_volume);
$varmercadobitcoin = $mercadobitcoin_price * $mercadobitcoin_volume;
//NOVADAX
//Cache
$cache_novadax = 'novadax.cache';
if(file_exists('novadax.cache')) {
if(time() - filemtime($cache_novadax) > $cachetime) {
//valor antigo -> atualizar valor
$cache_novadax1 = file_get_contents('https://api.novadax.com/v1/market/ticker?symbol=BTC_BRL');
file_put_contents($cache_novadax, $cache_novadax1);
$json_novadax = file_get_contents($cache_novadax);
} else {
$json_novadax = file_get_contents($cache_novadax);
}
} else {
//sem arquivo de cache -> criar
$cache_novadax1 = file_get_contents('https://api.novadax.com/v1/market/ticker?symbol=BTC_BRL');
file_put_contents($cache_novadax, $cache_novadax1);
$json_novadax = file_get_contents($cache_novadax);
}
$datanovadax = json_decode($json_novadax, true);
$novadax_price = $datanovadax['data']['lastPrice'];
$novadax_quote = $datanovadax['data']['quoteVolume24h'];
$novadax_volume = $novadax_quote / $novadax_price;
$varnovadax = $novadax_price * $novadax_volume;
//Calcula o preco medio ponderado
$allvariables = $varbraziliex + $varbitcointrade + $varwalltime + $varbitcointoyou + $varmercadobitcoin + $varnovadax; //soma todas as variaveis
$volumetotal = $braziliex_volume + $bitcointrade_volume + $walltime_volume + $bitcointoyou_volume + $mercadobitcoin_volume + $novadax_volume; //soma todos os volumes
$volumetotal = round($volumetotal, 8); //Bitcoin tem 8 casas decimais
$preco_ponderado = $allvariables / $volumetotal; //calcula o preco medio ponderado
//$preco_ponderado = intval($preco_ponderado); //transforma em numero
//Calcula o MarketShare
$pbraziliex = round(($braziliex_volume/$volumetotal)*100, 2);
$pbitcointrade = round(($bitcointrade_volume/$volumetotal)*100, 2);
$pwalltime = round(($walltime_volume/$volumetotal)*100, 2);
$pbitcointoyou = round(($bitcointoyou_volume/$volumetotal)*100, 2);
$pmercadobitcoin = round(($mercadobitcoin_volume/$volumetotal)*100, 2);
$pnovadax = round(($novadax_volume/$volumetotal)*100, 2);
//puxa a data e hora do servidor
//isso mostra em que data estão os valores, para evitar equívocos com o cache
date_default_timezone_set('America/Sao_Paulo');
//$date = date('Y-m-d H:i');
//cache da API
$cache_data = 'data2.cache';
if(file_exists($cache_data)) {
if(time() - filemtime($cache_data) > $cachetime) {
// too old , re-fetch
$cache = date('Y-m-d H:i'); //Atualiza o Cache
file_put_contents($cache_data, $cache);
$date = file_get_contents($cache_data);
} else {
$date = file_get_contents($cache_data);
}
} else {
// no cache, create one
$cache = date('Y-m-d H:i'); //Cria o Cache
file_put_contents($cache_data, $cache);
$date = file_get_contents($cache_data);
}
?>