A related question. I monitor 56 Forex currency pairs (the 28 majors for Ask and Bid). I submit those 56 BarsRequests at the same time. What is the most efficient way to issue those 56 BarsRequests so they have minimal effect on the UI performance? At first, I noticed a dramatic impact on UI refresh, to the point of NT actually freezing for several seconds. I now stage their submission to 5 at a time every 2 seconds (for want of a protocol), and have added an async approach. I currently do the following for each BarsRequest (still using the default MarketDataType, but soon to use Ask and then Bid)
internal async Task DoBarsRequestAsync(Instrument pInstrument)
{
try
{
if (pInstrument == null)
return;
TheBarsRequest = new BarsRequest(pInstrument,1); // Only need the latest bar
TheBarsRequest.BarsPeriod = new BarsPeriod { BarsPeriodType = BarsPeriodType.Minute, Value = 1 }; // 1 Minute
TheBarsRequest.TradingHours = TradingHours.Get("Default 24 x 7");
TheBarsRequest.Update += OnBarUpdate;
TheBarsRequest.Request(new Action<BarsRequest,ErrorCode,string>((bars, errorCode, errorMessage) =>
{
{
if (errorCode != ErrorCode.NoError)
{
Print("Error on requesting bars: " + errorCode + ", " + errorMessage);
return;
}
bool connected = false;
// Requesting real-time bars requires a current connection
lock (Connection.Connections)
connected = Connection.Connections.FirstOrDefault() != null;
if (!connected)
{
Print("No Connections!");
return;
}
}
}));
}
catch (Exception oops)
{
Print("EXCEPTION: " + oops.ToString());
return;
}
}
Dispatcher.InvokeAsync(new Action(() =>
{
SubmitTheBarsRequests();
}),DispatcherPriority.Loaded,CancelActionToken); // Lessen impact on rendering
Thanks.

Comment