コード例 #1
0
        static void Main(string[] args)
        {
            // Complete image of the concatenation our MarketByPrice level 2 initial refreshes
            JObject image = new JObject();

            // Create a session into the platform.
            ISession session = GlobalSettings.Sessions.GetSession();

            // Open the session
            session.Open();

            // Define a MarketByPrice stream specifying the Domain "MarketByPrice"
            // For each refresh, we merge the contents into the image object.  Once all refresh segments have arrived, the
            // OnComplete is executed and the completed image details are presented for display.
            using (IStream stream = DeliveryFactory.CreateStream(
                       new ItemStream.Params().Session(session)
                       .Name("BB.TO")
                       .WithDomain("MarketByPrice")
                       .OnRefresh((s, msg) => image.Merge(msg))
                       .OnComplete(s => DumpImage(image))
                       .OnUpdate((s, msg) => DumpUpdate(msg))
                       .OnStatus((s, msg) => Console.WriteLine(msg))))
            {
                // Open the stream...
                stream.Open();

                // Wait for data to come in then hit any key to close the stream...
                Console.ReadKey();
            }
        }
コード例 #2
0
        static void Main(string[] args)
        {
            try
            {
                using (ISession session = Configuration.Sessions.GetSession())
                {
                    // Open the session
                    session.Open();

                    // Define a stream to retrieve level 1 content...
                    using (IStream stream = DeliveryFactory.CreateStream(
                               new ItemStream.Params().Session(session)
                               .Name("EUR=")
                               .OnRefresh((s, msg) => Console.WriteLine(msg))
                               .OnUpdate((s, msg) => Console.WriteLine(msg))
                               .OnError((s, err) => Console.WriteLine(err))
                               .OnStatus((s, msg) => Console.WriteLine(msg))))
                    {
                        // Open the stream...
                        stream.Open();

                        // Wait for data to come in then hit any key to close the stream...
                        Console.ReadKey();
                    }
                }
            }
            catch (Exception e)
            {
                Console.WriteLine($"\n**************\nFailed to execute: {e.Message}\n{e.InnerException}\n***************");
            }
        }
コード例 #3
0
        static void Main(string[] args)
        {
            // Set Logger level to Trace
            Log.Level = NLog.LogLevel.Trace;

            bool     useRDP = false;
            ISession session;

            if (!useRDP)
            {
                System.Console.WriteLine("Start DeploytedPlatformSession");
                session = CoreFactory.CreateSession(new DeployedPlatformSession.Params()
                                                    .Host(WebSocketHost)
                                                    .WithDacsUserName(TREPUser)
                                                    .WithDacsApplicationID(appID)
                                                    .WithDacsPosition(position)
                                                    .OnState((s, state, msg) =>
                {
                    Console.WriteLine($"{DateTime.Now}:  {msg}. (State: {state})");
                    _sessionState = state;
                })
                                                    .OnEvent((s, eventCode, msg) => Console.WriteLine($"{DateTime.Now}: {msg}. (Event: {eventCode})")));
            }
            else
            {
                System.Console.WriteLine("Start RDP PlatformSession");
                session = CoreFactory.CreateSession(new PlatformSession.Params()
                                                    .OAuthGrantType(new GrantPassword().UserName(RDPUser)
                                                                    .Password(RDPPassword))
                                                    .AppKey(RDPAppKey)
                                                    .WithTakeSignonControl(true)
                                                    .OnState((s, state, msg) =>
                {
                    Console.WriteLine($"{DateTime.Now}:  {msg}. (State: {state})");
                    _sessionState = state;
                })
                                                    .OnEvent((s, eventCode, msg) => Console.WriteLine($"{DateTime.Now}: {msg}. (Event: {eventCode})")));
            }
            session.Open();
            if (_sessionState == Session.State.Opened)
            {
                System.Console.WriteLine("Session is now Opened");
                System.Console.WriteLine("Sending MRN_STORY request");
                using (IStream stream = DeliveryFactory.CreateStream(
                           new ItemStream.Params().Session(session)
                           .Name("MRN_STORY")
                           .WithDomain("NewsTextAnalytics")
                           .OnRefresh((s, msg) => Console.WriteLine($"{msg}\n\n"))
                           .OnUpdate((s, msg) => ProcessMRNUpdateMessage(msg))
                           .OnError((s, msg) => Console.WriteLine(msg))
                           .OnStatus((s, msg) => Console.WriteLine($"{msg}\n\n"))))
                {
                    stream.Open();
                    Thread.Sleep(runtime);
                }
            }
        }
        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.");
            }
        }
コード例 #5
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***************");
            }
        }
コード例 #6
0
        private static void TestStreaming()
        {
            string item1 = "EUR=";
            string item2 = "CAD=";

            try
            {
                IStream stream1 = DeliveryFactory.CreateStream(
                    new ItemStream.Params().Session(Session.DefaultSession)
                    .Name(item1)
                    .OnRefresh((s, msg) => Console.WriteLine($"{DateTime.Now}:{msg}"))
                    .OnUpdate((s, msg) => DumpMsg(msg))
                    .OnStatus((s, msg) => Console.WriteLine($"{DateTime.Now} => Status1: {msg}"))
                    .OnError((s, msg) => Console.WriteLine($"Stream1 error: {DateTime.Now}:{msg}")));
                if (stream1.Open() != Stream.State.Opened)
                {
                    Console.WriteLine($"Stream did not open: {stream1.OpenState}");
                }

                IStream stream2 = DeliveryFactory.CreateStream(
                    new ItemStream.Params().Session(Session.DefaultSession)
                    .Name(item2)
                    .OnRefresh((s, msg) => Console.WriteLine($"{DateTime.Now}:{msg}"))
                    .OnUpdate((s, msg) => DumpMsg(msg))
                    .OnStatus((s, msg) => Console.WriteLine($"{DateTime.Now} => Status2: {msg}"))
                    .OnError((s, msg) => Console.WriteLine($"Stream2 error: {DateTime.Now}:{msg}")));
                stream2.Open();

                Console.ReadKey();
                stream1.Close();
                Console.WriteLine($"Stream {item1} has been closed.  Hit any key to close the {item2} stream...");
                Console.ReadKey();
                stream2.Close();
            }
            catch (PlatformNotSupportedException e)
            {
                Console.WriteLine($"\n******{e.Message} Choose an alternative WebSocket implementation.\n");
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
        }
コード例 #7
0
        static void Main(string[] args)
        {
            // Create a session to connect into the platform.
            ISession session = GlobalSettings.Sessions.GetSession();

            // Open the session
            session.Open();

            // Define a stream to retrieve level 1 content...
            using (IStream stream = DeliveryFactory.CreateStream(
                       new ItemStream.Params().Session(session)
                       .Name("EUR=")
                       .OnRefresh((s, msg) => Console.WriteLine(msg))
                       .OnUpdate((s, msg) => Console.WriteLine(msg))
                       .OnStatus((s, msg) => Console.WriteLine(msg))))
            {
                // Open the stream...
                stream.Open();

                // Wait for data to come in then hit any key to close the stream...
                Console.ReadKey();
            }
        }
コード例 #8
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.");
            }
        }