exchange.GetPosition() Use the caution to determine whether or not it is an empty array

Author: sunsjk, Created: 2018-11-07 08:17:28, Updated: 2019-04-17 15:52:12

    exchange.SetTimeout(3000);
    exchange.SetContractType("XBTUSD");

    //取得第一次币量
    position = _C(exchange.GetPosition);
    last_Amount = position[0].Amount; //持币数量  
    hold_price = Math.round(position[0].Price); //持币均价
    
    
    TypeError: cannot read property 'Amount' of undefined at main (__FILE__:38)

Related

More

sunsjkvar position = _C (exchange.GetPosition); Log (("the actual content of the holding array", position); var len = position.length; // take the length of the array var Log (("length of the stored array", len); The result is len: empty is 0, empty is 1. So let's take the length of the array, how is it 1, not the other numbers? Thank you, little dream.

The Little DreamGetPosition returns a holding array, if no holding is returned [], an empty array, if no holding is returned, the next code is called position[0].Amount will definitely return an error, because position[0] does not exist. This is something that your tactics have not handled.