1

I am trying to get the value for 'Limit' from a returned stdClass array. I get nothing but invalid access error. Invalid object, invalid array offset

Below are 2 separate attempts

code:

function callbittrex($url, $flags, $apikey, $apisecret){
        $nonce=time();
        if($flags == 0){
                $uri = $url.'?apikey='.$apikey.'&nonce='.$nonce;
        }
        if($flags == 1){
                $uri = $url;
        }
        $sign=hash_hmac('sha512',$uri,$apisecret);
        $ch = curl_init($uri);
        curl_setopt($ch, CURLOPT_HTTPHEADER, array('apisign:'.$sign));
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        $execResult = curl_exec($ch);
        curl_close($ch);
        $obj = json_decode($execResult);
        return $obj;

}
$flags = 0;
$url='https://bittrex.com/api/v1.1/market/getopenorders';
$myobj = callbittrex($url, $flags, $apikey, $apisecret);
echo $myobj->result['0']->Limit;

error:

PHP Notice:  Undefined property: stdClass::$result in /home/buycoinz.php on line 31

Notice: Undefined property: stdClass::$result in /home/buycoinz.php on line 31
PHP Notice:  Trying to get property of non-object in /home/buycoinz.php on line 31

Notice: Trying to get property of non-object in /home/buycoinz.php on line 31

update: spelling error 'result' corrected.

return data:

stdClass::__set_state(array(
   'success' => true,
   'message' => '',
   'result' => 
  array (
    0 => 
    stdClass::__set_state(array(
       'Uuid' => NULL,
       'OrderUuid' => 'd880ed74-9da8-4725-8b4d-a02daa2d3a66',
       'Exchange' => 'BTC-EXP',
       'OrderType' => 'LIMIT_BUY',
       'Quantity' => 2,
       'QuantityRemaining' => 2,
       'Limit' => 0.00053649999999999998,
       'CommissionPaid' => 0,
       'Price' => 0,
       'PricePerUnit' => NULL,
       'Opened' => '2016-07-06T12:12:37.377',
       'Closed' => NULL,
       'CancelInitiated' => false,
       'ImmediateOrCancel' => false,
       'IsConditional' => false,
       'Condition' => 'NONE',
       'ConditionTarget' => NULL,
    )),
    1 => 
    stdClass::__set_state(array(
       'Uuid' => NULL,
       'OrderUuid' => '968bdd76-5cb2-4f80-9126-bc8fe6414e8a',
       'Exchange' => 'BTC-EXP',
       'OrderType' => 'LIMIT_BUY',
       'Quantity' => 2,
       'QuantityRemaining' => 2,
       'Limit' => 0.00050000000000000001,
       'CommissionPaid' => 0,
       'Price' => 0,
       'PricePerUnit' => NULL,
       'Opened' => '2016-07-06T12:14:47.91',
       'Closed' => NULL,
       'CancelInitiated' => false,
       'ImmediateOrCancel' => false,
       'IsConditional' => false,
       'Condition' => 'NONE',
       'ConditionTarget' => NULL,
    )),
  ),
))

second attempt:

code:

function callbittrex($url, $flags, $apikey, $apisecret){
        $nonce=time();
        if($flags == 0){
                $uri = $url.'?apikey='.$apikey.'&nonce='.$nonce;
        }
        if($flags == 1){
                $uri = $url;
        }
        $sign=hash_hmac('sha512',$uri,$apisecret);
        $ch = curl_init($uri);
        curl_setopt($ch, CURLOPT_HTTPHEADER, array('apisign:'.$sign));
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        $execResult = curl_exec($ch);
        curl_close($ch);
        $obj = json_decode($execResult, true);
        return $obj;

}
$flags = 0;

$url='https://bittrex.com/api/v1.1/market/getopenorders';
$myobj = callbittrex($url, $flags, $apikey, $apisecret);
foreach ($myobj as $dirobj){
        var_dump( $dirobj['array'][0] );
                //echo $dirobj['Limit'];
}

error:

NULL
PHP Warning:  Illegal string offset 'array' in /home/buycoinz.php on line 31

Warning: Illegal string offset 'array' in /home/buycoinz.php on line 31
PHP Notice:  Uninitialized string offset: 0 in /home/buycoinz.php on line 31

output following foreach() loop, stdClass array appears disabled:

bool(true)
string(0) ""
array(2) {
  [0]=>
  array(17) {
    ["Uuid"]=>
    NULL
    ["OrderUuid"]=>
    string(36) "d880ed74-9da8-4725-8b4d-a02daa2d3a66"
    ["Exchange"]=>
    string(7) "BTC-EXP"
    ["OrderType"]=>
    string(9) "LIMIT_BUY"
    ["Quantity"]=>
    float(2)
    ["QuantityRemaining"]=>
    float(2)
    ["Limit"]=>
    float(0.0005365)
    ["CommissionPaid"]=>
    float(0)
    ["Price"]=>
    float(0)
    ["PricePerUnit"]=>
    NULL
    ["Opened"]=>
    string(23) "2016-07-06T12:12:37.377"
    ["Closed"]=>
    NULL
    ["CancelInitiated"]=>
    bool(false)
    ["ImmediateOrCancel"]=>
    bool(false)
    ["IsConditional"]=>
    bool(false)
    ["Condition"]=>
    string(4) "NONE"
    ["ConditionTarget"]=>
    NULL
  }
  [1]=>
  array(17) {
    ["Uuid"]=>
    NULL
    ["OrderUuid"]=>
    string(36) "968bdd76-5cb2-4f80-9126-bc8fe6414e8a"
    ["Exchange"]=>
    string(7) "BTC-EXP"
    ["OrderType"]=>
    string(9) "LIMIT_BUY"
    ["Quantity"]=>
    float(2)
    ["QuantityRemaining"]=>
    float(2)
    ["Limit"]=>
    float(0.0005)
    ["CommissionPaid"]=>
    float(0)
    ["Price"]=>
    float(0)
    ["PricePerUnit"]=>
    NULL
    ["Opened"]=>
    string(22) "2016-07-06T12:14:47.91"
    ["Closed"]=>
    NULL
    ["CancelInitiated"]=>
    bool(false)
    ["ImmediateOrCancel"]=>
    bool(false)
    ["IsConditional"]=>
    bool(false)
    ["Condition"]=>
    string(4) "NONE"
    ["ConditionTarget"]=>
    NULL
  }
}

How do I access the value for 'Limit' in this stdClass array?

1 Answer 1

0

In first attempt, you are trying to get results instead of result.

In second attempt (when you actually return array, not stdClass) you can get result of request simply put:

$result = callbittrex($url, $flags, $apikey, $apisecret)['result'];
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.