@@ -44,9 +44,13 @@ public function getApi($url, $target, $auth=NULL) {
44
44
curl_setopt ($ ch , CURLOPT_CONNECTTIMEOUT , 30 );
45
45
curl_setopt ($ ch , CURLOPT_TIMEOUT , 30 );
46
46
curl_setopt ($ ch , CURLOPT_RETURNTRANSFER , true );
47
+ curl_setopt ($ ch , CURLOPT_FOLLOWLOCATION , true );
47
48
curl_setopt ($ ch , CURLOPT_USERAGENT , 'Mozilla/4.0 (compatible; PHP client; ' .php_uname ('s ' ).'; PHP/ ' .phpversion ().') ' );
48
49
}
49
- curl_setopt ($ ch , CURLOPT_URL , $ url . $ target );
50
+
51
+ $ url = rtrim ($ url , '/ ' );
52
+ $ target = ltrim ($ target , '/ ' );
53
+ curl_setopt ($ ch , CURLOPT_URL , $ url . '/ ' . $ target );
50
54
// curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
51
55
52
56
curl_setopt ($ ch , CURLOPT_SSL_VERIFYPEER , FALSE );
@@ -72,11 +76,9 @@ public function getApi($url, $target, $auth=NULL) {
72
76
**/
73
77
private function getApiType ($ url ) {
74
78
if (preg_match ('/coinchoose.com/ ' , $ url )) {
75
- return 'coinchose ' ;
76
- } else if (preg_match ('/btc-e.com / ' , $ url )) {
79
+ return 'coinchoose ' ;
80
+ } else if (preg_match ('/btc-e.nz / ' , $ url )) {
77
81
return 'btce ' ;
78
- } else if (preg_match ('/cryptsy.com/ ' , $ url )) {
79
- return 'cryptsy ' ;
80
82
} else if (preg_match ('/cryptopia.co.nz/ ' , $ url )) {
81
83
return 'cryptopia ' ;
82
84
} else if (preg_match ('/cryptorush.in/ ' , $ url )) {
@@ -87,6 +89,18 @@ private function getApiType($url) {
87
89
return 'c-cex ' ;
88
90
} else if (preg_match ('/bittrex.com/ ' , $ url )) {
89
91
return 'bittrex ' ;
92
+ } else if (preg_match ('/crypto-bridge.org/ ' , $ url )) {
93
+ return 'cryptobridge ' ;
94
+ } else if (preg_match ('/yobit.net/ ' , $ url )) {
95
+ return 'yobit ' ;
96
+ } else if (preg_match ('/binance.com/ ' , $ url )) {
97
+ return 'binance ' ;
98
+ } else if (preg_match ('/southxchange.com/ ' , $ url )) {
99
+ return 'southxchange ' ;
100
+ } else if (preg_match ('/mercatox.com/ ' , $ url )) {
101
+ return 'mercatox ' ;
102
+ } else if (preg_match ('/tradeogre.com/ ' , $ url )) {
103
+ return 'tradeogre ' ;
90
104
}
91
105
$ this ->setErrorMessage ("API URL unknown " );
92
106
return false ;
@@ -97,30 +111,28 @@ private function getApiType($url) {
97
111
**/
98
112
public function getPrice () {
99
113
$ aData = $ this ->getApi ($ this ->config ['price ' ]['url ' ], $ this ->config ['price ' ]['target ' ]);
100
- $ strCurrency = $ this ->config ['currency ' ];
114
+ $ strBase = $ this ->config ['currency ' ];
115
+ $ strQuote = $ this ->config ['price ' ]['currency ' ];
101
116
// Check the API type for configured URL
102
117
if (!$ strApiType = $ this ->getApiType ($ this ->config ['price ' ]['url ' ]))
103
118
return false ;
104
119
// if api data is valid, extract price depending on API type
105
120
if (is_array ($ aData )) {
106
121
switch ($ strApiType ) {
107
- case 'coinchose ' :
122
+ case 'coinchoose ' :
108
123
foreach ($ aData as $ aItem ) {
109
- if ($ strCurrency == $ aItem [0 ])
124
+ if ($ strBase == $ aItem [0 ])
110
125
return $ aItem ['price ' ];
111
126
}
112
127
break ;
113
128
case 'btce ' :
114
129
return $ aData ['ticker ' ]['last ' ];
115
130
break ;
116
- case 'cryptsy ' :
117
- return @$ aData ['return ' ]['markets ' ][$ strCurrency ]['lasttradeprice ' ];
118
- break ;
119
131
case 'cryptopia ' :
120
132
return @$ aData ['Data ' ]['LastPrice ' ];
121
133
break ;
122
134
case 'cryptorush ' :
123
- return @$ aData ["$ strCurrency / " . $ this -> config [ ' price ' ][ ' currency ' ] ]['last_trade ' ];
135
+ return @$ aData ["{ $ strBase } / { $ strQuote }" ]['last_trade ' ];
124
136
break ;
125
137
case 'mintpal ' :
126
138
return @$ aData ['0 ' ]['last_price ' ];
@@ -131,6 +143,26 @@ public function getPrice() {
131
143
case 'bittrex ' :
132
144
return @$ aData ['result ' ]['Last ' ];
133
145
break ;
146
+ case 'cryptobridge ' :
147
+ foreach ($ aData as $ aItem ) {
148
+ if ("{$ strBase }_ {$ strQuote }" == $ aItem ['id ' ])
149
+ return $ aItem ['last ' ];
150
+ }
151
+ case 'yobit ' :
152
+ return @$ aData [strtolower ($ strBase ) . "_ " . strtolower ($ strQuote )]['last ' ];
153
+ break ;
154
+ case 'binance ' :
155
+ return @$ aData ['price ' ];
156
+ break ;
157
+ case 'southxchange ' :
158
+ return @$ aData ['Last ' ];
159
+ break ;
160
+ case 'mercatox ' :
161
+ return @$ aData ['pairs ' ]["{$ strBase }_ {$ strQuote }" ]['last ' ];
162
+ break ;
163
+ case 'tradeogre ' :
164
+ return @$ aData ['price ' ];
165
+ break ;
134
166
}
135
167
} else {
136
168
$ this ->setErrorMessage ("Got an invalid response from ticker API " );
0 commit comments