[BUG] Historical trade registered after Position.Modified event
Created at 14 Jan 2019, 17:32
[BUG] Historical trade registered after Position.Modified event
14 Jan 2019, 17:32
Hi Spotware,
When a position is partially closed and triggers Position.Modified event it happens before historical trade is registered. You can see the sample below to reproduce the issue. Hope you can fix this as soon as possible.
using System.Linq; using System.Threading; using System.Threading.Tasks; using cAlgo.API; namespace cAlgo { [Robot(TimeZone = TimeZones.UTC, AccessRights = AccessRights.None)] public class BugDemonstration : Robot { protected override void OnStart() { // executes market order var marketOrder = ExecuteMarketOrder(TradeType.Buy, Symbol, Symbol.VolumeInUnitsMin * 2); if (marketOrder.IsSuccessful) { var position = marketOrder.Position; // closes half of the position var partialClose = position.ModifyVolume(position.VolumeInUnits / 2); if (partialClose.IsSuccessful) { // tries to find historical trade of partial close var historicalTrade = History.FirstOrDefault(trade => trade.PositionId == position.Id); // returns null, historical trade not found Print("Sync trade = {0}", historicalTrade); // async task trying every 50ms to find the trade var task = new Task(() => { while (historicalTrade == null) { Thread.Sleep(50); historicalTrade = History.FirstOrDefault(trade => trade.PositionId == position.Id); // when found if (historicalTrade != null) { BeginInvokeOnMainThread(() => { Print("Async trade = {0}", historicalTrade); ClosePosition(position); Stop(); }); } } }); task.Start(); } } } } }
Replies
PanagiotisCharalampous
24 Jan 2019, 10:37
Hi Jiri,
It is a known issue and will be fixed in one of the upcoming updates.
Best Regards,
Panagiotis
@PanagiotisCharalampous
whis.gg
24 Jan 2019, 01:52
Just a friendly follow-up, is this going to be fixed any time soon?
@whis.gg