@@ -3249,6 +3249,14 @@ public function ocoOrder(string $side, string $symbol, $quantity, $price, $stopp
3249
3249
public function avgPrice (string $ symbol )
3250
3250
{
3251
3251
$ ticker = $ this ->httpRequest ("v3/avgPrice " , "GET " , ["symbol " => $ symbol ]);
3252
+ if (is_array ($ ticker ) === false ) {
3253
+ echo "Error: unable to fetch avg price " . PHP_EOL ;
3254
+ $ ticker = [];
3255
+ }
3256
+ if (empty ($ ticker )) {
3257
+ echo "Error: avg price was empty " . PHP_EOL ;
3258
+ return null ;
3259
+ }
3252
3260
return $ ticker ['price ' ];
3253
3261
}
3254
3262
@@ -3320,11 +3328,12 @@ public function futuresTime()
3320
3328
public function futuresExchangeInfo ()
3321
3329
{
3322
3330
if (!$ this ->futuresExchangeInfo ) {
3323
- $ arr = array ();
3324
- $ arr ['symbols ' ] = array ();
3325
-
3326
3331
$ arr = $ this ->httpRequest ("v1/exchangeInfo " , "GET " , [ 'fapi ' => true ]);
3327
-
3332
+ if ((is_array ($ arr ) === false ) || empty ($ arr )) {
3333
+ echo "Error: unable to fetch futures exchange info " . PHP_EOL ;
3334
+ $ arr = array ();
3335
+ $ arr ['symbols ' ] = array ();
3336
+ }
3328
3337
$ this ->futuresExchangeInfo = $ arr ;
3329
3338
$ this ->futuresExchangeInfo ['symbols ' ] = null ;
3330
3339
@@ -3369,6 +3378,13 @@ public function futuresDepth(string $symbol, int $limit = null)
3369
3378
$ params ['limit ' ] = $ limit ;
3370
3379
}
3371
3380
$ json = $ this ->httpRequest ("v1/depth " , "GET " , $ params );
3381
+ if (is_array ($ json ) === false ) {
3382
+ echo "Error: unable to fetch futures depth " . PHP_EOL ;
3383
+ }
3384
+ if (empty ($ json )) {
3385
+ echo "Error: futures depth were empty " . PHP_EOL ;
3386
+ return [];
3387
+ }
3372
3388
if (isset ($ this ->info [$ symbol ]) === false ) {
3373
3389
$ this ->info [$ symbol ] = [];
3374
3390
$ this ->info [$ symbol ]['futures ' ] = [];
@@ -3801,7 +3817,8 @@ public function futuresPrice(string $symbol)
3801
3817
];
3802
3818
$ ticker = $ this ->httpRequest ("v1/ticker/price " , "GET " , $ parameters );
3803
3819
if (!isset ($ ticker ['price ' ])) {
3804
- throw new \Exception ("No price found for symbol $ symbol " );
3820
+ echo "Error: unable to fetch futures price for $ symbol " . PHP_EOL ;
3821
+ return null ;
3805
3822
}
3806
3823
return $ ticker ['price ' ];
3807
3824
}
@@ -3848,7 +3865,8 @@ public function futuresPriceV2(string $symbol)
3848
3865
];
3849
3866
$ ticker = $ this ->httpRequest ("v2/ticker/price " , "GET " , $ parameters );
3850
3867
if (!isset ($ ticker ['price ' ])) {
3851
- throw new \Exception ("No price found for symbol $ symbol " );
3868
+ echo "Error: unable to fetch futures price for $ symbol " . PHP_EOL ;
3869
+ return null ;
3852
3870
}
3853
3871
return $ ticker ['price ' ];
3854
3872
}
0 commit comments