Issue where looking at Result.Position after creating an order is null?
Issue where looking at Result.Position after creating an order is null?
12 Apr 2022, 03:10
I'm doing something where I have a List<Position>, and when an order executes I'm adding it to this list:
However, result.Position is Null in this case, I figure it may be something to do with asynchronous code, or delays. But not sure I understand exactly as I am not using ExecuteMarketOrderAysnc.
When I tried to use ExecuteMarketOrderAysnc, with await, I got an error and looking up other threads here it seems that calgo does not support async/await type logic.
Can someone shed some light on why the Result.Position is null, causing the algo to:
When it tries to access the element in the list expecting a Position but finding null instead?
amusleh
12 Apr 2022, 10:16
Hi,
After you call execute market order method you should check result.IsSuccessful property before trying to access the Position property of result, example:
The above code is the right way for using result of an ExecuteMarketOrder non async call.
In case you just want to store a position on a collection when it opens you can use Positions.Opened event, example:
For ExecuteMarketOrderAsync you should use the callback delegate:
@amusleh