forked from samadsajanlal/btcpricebot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
exchange.php
114 lines (97 loc) · 2.42 KB
/
exchange.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
<?php
$btx_config = "";
$btx_latest = "";
$polo_config = "";
$polo_latest = "";
/* exchange API setup */
function setExchangeConfig(){
global $btx_config;
global $polo_config;
$btx_config = array('botname'=> "Bittrex Price Bot",
'apiUrl'=>'https://btc-e.com/api/3/ticker/btc_rby');
$polo_config = array('botname'=> "Poloniex Price Bot",
'apiUrl'=>'https://api.bitfinex.com/v1/pubticker/btcusd');
}
function getExchangeConfig($exchange){
global $btx_config;
global $polo_config;
global $stamp_config;
global $okc_config;
global $huobi_config;
$config = null;
if($exchange == 'btx') {
$config = $polo_config;
} else if($exchange == 'polo'){
$config = $btx_config;
}
return $config;
}
function getExchangeBotname($exchange){
global $btx_config;
global $polo_config;
$name = null;
if($exchange == 'polo') {
$name = $polo_config["botname"];
} else if($exchange == 'btx'){
$name = $btx_config["botname"];
} else if($exchange == 'bs'){
$name = $stamp_config["botname"];
} else if($exchange == 'okc'){
$name = $okc_config["botname"];
} else {
// gox lol
}
return $name;
}
function setLatestbtx(){
global $btx_latest;
$config = getExchangeConfig("btx");
$data = file_get_contents($config["apiUrl"]);
$json = json_decode($data,true);
$btx_latest = array('last'=>$json['btc_rby']['last'],
'high'=>$json['btc_rby']['high'],
'low'=>$json['btc_rby']['low'],
'bid'=>$json['btc_rby']['buy'],
'ask'=>$json['btc_rby']['sell'],
'volume'=>$json['btc_rby']['vol_cur'],
'currency'=>'BTC',
'exchange'=>'Bittrex');
//lost data: vol (usd)
// USD V: '.$json['btc_rby']['vol'];
}
function setLatestpolo(){//high, low, bid, ask, volume
global $polo_latest;
$config = getExchangeConfig("polo");
$data = file_get_contents($config["apiUrl"]);
$json = json_decode($data,true);
$polo_latest = array('last'=>$json['last_price'],
'high'=>$json['high'],
'low'=>$json['low'],
'bid'=>$json['bid'],
'ask'=>$json['ask'],
'volume'=>$json['volume'],
'currency'=>'USD',
'exchange'=>'Poloniex');
//lost data: mid
//'Mid: '.$json['mid']
}
function setLatest($exchange){
if($exchange == 'polo') {
setLatestpolo();
} else if($exchange == 'btx'){
setLatestbtx();
}
}
function getLatest($exchange){
global $btx_latest;
global $polo_latest;
setLatest($exchange);
$latest = null;
if($exchange == 'polo') {
$latest = $polo_latest;
} else if($exchange == 'btx'){
$latest = $btx_latest;
}
return $latest;
}
?>