retrieve data at a specific snap time (follow up)

Hi,
I need to save live RIC values at a very specific snap time. I've got
a list of RICs on different feeds, I realized (am I right ?) that the
best solution is to group these RICs by feed and setup a data request
for each feed.
Here is the code I'm using: (repoDico is my RICs/Fields/Feeds Dictionary)
I'm using ThomsonReuters.Desktop.SDK.DataAccess.Realtime
Can you please have a look and correct what seems wrong to you.
public void Flash(Dictionary<string, ReutersFlashObject> repoDico)
{
_flashed = new Dictionary<string, double>();
List<string> feeds;
List<string> fields;
List<string> rics;
var realtime = services.Realtime;
feeds = repoDico.Values.Select(x => x.source).Distinct().ToList();
for (int i = 0; i < feeds.Count; i++)
{
fields = repoDico.Values.Where(x => x.source == feeds[i]).Select(x => x.field).Distinct().ToList();
rics = repoDico.Values.Where(x => x.source == feeds[i]).Select(x => x.ric).Distinct().ToList();
request = realtime.SetupDataRequest()
.WithRics(rics)
.WithFields(fields)
.WithFeed((feeds[i] == "IDN") ? "" : feeds[i])
.OnError(RealTimeDataError)
.OnDataReceived(update => DataReceivedCallback(feeds[i], update))
.OnStatusReceived(StatusReceived)
.CreateAndSend();
subscription = realtime.SetupDataSubscription()
.WithRics(rics)
.WithFields(fields)
.WithFeed((feeds[i] == "IDN") ? "" : feeds[i])
.OnError(RealTimeDataError)
.OnDataUpdated(update => DataReceivedCallback(feeds[i], update))
.OnStatusUpdated(StatusReceived)
.CreateAndStart();
PushFrame();
}
}
private void DataReceivedCallback(string feed, IRealtimeUpdateDictionary updates)
{
string ric = "", field = "";
for (int i = 0; i < updates.Keys.Count; i++)
{
ric = updates.Keys.ElementAt(i);
for (int j = 0; j < updates[ric].Keys.Count; j++)
{
//Save the data somewhere
}
}
Dispatcher.CurrentDispatcher.BeginInvoke(new DispatcherOperationCallback(StopFrame), DispatcherPriority.Background, frame);
}
private static void PushFrame()
{
Dispatcher.ExitAllFrames();
frame = new DispatcherFrame();
Dispatcher.PushFrame(frame);
}
private static object StopFrame(object f)
{
((DispatcherFrame)f).Continue = false;
Best Answer
-
From the snippet code, the frame has been stopped after the DataReceivedCallback function is called. From my test, the DataReceivedCallback function may be called multiple times for each request. For example, if the application specifies three RICs in the request, the DataReceivedCallback function can be called twice.
The best practice is that the frame shouldn't be stopped. It should be dispatched forever until the application exits.
Can you share the full code so I can modify and test it in my environment?
0
Answers
-
is there a reason you use the subscription object along side the request object? Subscription will send you subsequent updates, while the request just makes a snapshot of the requested data.
0 -
Hi Zhenya,
Thanks for your quick answer. I've already submitted this before and I was told to do so. Let me try not to subscribe and get back to you.
Mohammed
0 -
Hi again Zhenya,
I'm using only the request object now. I'm still having trouble and I think it comes from the way i'm using the Dispatcher to catch all the updates.
Can you please send me an example of a good practice for a snap.Thanks
Mohammed0 -
#region Dispatcher
private static void PushFrame()
{
DispatcherFrame frame = new DispatcherFrame();
Dispatcher.CurrentDispatcher.BeginInvoke(new DispatcherOperationCallback(StopFrame), DispatcherPriority.Background, frame);
Dispatcher.PushFrame(frame);
}
private static object StopFrame(object f)
{
((DispatcherFrame)f).Continue = false;
return null;
}
#endregion
#region RealTime Events
private void DataReceivedCallback(string feed, string ric, int expectedDataCount, IRealtimeUpdateDictionary updates)
{
foreach (string ricKey in updates.Keys)
{
foreach (string field in updates[ricKey].Keys)
{
if (!_flashed.ContainsKey(ReutersFlashObject.GetKey(feed, ricKey, field)))
{
_flashed.Add(ReutersFlashObject.GetKey(feed, ricKey, field), updates[ricKey][field].Value.ToDouble());
_flashedTime.Add(ReutersFlashObject.GetKey(feed, ricKey, field), DateTime.Now);
}
else
{
Logger.Instance.Log("We have it already: " + ReutersFlashObject.GetKey(feed, ricKey, field));
}
}
}
}
private void RealTimeDataError(RealtimeDataError error)
{
Logger.Instance.Log(error.Message, Logger.LogType.Fatal);
}
private void StatusReceived(InstrumentStateUpdate statusUpdate)
{
Logger.Instance.Log("status update on " + statusUpdate.Ric + ": " + statusUpdate.InstrumentState);
}
#endregion
public void Flash(Dictionary<string, ReutersFlashObject> repoDico)
{
_flashed = new Dictionary<string, double>();
_flashedTime = new Dictionary<string, DateTime>();
List<string> feeds;
List<string> fields;
List<string> rics;
var realtime = services.Realtime;
feeds = repoDico.Values.Select(x => x.source).Distinct().ToList();
for (int i = 0; i < feeds.Count; i++)
{
rics = repoDico.Values.Where(x => x.source == feeds[i]).Select(x => x.ric).Distinct().ToList();
for (int j = 0; j < rics.Count; j++)
{
fields = repoDico.Values.Where(x => x.source == feeds[i] && x.ric == rics[j]).Select(x => x.field).Distinct().ToList();
//Logger.Instance.Log("request on " + feeds[i] + ";" + rics[j]);
request = realtime.SetupDataRequest()
.WithRics(rics[j])
.WithFields(fields)
.WithFeed((feeds[i] == "IDN") ? "" : feeds[i])
.OnError(RealTimeDataError)
.OnDataReceived(update => DataReceivedCallback(feeds[i],rics[j], fields.Count, update))
.OnStatusReceived(StatusReceived)
.CreateAndSend();
PushFrame();
}
}
//for (int i = 0; i < feeds.Count; i++)
//{
// fields = repoDico.Values.Where(x => x.source == feeds[i]).Select(x => x.field).Distinct().ToList();
// rics = repoDico.Values.Where(x => x.source == feeds[i]).Select(x => x.ric).Distinct().ToList();
// request = realtime.SetupDataRequest()
// .WithRics(rics)
// .WithFields(fields)
// .WithFeed((feeds[i] == "IDN") ? "" : feeds[i])
// .OnError(RealTimeDataError)
// .OnDataReceived(update => DataReceivedCallback(feeds[i], repoDico.Values.Where(x => x.source == feeds[i]).Count(), update))
// .OnStatusReceived(StatusReceived)
// .CreateAndSend();
// //subscription = realtime.SetupDataSubscription()
// // .WithRics(rics)
// // .WithFields(fields)
// // .WithFeed((feeds[i] == "IDN") ? "" : feeds[i])
// // .OnError(RealTimeDataError)
// // .OnDataUpdated(update => DataReceivedCallback(feeds[i], update))
// // .OnStatusUpdated(StatusReceived)
// // .CreateAndStart();
// PushFrame();
//}
Dispatcher.ExitAllFrames();
}0 -
My code is programcs.txt.
0
Categories
- All Categories
- 3 Polls
- 6 AHS
- 36 Alpha
- 166 App Studio
- 6 Block Chain
- 4 Bot Platform
- 18 Connected Risk APIs
- 47 Data Fusion
- 34 Data Model Discovery
- 687 Datastream
- 1.4K DSS
- 622 Eikon COM
- 5.2K Eikon Data APIs
- 10 Electronic Trading
- Generic FIX
- 7 Local Bank Node API
- 3 Trading API
- 2.9K Elektron
- 1.4K EMA
- 254 ETA
- 557 WebSocket API
- 38 FX Venues
- 14 FX Market Data
- 1 FX Post Trade
- 1 FX Trading - Matching
- 12 FX Trading – RFQ Maker
- 5 Intelligent Tagging
- 2 Legal One
- 23 Messenger Bot
- 3 Messenger Side by Side
- 9 ONESOURCE
- 7 Indirect Tax
- 60 Open Calais
- 276 Open PermID
- 44 Entity Search
- 2 Org ID
- 1 PAM
- PAM - Logging
- 6 Product Insight
- Project Tracking
- ProView
- ProView Internal
- 22 RDMS
- 1.9K Refinitiv Data Platform
- 673 Refinitiv Data Platform Libraries
- 4 LSEG Due Diligence
- LSEG Due Diligence Portal API
- 4 Refinitiv Due Dilligence Centre
- Rose's Space
- 1.2K Screening
- 18 Qual-ID API
- 13 Screening Deployed
- 23 Screening Online
- 12 World-Check Customer Risk Screener
- 1K World-Check One
- 46 World-Check One Zero Footprint
- 45 Side by Side Integration API
- 2 Test Space
- 3 Thomson One Smart
- 10 TR Knowledge Graph
- 151 Transactions
- 143 REDI API
- 1.8K TREP APIs
- 4 CAT
- 27 DACS Station
- 121 Open DACS
- 1.1K RFA
- 104 UPA
- 193 TREP Infrastructure
- 229 TRKD
- 918 TRTH
- 5 Velocity Analytics
- 9 Wealth Management Web Services
- 90 Workspace SDK
- 11 Element Framework
- 5 Grid
- 18 World-Check Data File
- 1 Yield Book Analytics
- 48 中文论坛