The resource loading... loading...

getposition This function returns an error without a position

Author: xiaoxiaolu, Created: 2018-04-12 16:36:42, Updated:

How do you debug this problem? Use the following code to get position information if there are no positions in the account while ((true) { This is a list of all the different ways Var position=_C (exchange.GetPosition) is credited in the database.

if ((position ==null) { Continue I'm not sure. type=position[0].Type If this is the case, then this is the case If (excell!==sellPrice) is equal to (excell!==sellPrice) Cancel Pending Orders exchange.SetDirection ((closebuy)) exchange.Sell ((sellPrice, position[0].Amount) is the name of the exchange. Exsell = sell price I'm not sure. I'm not sure. When the account has no position, getposition should be an empty array, so it executes the continue in the if statement to restart the loop, but the disk test still returns an error. TypeError: cannot read property Type of undefined at main (FILE:129)

I tried to change the condition in if, such as position[0]==null or typeof(position)==undefined, either of which didn't work or would execute the following type=position[0].The type bar returned an error.

How can this problem be solved?


More

xionglonghuiThe solution is as follows: This is a list of all the different ways Var Position is credited in the database. if ((position.length>0) {pos (192,210) } // Please put the code in this large parenthesis. The principle is as follows: first determine the length of the array returned by this holding function, if the length is greater than 0, it means that there is a holding information, you can not directly use null, undefine. Then you can access position[0] I'm not sure.

yumountI'm having the same problem, and I feel the need to set up an error tolerant function for exchange.GetPosition separately, otherwise the function is almost completely useless without holding. By the way, please ask the landlord how it was resolved.

Inventors quantify - small dreamsLooking at the post, I found the problem, when you call exchange.GetPosition (()) if you don't hold, it returns [], an empty array, which is not equal to null, which is your judgment. When position == is null, it is false, so it does not trigger continue, then you access position[0] The element does not exist, so it is undefine, then call his Type attribute and it returns an error.