public async Task OpenItemAsync(string item, Refinitiv.DataPlatform.Core.ISession RdpSession, Type modelType)
        {
            var fieldnameList = modelType.GetProperties()
                                .SelectMany(p => p.GetCustomAttributes(typeof(JsonPropertyAttribute))
                                            .Cast <JsonPropertyAttribute>())
                                .Select(prop => prop.PropertyName)
                                .ToArray();

            if (RdpSession != null)
            {
                await Task.Run(() =>
                {
                    ItemStream.Params itemParams;
                    if (!fieldnameList.Any())
                    {
                        // First, prepare our item stream details including the fields of interest and where to capture events...
                        itemParams = new ItemStream.Params().Session(RdpSession)
                                     .OnRefresh(processOnRefresh)
                                     .OnUpdate(processOnUpdate)
                                     .OnStatus(processOnStatus);
                    }
                    else
                    {
                        // First, prepare our item stream details including the fields of interest and where to capture events...
                        itemParams = new ItemStream.Params().Session(RdpSession)
                                     .WithFields(fieldnameList)
                                     .OnRefresh(processOnRefresh)
                                     .OnUpdate(processOnUpdate)
                                     .OnStatus(processOnStatus);
                    }

                    var stream = DeliveryFactory.CreateStream(itemParams.Name(item));
                    if (_streamCache.TryAdd(item, stream))
                    {
                        stream.OpenAsync();
                    }
                    else
                    {
                        var msg = $"Unable to open new stream for item {item}.";
                        RaiseOnError(msg);
                    }
                });
            }
            else
            {
                throw new ArgumentNullException("RDP Session is null.");
            }
        }
示例#2
0
        static void Main(string[] args)
        {
            try
            {
                // Create the platform session.
                using (ISession session = Configuration.Sessions.GetSession())
                {
                    // Open the session
                    if (session.Open() == Session.State.Opened)
                    {
                        // *******************************************************************************************************************************
                        // Requesting for multiple instruments.
                        // The ItemStream interface supports the ability to request/stream a single item.  The following code segment utilizes the power
                        // of the .NET asynchronous libraries to send a collection of requests and monitor the whole collection for completion.
                        // *******************************************************************************************************************************
                        List <Task <Stream.State> > tasks = new List <Task <Stream.State> >();

                        // First, prepare our item stream details including the fields of interest and where to capture events...
                        var itemParams = new ItemStream.Params().Session(session).WithFields("DSPLY_NAME", "BID", "ASK")
                                         .OnRefresh((s, msg) => DumpMsg(msg))
                                         .OnUpdate((s, msg) => DumpMsg(msg))
                                         .OnStatus((s, msg) => Console.WriteLine(msg));

                        // Next, iterate through the collection of items, applying each to our parameters specification.  Send each request asynchronously...
                        foreach (var item in new[] { "EUR=", "GBP=", "CAD=" })
                        {
                            // Create our stream
                            IStream stream = DeliveryFactory.CreateStream(itemParams.Name(item));

                            // Open the stream asynchronously and keep track of the task
                            tasks.Add(stream.OpenAsync());
                        }

                        // Monitor the collection for completion.  We are intentionally blocking here waiting for the whole collection to complete.
                        Task.WhenAll(tasks).GetAwaiter().GetResult();
                        Console.WriteLine("\nInitial response for all instruments complete.  Updates will follow based on changes in the market...");

                        // Wait for updates...
                        Console.ReadKey();
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine($"\n**************\nFailed to execute: {e.Message}\n{e.InnerException}\n***************");
            }
        }
示例#3
0
        public async Task OpenItemAsync(string item, Refinitiv.DataPlatform.Core.ISession RdpSession, IEnumerable <string> fieldNameList = null,
                                        bool streamRequest = false)
        {
            if (RdpSession != null)
            {
                await Task.Run(() =>
                {
                    var itemParams = new ItemStream.Params().Session(RdpSession)
                                     .WithStreaming(streamRequest)
                                     .OnRefresh(processOnRefresh)
                                     .OnUpdate(processOnUpdate)
                                     .OnStatus(processOnStatus);
                    var nameList = (fieldNameList ?? Array.Empty <string>()).ToList();
                    if (nameList.Any())
                    {
                        // First, prepare our item stream details including the fields of interest and where to capture events...
                        itemParams.WithFields(nameList);
                    }


                    var stream = DeliveryFactory.CreateStream(itemParams.Name(item));
                    if (_streamCache.TryAdd(item, stream))
                    {
                        stream.OpenAsync();
                    }
                    else
                    {
                        var msg = $"Unable to open new stream for item {item}.";
                        RaiseOnError(msg);
                    }
                }).ConfigureAwait(false);
            }
            else
            {
                throw new ArgumentNullException("RDP Session is null.");
            }
        }