Reading Async trades after execution

Created at 14 Nov 2019, 07:59
How’s your experience with the cTrader Platform?
Your feedback is crucial to cTrader's development. Please take a few seconds to share your opinion and help us improve your trading experience. Thanks!
EO

eofe

Joined 18.06.2019

Reading Async trades after execution
14 Nov 2019, 07:59


Hi,

When I run the code below, ReadMyTrades() does not print anything.

Could async experts provide some guidence on what can I do to read my trades after Async execution please?

         protected override void OnStart()
        {
            ExecuteMyOrder();
            ReadMyTrades();
        }

        private void ExecuteMyOrder()
        {
            for (int i = 1; i <= 5; i++)
            {
                ExecuteMarketOrderAsync(TradeType.Buy, Symbol.Name, Symbol.QuantityToVolumeInUnits(i));
            }
        }

        private void ReadMyTrades()
        {
            foreach (var position in Positions)
            {
                Print(position.Id);
            }
        }


@eofe
Replies

PanagiotisCharalampous
14 Nov 2019, 08:29

Hi eofe,

This happens because you execute the order asynchronously. ReadMyTrades() is executed before the position opens.

Best Regards,

Panagiotis


@PanagiotisCharalampous

eofe
14 Nov 2019, 09:22

Thanks for your quick answer Panagiotis.

Could you give me some pointers as to how would you structure the code so readmytrades() will work as intended please?


@eofe