@@ -44,9 +44,13 @@ public function getApi($url, $target, $auth=NULL) {
4444 curl_setopt ($ ch , CURLOPT_CONNECTTIMEOUT , 30 );
4545 curl_setopt ($ ch , CURLOPT_TIMEOUT , 30 );
4646 curl_setopt ($ ch , CURLOPT_RETURNTRANSFER , true );
47+ curl_setopt ($ ch , CURLOPT_FOLLOWLOCATION , true );
4748 curl_setopt ($ ch , CURLOPT_USERAGENT , 'Mozilla/4.0 (compatible; PHP client; ' .php_uname ('s ' ).'; PHP/ ' .phpversion ().') ' );
4849 }
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 );
5054 // curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
5155
5256 curl_setopt ($ ch , CURLOPT_SSL_VERIFYPEER , FALSE );
@@ -72,11 +76,9 @@ public function getApi($url, $target, $auth=NULL) {
7276 **/
7377 private function getApiType ($ url ) {
7478 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 )) {
7781 return 'btce ' ;
78- } else if (preg_match ('/cryptsy.com/ ' , $ url )) {
79- return 'cryptsy ' ;
8082 } else if (preg_match ('/cryptopia.co.nz/ ' , $ url )) {
8183 return 'cryptopia ' ;
8284 } else if (preg_match ('/cryptorush.in/ ' , $ url )) {
@@ -87,6 +89,18 @@ private function getApiType($url) {
8789 return 'c-cex ' ;
8890 } else if (preg_match ('/bittrex.com/ ' , $ url )) {
8991 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 ' ;
90104 }
91105 $ this ->setErrorMessage ("API URL unknown " );
92106 return false ;
@@ -97,30 +111,28 @@ private function getApiType($url) {
97111 **/
98112 public function getPrice () {
99113 $ 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 ' ];
101116 // Check the API type for configured URL
102117 if (!$ strApiType = $ this ->getApiType ($ this ->config ['price ' ]['url ' ]))
103118 return false ;
104119 // if api data is valid, extract price depending on API type
105120 if (is_array ($ aData )) {
106121 switch ($ strApiType ) {
107- case 'coinchose ' :
122+ case 'coinchoose ' :
108123 foreach ($ aData as $ aItem ) {
109- if ($ strCurrency == $ aItem [0 ])
124+ if ($ strBase == $ aItem [0 ])
110125 return $ aItem ['price ' ];
111126 }
112127 break ;
113128 case 'btce ' :
114129 return $ aData ['ticker ' ]['last ' ];
115130 break ;
116- case 'cryptsy ' :
117- return @$ aData ['return ' ]['markets ' ][$ strCurrency ]['lasttradeprice ' ];
118- break ;
119131 case 'cryptopia ' :
120132 return @$ aData ['Data ' ]['LastPrice ' ];
121133 break ;
122134 case 'cryptorush ' :
123- return @$ aData ["$ strCurrency / " . $ this -> config [ ' price ' ][ ' currency ' ] ]['last_trade ' ];
135+ return @$ aData ["{ $ strBase } / { $ strQuote }" ]['last_trade ' ];
124136 break ;
125137 case 'mintpal ' :
126138 return @$ aData ['0 ' ]['last_price ' ];
@@ -131,6 +143,26 @@ public function getPrice() {
131143 case 'bittrex ' :
132144 return @$ aData ['result ' ]['Last ' ];
133145 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 ;
134166 }
135167 } else {
136168 $ this ->setErrorMessage ("Got an invalid response from ticker API " );
0 commit comments