33namespace Hitbtc ;
44
55use GuzzleHttp \Client as HttpClient ;
6+ use GuzzleHttp \Handler \CurlHandler ;
7+ use GuzzleHttp \HandlerStack ;
68use GuzzleHttp \Message \Response ;
79use Hitbtc \Exception \InvalidRequestException ;
810use Hitbtc \Exception \RejectException ;
@@ -45,11 +47,13 @@ public function __construct($publicKey, $secretKey, $demo = false)
4547 public function getHttpClient ()
4648 {
4749 if (!$ this ->httpClient ) {
50+ $ stack = HandlerStack::create ();
51+ $ stack ->push (new AuthMiddleware ($ this ->publicKey , $ this ->secretKey ));
52+
4853 $ this ->httpClient = new HttpClient ([
49- 'base_url ' => $ this ->host ,
54+ 'handler ' => $ stack ,
55+ 'base_uri ' => $ this ->host ,
5056 ]);
51- $ this ->httpClient ->getEmitter ()->attach (new AuthSubscriber ($ this ->publicKey , $ this ->secretKey ));
52-
5357 }
5458
5559 return $ this ->httpClient ;
@@ -69,7 +73,7 @@ public function newOrder(NewOrder $order)
6973 'body ' => $ order ->asArray (),
7074 'exceptions ' => false ,
7175 ));
72- $ document = $ response ->json ( );
76+ $ document = json_decode ( $ response ->getBody (), true );
7377
7478 if (isset ($ document ['ExecutionReport ' ])) {
7579 if ($ document ['ExecutionReport ' ]['execReportType ' ] == 'rejected ' ) {
@@ -105,7 +109,7 @@ public function cancelOrder(Order $order, $cancelRequestId = null)
105109 ),
106110 'exceptions ' => false ,
107111 ));
108- $ document = $ response ->json ( );
112+ $ document = json_decode ( $ response ->getBody (), true );
109113 if (isset ($ document ['ExecutionReport ' ])) {
110114 return new Order ($ document ['ExecutionReport ' ]);
111115 } elseif (isset ($ document ['CancelReject ' ])) {
@@ -127,7 +131,7 @@ public function getActiveOrders($symbols = null)
127131 $ params ['query ' ]['symbols ' ] = implode (', ' , (array ) $ symbols );
128132 }
129133 $ response = $ this ->getHttpClient ()->get ('/api/1/trading/orders/active ' , $ params );
130- $ document = $ response ->json ( );
134+ $ document = json_decode ( $ response ->getBody (), true );
131135 if (isset ($ document ['orders ' ])) {
132136 $ orders = [];
133137 foreach ($ document ['orders ' ] as $ orderData ) {
@@ -164,7 +168,7 @@ public function getRecentOrders($symbols = null, $sort = 'asc', $statuses = null
164168 }
165169
166170 $ response = $ this ->getHttpClient ()->get ('/api/1/trading/orders/recent ' , array ('query ' => $ query , 'exceptions ' => false ));
167- $ document = $ response ->json ( );
171+ $ document = json_decode ( $ response ->getBody (), true );
168172 if (isset ($ document ['orders ' ])) {
169173 $ orders = [];
170174 foreach ($ document ['orders ' ] as $ orderData ) {
@@ -208,7 +212,7 @@ public function getTrades($symbols = null, $by = 'trade_id', $sort = 'ask', $fro
208212 }
209213
210214 $ response = $ this ->getHttpClient ()->get ('/api/1/trading/trades ' , array ('query ' => $ query , 'exceptions ' => false ));
211- $ document = $ response ->json ( );
215+ $ document = json_decode ( $ response ->getBody (), true );
212216 if (isset ($ document ['trades ' ])) {
213217 $ trades = [];
214218 foreach ($ document ['trades ' ] as $ tradeData ) {
@@ -232,7 +236,7 @@ public function getTradesByOrder($clientOrderId)
232236 );
233237
234238 $ response = $ this ->getHttpClient ()->get ('/api/1/trading/trades/by/order ' , array ('query ' => $ query , 'exceptions ' => false ));
235- $ document = $ response ->json ( );
239+ $ document = json_decode ( $ response ->getBody (), true );
236240 if (isset ($ document ['trades ' ])) {
237241 $ trades = [];
238242 foreach ($ document ['trades ' ] as $ tradeData ) {
@@ -251,7 +255,7 @@ public function getTradesByOrder($clientOrderId)
251255 public function getBalanceTrading ()
252256 {
253257 $ response = $ this ->getHttpClient ()->get ('/api/1/trading/balance ' , array ('exceptions ' => false ));
254- $ document = $ response ->json ( );
258+ $ document = json_decode ( $ response ->getBody (), true );
255259 if (isset ($ document ['balance ' ])) {
256260 $ balances = [];
257261 foreach ($ document ['balance ' ] as $ balanceData ) {
@@ -270,7 +274,7 @@ public function getBalanceTrading()
270274 public function getBalanceMain ()
271275 {
272276 $ response = $ this ->getHttpClient ()->get ('/api/1/payment/balance ' , array ('exceptions ' => false ));
273- $ document = $ response ->json ( );
277+ $ document = json_decode ( $ response ->getBody (), true );
274278 if (isset ($ document ['balance ' ])) {
275279 $ balances = [];
276280 foreach ($ document ['balance ' ] as $ balanceData ) {
@@ -295,7 +299,7 @@ public function getPaymentAddress($currency, $new = false)
295299 } else {
296300 $ response = $ this ->getHttpClient ()->get ('/api/1/payment/address/ ' . $ currency , array ('exceptions ' => false ));
297301 }
298- $ document = $ response ->json ( );
302+ $ document = json_decode ( $ response ->getBody (), true );
299303 if (isset ($ document ['address ' ])) {
300304 return $ document ['address ' ];
301305 }
@@ -320,7 +324,7 @@ protected function _transferAmount($currency, $amount, $trading)
320324 ),
321325 'exceptions ' => false
322326 ));
323- $ document = $ response ->json ( );
327+ $ document = json_decode ( $ response ->getBody (), true );
324328 if (isset ($ document ['transaction ' ])) {
325329 return $ document ['transaction ' ];
326330 } elseif (isset ($ document ['message ' ])) {
@@ -376,7 +380,7 @@ public function payout($currency, $amount, $address, $paymentId = null)
376380 ),
377381 'exceptions ' => false
378382 ));
379- $ document = $ response ->json ( );
383+ $ document = json_decode ( $ response ->getBody (), true );
380384 if (isset ($ document ['transaction ' ])) {
381385 return $ document ['transaction ' ];
382386 } elseif (isset ($ document ['message ' ])) {
@@ -394,7 +398,7 @@ public function getTransactions($sort = 'asc', $offset = 0, $limit = 1000)
394398 );
395399
396400 $ response = $ this ->getHttpClient ()->get ('/api/1/payment/transactions ' , array ('query ' => $ query , 'exceptions ' => false ));
397- $ document = $ response ->json ( );
401+ $ document = json_decode ( $ response ->getBody (), true );
398402 if (isset ($ document ['transactions ' ])) {
399403 $ transactions = [];
400404 foreach ($ document ['transactions ' ] as $ txn ) {
0 commit comments