Ejemplo n.º 1
0
        /// <summary>
        /// While the code is drastically simplified in comparison to the async pattern, you will typically
        /// want to do this on another thread and use BeingInvoke on the UI to marshal UI updates to the UI thread.
        /// This is probably the simplest pattern.
        /// </summary>
        private static void GetNewsSynchronously()
        {
            try
            {
                var ctx = new CIAPI.Rpc.Client(new Uri(StaticTestConfig.RpcUrl), new Uri(StaticTestConfig.StreamingUrl), AppKey);

                ctx.LogIn(StaticTestConfig.ApiUsername, StaticTestConfig.ApiPassword);

                var headlinesResponse = ctx.News.ListNewsHeadlinesWithSource("dj", "UK", 10);

                foreach (var item in headlinesResponse.Headlines)
                {
                    // item contains id, date and headline.
                    Console.WriteLine("{0} {1} {2}\r\n", item.StoryId, item.Headline, item.PublishDate);

                    // fetch details to get all of the above and the body of the story
                    var detailResponse = ctx.News.GetNewsDetail("dj", item.StoryId.ToString());

                    Console.WriteLine("{0}", detailResponse.NewsDetail.Story.Substring(0, 35) + "...");
                    Console.WriteLine("\r\n-----------------------------------------------------------------------------\r\n");
                }

                ctx.LogOut();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
                Console.WriteLine("\r\nPress enter to continue\r\n");
                Console.ReadLine();
            }

            #endregion
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            try
            {
                var listeners = new[] { new TextWriterTraceListener(Console.Out) };
                Debug.Listeners.AddRange(listeners);

                var adapter = new MyLoggerFactoryAdapter(null)
                {
                    OnMessage = AddLogMessage
                };
                LogManager.Adapter = adapter;

                var client = new CIAPI.Rpc.Client(RPC_URI);
                client.LogIn(USERNAME, PASSWORD);

                var news = client.News.ListNewsHeadlinesWithSource("mni", "ALL", 10);

                client.LogOut();
            }
            catch (Exception exc)
            {
                Console.WriteLine(exc);
            }
        }
Ejemplo n.º 3
0
        public void CanLogoutAsync()
        {

            var requestFactory = new TestRequestFactory();

            var throttleScopes = new Dictionary<string, IThrottedRequestQueue>
                {
                    {"data", new ThrottedRequestQueue(TimeSpan.FromSeconds(5), 30, 10)},
                    {"trading", new ThrottedRequestQueue(TimeSpan.FromSeconds(3), 1, 10)}
                };

            requestFactory.CreateTestRequest(LoggedOut);

            var ctx = new CIAPI.Rpc.Client(new Uri(TestConfig.ApiUrl), new RequestCache(), requestFactory, throttleScopes, 3);

            ctx.BeginDeleteSession(TestConfig.ApiUsername, TestConfig.ApiTestSessionId, ar =>
            {
                EnqueueCallback(() =>
                {
                    var response = ctx.EndDeleteSession(ar);
                    Assert.IsTrue(response.LoggedOut);
                }
            );

                EnqueueTestComplete();
            }, null);
        }
Ejemplo n.º 4
0
 protected void Application_Start(object sender, EventArgs e)
 {
     // set up a capturing logger so that we can output snapshots of activity upon page render
     LogManager.CreateInnerLogger =
         (logName, logLevel, showLevel, showDateTime, showLogName, dateTimeFormat) =>
     {
         return(new CapturingAppender(logName, logLevel, showLevel, showDateTime, showLogName,
                                      dateTimeFormat));
     };
     try
     {
         GlobalRpcClient = new Client(new Uri("https://ciapipreprod.cityindextest9.co.uk/TradingApi"), AppKey);
         ApiLogOnResponseDTO response = GlobalRpcClient.LogIn("XX070608", "password");
         if (response.PasswordChangeRequired)
         {
             _rpcStatus = "admin must change password for global account";
         }
         else
         {
             _rpcStatus = "OK";
         }
     }
     catch (ApiException ex)
     {
         _rpcStatus = ex.ToString();
     }
     catch (Exception ex)
     {
         _rpcStatus = ex.ToString();
     }
 }
Ejemplo n.º 5
0
        public void SubscribeToNewsHeadlineStream()
        {
            //First we need a valid session, obtained from the Rpc client
            var ctx = new CIAPI.Rpc.Client(RPC_URI);
            ctx.LogIn(USERNAME, PASSWORD);

            //Next we create a connection to the streaming api, using the authenticated session
            //You application should only ever have one of these
            var streamingClient = StreamingClientFactory.CreateStreamingClient(STREAMING_URI, USERNAME, ctx.Session);
            

            //And instantiate a listener for news headlines on the appropriate topic
            //You can have multiple listeners on one connection
            var newsListener = streamingClient.BuildNewsHeadlinesListener("UK");
            

            //The MessageReceived event will be triggered every time a new News headline is available,
            //so attach a handler for that event, and wait until something comes through
            var gate = new ManualResetEvent(false);
            NewsDTO receivedNewsHeadline = null;
            newsListener.MessageReceived += (s, e) =>
            {
                receivedNewsHeadline = e.Data;
                //Do something with the new News headline data - perhaps update a news ticker?
                gate.Set();
            };
            gate.WaitOne();

            //Shut down the connection
            streamingClient.Dispose();

            //Destroy your session
            ctx.LogOut();
        }
Ejemplo n.º 6
0
        public void FetchNews_async()
        {
            var ctx = new CIAPI.Rpc.Client(RPC_URI);
            var gate = new AutoResetEvent(false);
            ctx.BeginLogIn(USERNAME, PASSWORD, a =>
            {
                ctx.EndLogIn(a);

                ctx.News.BeginListNewsHeadlinesWithSource("dj", "UK", 10, newsResult =>
                {

                    ListNewsHeadlinesResponseDTO news = ctx.News.EndListNewsHeadlinesWithSource(newsResult);

                    //do something with the news

                    ctx.BeginLogOut(result=>
                        {
                            gate.Set();
                        
                        }, null);
                }, null);
            }, null);

            gate.WaitOne();
        }
Ejemplo n.º 7
0
 protected void Application_Start(object sender, EventArgs e)
 {
     // set up a capturing logger so that we can output snapshots of activity upon page render
     LogManager.CreateInnerLogger =
         (logName, logLevel, showLevel, showDateTime, showLogName, dateTimeFormat) =>
             {
                 return new CapturingAppender(logName, logLevel, showLevel, showDateTime, showLogName,
                                              dateTimeFormat);
             };
     try
     {
         GlobalRpcClient = new Client(new Uri("https://ciapipreprod.cityindextest9.co.uk/TradingApi"), AppKey);
         ApiLogOnResponseDTO response = GlobalRpcClient.LogIn("XX070608", "password");
         if (response.PasswordChangeRequired)
         {
             _rpcStatus = "admin must change password for global account";
         }
         else
         {
             _rpcStatus = "OK";
         }
     }
     catch (ApiException ex)
     {
         _rpcStatus = ex.ToString();
     }
     catch (Exception ex)
     {
         _rpcStatus = ex.ToString();
     }
 }
Ejemplo n.º 8
0
        private void LoginButtonClick(object sender, EventArgs e)
        {
            DisableUi();
            _ctx = new CIAPI.Rpc.Client(new Uri(ApiEndpointTextBox.Text),new Uri("http://nostreaminginthisapp.com"),  AppKey);
            _ctx.BeginLogIn(UidTextBox.Text, PwdTextBox.Text, result =>
                {
                    try
                    {

                        _ctx.EndLogIn(result);
                        Invoke(() =>
                        {
                            MainTabControl.Enabled = true;
                            LogOutButton.Enabled = true;
                            LoginButton.Enabled = false;
                            Application.DoEvents();

                        });
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                    }
                    finally
                    {
                        Cursor = Cursors.Default;
                    }
                }, null);

        }
Ejemplo n.º 9
0
 private void LoginButtonClick(object sender, EventArgs e)
 {
     DisableUi();
     _ctx = new CIAPI.Rpc.Client(new Uri(ApiEndpointTextBox.Text), new Uri("http://nostreaminginthisapp.com"), AppKey);
     _ctx.BeginLogIn(UidTextBox.Text, PwdTextBox.Text, result =>
     {
         try
         {
             _ctx.EndLogIn(result);
             Invoke(() =>
             {
                 MainTabControl.Enabled = true;
                 LogOutButton.Enabled   = true;
                 LoginButton.Enabled    = false;
                 Application.DoEvents();
             });
         }
         catch (Exception ex)
         {
             MessageBox.Show(ex.Message);
         }
         finally
         {
             Invoke(() =>
             {
                 Cursor = Cursors.Default;
                 Application.DoEvents();
             });
         }
     }, null);
 }
Ejemplo n.º 10
0
        static void Main(string[] args)
        {
            try
            {
                var adapter = new MyLoggerFactoryAdapter(null) { OnMessage = AddLogMessage };
                LogManager.Adapter = adapter;

                _client = new CIAPI.Rpc.Client(RPC_URI);
                _client.LogIn(USERNAME, PASSWORD);

                for (int i = 0; i < 100; i++)
                {
                    ThreadPool.QueueUserWorkItem(s => EndlessTest());
                }

                Console.ReadKey();

                _client.LogOut();
                _client.Dispose();
            }
            catch (Exception exc)
            {
                Console.WriteLine(exc);
            }
        }
        private void BuildClients()
        {
            Dispatcher.BeginInvoke(() => listBox1.Items.Add("creating rpc client"));
            RpcClient = new Client(RPC_URI, "CI-WP7");
            RpcClient.BeginLogIn(USERNAME, PASSWORD, ar =>
            {
                var session = RpcClient.EndLogIn(ar);

                ThreadPool.QueueUserWorkItem(_ =>
                {
                    Dispatcher.BeginInvoke(() => listBox1.Items.Add("creating listeners"));
                    StreamingClient = StreamingClientFactory.CreateStreamingClient(STREAM_URI, USERNAME, session.Session);
                    MarketPricesStream = StreamingClient.BuildPricesListener(new[] { MarketId });
                    MarketPricesStream.MessageReceived += OnMarketPricesStreamMessageReceived;
                    OrdersStream = StreamingClient.BuildOrdersListener();
                    OrdersStream.MessageReceived += OnOrdersStreamMessageReceived;

                    Dispatcher.BeginInvoke(() => listBox1.Items.Add("getting account info"));
                    RpcClient.AccountInformation.BeginGetClientAndTradingAccount(ar2 =>
                    {
                        Account = RpcClient.AccountInformation.EndGetClientAndTradingAccount(ar2);

                        Dispatcher.BeginInvoke(() => listBox1.Items.Add("getting market info"));
                        RpcClient.Market.BeginGetMarketInformation(MarketId.ToString(), ar3 =>
                        {
                            Market = RpcClient.Market.EndGetMarketInformation(ar3).MarketInformation;
                            Dispatcher.BeginInvoke(() => button1.IsEnabled = true);
                        }, null);
                    }, null);
                });
            }, null);
        }
Ejemplo n.º 12
0
        public static void ConnectCIAPI()
        {
            CIAPI_Client = new CIAPI.Rpc.Client(RPC_URI);
            CIAPI_Client.LogIn(USERNAME, PASSWORD);

            StreamingClient = StreamingClientFactory.CreateStreamingClient(STREAMING_URI, USERNAME, CIAPI_Client.SessionId);
            StreamingClient.Connect();

            IsConnected = true;
        }
 private void BuildClients()
 {
     Dispatcher.BeginInvoke(() => listBox1.Items.Add("creating rpc client"));
     RpcClient = new Client(RPC_URI);
     RpcClient.BeginLogIn(USERNAME, PASSWORD, ar =>
     {
         RpcClient.EndLogIn(ar);
         Dispatcher.BeginInvoke(() => button1.IsEnabled = true);
     }, null);
 }
Ejemplo n.º 14
0
 private void BuildClients()
 {
     Dispatcher.BeginInvoke(() => listBox1.Items.Add("creating rpc client"));
     RpcClient = new Client(new Uri(StaticTestConfig.RpcUrl), new Uri(StaticTestConfig.StreamingUrl), StaticTestConfig.AppKey);
     RpcClient.BeginLogIn(StaticTestConfig.ApiUsername, StaticTestConfig.ApiPassword, ar =>
     {
         RpcClient.EndLogIn(ar);
         Dispatcher.BeginInvoke(() => button1.IsEnabled = true);
     }, null);
 }
Ejemplo n.º 15
0
 private void BuildClients()
 {
     Dispatcher.BeginInvoke(() => listBox1.Items.Add("creating rpc client"));
     RpcClient = new Client(new Uri(StaticTestConfig.RpcUrl), new Uri(StaticTestConfig.StreamingUrl), StaticTestConfig.AppKey);
     RpcClient.BeginLogIn(StaticTestConfig.ApiUsername, StaticTestConfig.ApiPassword, ar =>
     {
         RpcClient.EndLogIn(ar);
         Dispatcher.BeginInvoke(() => button1.IsEnabled = true);
     }, null);
 }
Ejemplo n.º 16
0
        public void FindMarkets()
        {
            var client = new Client(new Uri(ApiUrl));

            LogTextBox.Text = LogTextBox.Text + "Trying to connect.." + Environment.NewLine;

            client.BeginLogIn(UserName, Password,
                              response => Dispatcher.BeginInvoke(new Action(() =>
                              {
                                  client.EndLogIn(response);
                                  LogTextBox.Text = LogTextBox.Text + string.Format("Connected: {0}", !string.IsNullOrEmpty(client.Session)) + Environment.NewLine;
                                  LogTextBox.Text = LogTextBox.Text + string.Format("Call Search Method.")+ Environment.NewLine;

                                  try
                                  {
                                      client.Market.BeginListMarketInformationSearch(
                                          false, // market code not used for search
                                          true, // use market name
                                          false, // iFX markets should always be CFD according to Peter
                                          true,
                                          false,
                                          SearchTextBox.Text,
                                          10,
                                          searchCallBack => Dispatcher.BeginInvoke(() =>
                                                                                       {
                                                                                           {
                                                                                               try
                                                                                               {
                                                                                                   var findedMarkets =
                                                                                                       client.Market.EndListMarketInformationSearch(searchCallBack);

                                                                                                   foreach (var marketInfoDTO in findedMarkets.MarketInformation)
                                                                                                   {

                                                                                                       LogTextBox.Text = LogTextBox.Text + 
                                                                                                           string.Format(marketInfoDTO.MarketId.ToString()) + Environment.NewLine;
                                                                                                   }
                                                                                               }
                                                                                               catch (Exception ex)
                                                                                               {
                                                                                                   LogTextBox.Text = LogTextBox.Text + string.Format("Exception: {0}", ex.Message) + Environment.NewLine;
                                                                                               }

                                                                                           }
                                                                                       }),
                                        null);
                                  }
                                  catch (Exception ex)
                                  {
                                      LogTextBox.Text = LogTextBox.Text + string.Format("Exception: {0}", ex.Message) + Environment.NewLine;
                                  }

                              }), null), null);
        }
Ejemplo n.º 17
0
        public void FetchNews_sync()
        {
            var ctx = new CIAPI.Rpc.Client(RPC_URI);
            ctx.LogIn(USERNAME, PASSWORD);

            ListNewsHeadlinesResponseDTO news = ctx.News.ListNewsHeadlinesWithSource("dj", "UK", 10);
            
            //do something with the news

            ctx.LogOut();
        }
Ejemplo n.º 18
0
        public void FetchNews_sync()
        {
            var ctx = new CIAPI.Rpc.Client(RPC_URI, STREAMING_URI, AppKey);

            ctx.LogIn(USERNAME, PASSWORD);

            ListNewsHeadlinesResponseDTO news = ctx.News.ListNewsHeadlinesWithSource("dj", "UK", 10);

            //do something with the news

            ctx.LogOut();
        }
        public void FetchNews_sync()
        {
            var ctx = new CIAPI.Rpc.Client(RPC_URI);

            ctx.LogIn(USERNAME, PASSWORD);

            ListNewsHeadlinesResponseDTO news = ctx.ListNewsHeadlines("UK", 10);

            //do something with the news

            ctx.LogOut();
        }
Ejemplo n.º 20
0
        public static IStreamingClient BuildStreamingClient(
            string userName = "******",
            string password = "******")
        {
            const string apiUrl = "https://ciapipreprod.cityindextest9.co.uk/TradingApi/";

            var authenticatedClient = new CIAPI.Rpc.Client(new Uri(apiUrl));
            authenticatedClient.LogIn(userName, password);

            var streamingUri = new Uri("https://pushpreprod.cityindextest9.co.uk");

            return StreamingClientFactory.CreateStreamingClient(streamingUri, userName, authenticatedClient.Session);
        }
Ejemplo n.º 21
0
        private static void GetNewsAsynchronously()
        {
            _ctx = new CIAPI.Rpc.Client(new Uri(StaticTestConfig.RpcUrl), new Uri(StaticTestConfig.StreamingUrl), AppKey);

            _gate = new ManualResetEvent(false);
            BeginLogIn(StaticTestConfig.ApiUsername, StaticTestConfig.ApiPassword);

            _gate.WaitOne();



            Console.WriteLine("\r\nFinished.\r\nPress enter to continue\r\n");
            Console.ReadLine();
        }
Ejemplo n.º 22
0
        private static void GetNewsAsynchronously()
        {
            _ctx = new CIAPI.Rpc.Client(new Uri(TestConfig.RpcUrl));

            _gate = new ManualResetEvent(false);
            BeginLogIn(TestConfig.ApiUsername, TestConfig.ApiPassword);

            _gate.WaitOne();



            Console.WriteLine("\r\nFinished.\r\nPress enter to continue\r\n");
            Console.ReadLine();
        }
Ejemplo n.º 23
0
        private void BuildClients()
        {
            Dispatcher.BeginInvoke(() => listBox1.Items.Add("creating rpc client"));

            //Hook up a logger for the CIAPI.CS libraries
            LogManager.CreateInnerLogger = (logName, logLevel, showLevel, showDateTime, showLogName, dateTimeFormat)
                                            => new SimpleDebugAppender(logName, logLevel, showLevel, showDateTime, showLogName, dateTimeFormat);

            RpcClient = new Client(new Uri(StaticTestConfig.RpcUrl), new Uri(StaticTestConfig.StreamingUrl),AppKey);
            RpcClient.BeginLogIn(StaticTestConfig.ApiUsername, StaticTestConfig.ApiPassword, ar =>
            {
                RpcClient.EndLogIn(ar);
                Dispatcher.BeginInvoke(() => button1.IsEnabled = true);
            }, null);
        }
Ejemplo n.º 24
0
        private void BuildClients()
        {
            Dispatcher.BeginInvoke(() => listBox1.Items.Add("creating rpc client"));

            //Hook up a logger for the CIAPI.CS libraries
            LogManager.CreateInnerLogger = (logName, logLevel, showLevel, showDateTime, showLogName, dateTimeFormat)
                                           => new SimpleDebugAppender(logName, logLevel, showLevel, showDateTime, showLogName, dateTimeFormat);

            RpcClient = new Client(new Uri(StaticTestConfig.RpcUrl), new Uri(StaticTestConfig.StreamingUrl), AppKey);
            RpcClient.BeginLogIn(StaticTestConfig.ApiUsername, StaticTestConfig.ApiPassword, ar =>
            {
                RpcClient.EndLogIn(ar);
                Dispatcher.BeginInvoke(() => button1.IsEnabled = true);
            }, null);
        }
Ejemplo n.º 25
0
        private void BuildClients()
        {
            Dispatcher.BeginInvoke(() => listBox1.Items.Add("creating rpc client"));
            RpcClient = new Client(RPC_URI, STREAM_URI, "CI-WP7");
            RpcClient.BeginLogIn(USERNAME, PASSWORD, ar =>
            {
                var session = RpcClient.EndLogIn(ar);

                ThreadPool.QueueUserWorkItem(_ =>
                {
                    Dispatcher.BeginInvoke(() => listBox1.Items.Add("creating listeners"));
                    StreamingClient = RpcClient.CreateStreamingClient();
                    MarketPricesStream = StreamingClient.BuildDefaultPricesListener(AccountOperatorId);
                    MarketPricesStream.MessageReceived += OnMarketPricesStreamMessageReceived;
                    Dispatcher.BeginInvoke(() => button1.IsEnabled = true);
                });
            }, null);
        }
Ejemplo n.º 26
0
        private void BuildClients()
        {
            Dispatcher.BeginInvoke(() => listBox1.Items.Add("creating rpc client"));
            RpcClient = new Client(RPC_URI, STREAM_URI, "CI-WP7");
            RpcClient.BeginLogIn(USERNAME, PASSWORD, ar =>
            {
                var session = RpcClient.EndLogIn(ar);

                ThreadPool.QueueUserWorkItem(_ =>
                {
                    Dispatcher.BeginInvoke(() => listBox1.Items.Add("creating listeners"));
                    StreamingClient    = RpcClient.CreateStreamingClient();
                    MarketPricesStream = StreamingClient.BuildDefaultPricesListener(AccountOperatorId);
                    MarketPricesStream.MessageReceived            += OnMarketPricesStreamMessageReceived;
                    Dispatcher.BeginInvoke(() => button1.IsEnabled = true);
                });
            }, null);
        }
Ejemplo n.º 27
0
        private void BuildClients()
        {
            //Hook up a logger for the CIAPI.CS libraries
            LogManager.CreateInnerLogger = (logName, logLevel, showLevel, showDateTime, showLogName, dateTimeFormat)
                         => new SimpleDebugAppender(logName, logLevel, showLevel, showDateTime, showLogName, dateTimeFormat);

            Dispatcher.BeginInvoke(() => listBox1.Items.Add("creating rpc client"));
            RpcClient = new Client(RpcUri, StreamingUri, "CI-WP7");
            RpcClient.BeginLogIn(UerName, Password, ar =>
            {
                try
                {
                    RpcClient.EndLogIn(ar);
                    //RpcClient.MagicNumberResolver.PreloadMagicNumbersAsync();
                    RpcClient.MagicNumberResolver.PreloadMagicNumbers();
                    ThreadPool.QueueUserWorkItem(_ =>
                    {
                        Dispatcher.BeginInvoke(() => listBox1.Items.Add("creating listeners"));
                        StreamingClient = RpcClient.CreateStreamingClient();
                        PriceListener = StreamingClient.BuildPricesListener(MarketId);
                        PriceListener.MessageReceived += OnMessageReceived;

                        Dispatcher.BeginInvoke(() => listBox1.Items.Add("getting account info"));
                        RpcClient.AccountInformation.BeginGetClientAndTradingAccount(ar2 =>
                        {
                            Account = RpcClient.AccountInformation.EndGetClientAndTradingAccount(ar2);

                            Dispatcher.BeginInvoke(() => listBox1.Items.Add("getting market info"));
                            RpcClient.Market.BeginGetMarketInformation(MarketId.ToString(), ar3 =>
                            {
                                Market = RpcClient.Market.EndGetMarketInformation(ar3).MarketInformation;
                                Dispatcher.BeginInvoke(() => Button1.IsEnabled = true);
                            }, null);
                        }, null);
                    });
                }
                catch (Exception ex)
                {
                    Dispatcher.BeginInvoke(() => listBox1.Items.Add("exception caught: " + ex));
                }
            }, null);
        }
Ejemplo n.º 28
0
        private void BuildClients()
        {
            //Hook up a logger for the CIAPI.CS libraries
            LogManager.CreateInnerLogger = (logName, logLevel, showLevel, showDateTime, showLogName, dateTimeFormat)
                                           => new SimpleDebugAppender(logName, logLevel, showLevel, showDateTime, showLogName, dateTimeFormat);

            Dispatcher.BeginInvoke(() => listBox1.Items.Add("creating rpc client"));
            RpcClient = new Client(RpcUri, StreamingUri, "CI-WP7");
            RpcClient.BeginLogIn(UerName, Password, ar =>
            {
                try
                {
                    RpcClient.EndLogIn(ar);
                    //RpcClient.MagicNumberResolver.PreloadMagicNumbersAsync();
                    RpcClient.MagicNumberResolver.PreloadMagicNumbers();
                    ThreadPool.QueueUserWorkItem(_ =>
                    {
                        Dispatcher.BeginInvoke(() => listBox1.Items.Add("creating listeners"));
                        StreamingClient = RpcClient.CreateStreamingClient();
                        PriceListener   = StreamingClient.BuildPricesListener(MarketId);
                        PriceListener.MessageReceived += OnMessageReceived;

                        Dispatcher.BeginInvoke(() => listBox1.Items.Add("getting account info"));
                        RpcClient.AccountInformation.BeginGetClientAndTradingAccount(ar2 =>
                        {
                            Account = RpcClient.AccountInformation.EndGetClientAndTradingAccount(ar2);

                            Dispatcher.BeginInvoke(() => listBox1.Items.Add("getting market info"));
                            RpcClient.Market.BeginGetMarketInformation(MarketId.ToString(), ar3 =>
                            {
                                Market = RpcClient.Market.EndGetMarketInformation(ar3).MarketInformation;
                                Dispatcher.BeginInvoke(() => Button1.IsEnabled = true);
                            }, null);
                        }, null);
                    });
                }
                catch (Exception ex)
                {
                    Dispatcher.BeginInvoke(() => listBox1.Items.Add("exception caught: " + ex));
                }
            }, null);
        }
Ejemplo n.º 29
0
        // Constructor
        public MainPage()
        {
            InitializeComponent();


            var authenticatedClient = new CIAPI.Rpc.Client(new Uri(apiUrl));
            authenticatedClient.BeginLogIn(userName, password, (ar) =>
                {
                    authenticatedClient.EndLogIn(ar);

                    var client = new LightstreamerClient(new Uri(streamingUrl), authenticatedClient.UserName, authenticatedClient.Session);

                    client.StatusUpdate += client_StatusUpdate;

                    var listener = client.BuildListener<PriceDTO>(dataAdapter, topic);
                    listener.MessageReceived += listener_MessageReceived;
                }, null);


            
        }
        public void SubscribeToNewsHeadlineStream()
        {
            //First we need a valid session, obtained from the Rpc client
            var ctx = new CIAPI.Rpc.Client(RPC_URI);

            ctx.LogIn(USERNAME, PASSWORD);

            //Next we create a connection to the streaming api, using the authenticated session
            //You application should only ever have one of these
            var streamingClient = StreamingClientFactory.CreateStreamingClient(STREAMING_URI, USERNAME, ctx.SessionId);

            streamingClient.Connect();

            //And instantiate a listener for news headlines on the appropriate topic
            //You can have multiple listeners on one connection
            var newsListener = streamingClient.BuildNewsHeadlinesListener("NEWS.MOCKHEADLINES.UK");

            newsListener.Start();

            //The MessageReceived event will be triggered every time a new News headline is available,
            //so attach a handler for that event, and wait until something comes through
            var     gate = new ManualResetEvent(false);
            NewsDTO receivedNewsHeadline = null;

            newsListener.MessageReceived += (s, e) =>
            {
                receivedNewsHeadline = e.Data;
                //Do something with the new News headline data - perhaps update a news ticker?
                gate.Set();
            };
            gate.WaitOne();

            //Clean up
            //Stop any listeners
            newsListener.Stop();
            //Shut down the connection
            streamingClient.Disconnect();
            //Destroy your session
            ctx.LogOut();
        }
Ejemplo n.º 31
0
		static void Main(string[] args)
		{
			try
			{
				var listeners = new[] { new TextWriterTraceListener(Console.Out) };
				Debug.Listeners.AddRange(listeners);

				var adapter = new MyLoggerFactoryAdapter(null) { OnMessage = AddLogMessage };
				LogManager.Adapter = adapter;

				var client = new CIAPI.Rpc.Client(RPC_URI);
				client.LogIn(USERNAME, PASSWORD);

				var news = client.News.ListNewsHeadlinesWithSource("mni", "ALL", 10);

				client.LogOut();
			}
			catch (Exception exc)
			{
				Console.WriteLine(exc);
			}
		}
Ejemplo n.º 32
0
        public void Test2()
        {
            
            var authenticatedClient = new CIAPI.Rpc.Client(new Uri(apiUrl));
            authenticatedClient.LogIn(userName, password);


            var client = new LightstreamerClient(streamingUrl, authenticatedClient.UserName, authenticatedClient.Session);

            client.StatusUpdate += AdapterStatusUpdate;

            var listener = client.BuildListener<PriceDTO>(dataAdapter, topic);
            listener.MessageReceived += ListenerMessageReceived;

            new ManualResetEvent(false).WaitOne(20000);

            client.TearDownListener(listener);

            client.Dispose();


        }
Ejemplo n.º 33
0
        public void CanLoginAsync()
        {
            var requestFactory = new TestRequestFactory();

            var throttleScopes = new Dictionary<string, IThrottedRequestQueue>
                {
                    {"data", new ThrottedRequestQueue(TimeSpan.FromSeconds(5), 30, 10)},
                    {"trading", new ThrottedRequestQueue(TimeSpan.FromSeconds(3), 1, 10)}
                };

            var ctx = new CIAPI.Rpc.Client(new Uri(TestConfig.ApiUrl), new RequestCache(), requestFactory, throttleScopes, 3);

            requestFactory.CreateTestRequest(LoggedIn);

            ctx.BeginCreateSession( TestConfig.ApiUsername, TestConfig.ApiPassword, ar =>
            {
                var response = ctx.EndCreateSession(ar);
                Assert.IsNotNullOrEmpty(response.Session);
                EnqueueTestComplete();
            }, null);

        }
Ejemplo n.º 34
0
        // Constructor
        public MainPage()
        {
            InitializeComponent();
            CIAPIButton.IsEnabled = false;


            // creating a single rpc client for an application is a better
            // approximation of the intended usage.

            client = new Client(new Uri(StaticTestConfig.RpcUrl), new Uri(StaticTestConfig.StreamingUrl), StaticTestConfig.AppKey);
            listBox1.Items.Add("Trying to connect..");


            client.BeginLogIn(StaticTestConfig.ApiUsername, StaticTestConfig.ApiPassword,
                              response => Dispatcher.BeginInvoke(new Action(() =>
            {
                client.EndLogIn(response);

                listBox1.Items.Add(string.Format("Connected: {0}", !string.IsNullOrEmpty(client.Session)));
                CIAPIButton.IsEnabled = true;
            }), null), null);
        }
Ejemplo n.º 35
0
        private void BuildClients()
        {
            //Hook up a logger for the CIAPI.CS libraries
            LogManager.CreateInnerLogger = (logName, logLevel, showLevel, showDateTime, showLogName, dateTimeFormat)
                                           => new SimpleDebugAppender(logName, logLevel, showLevel, showDateTime, showLogName, dateTimeFormat);

            Dispatcher.BeginInvoke(() => listBox1.Items.Add("creating rpc client"));
            RpcClient = new Client(RPC_URI, STREAM_URI, "CI-WP7");

            RpcClient.BeginLogIn(USERNAME, PASSWORD, ar =>
            {
                _logger.Info("ending login");
                var session = RpcClient.EndLogIn(ar);

                ThreadPool.QueueUserWorkItem(_ =>
                {
                    Dispatcher.BeginInvoke(() => listBox1.Items.Add("creating listeners"));
                    StreamingClient    = RpcClient.CreateStreamingClient();
                    MarketPricesStream = StreamingClient.BuildPricesListener(new[] { MarketId });
                    MarketPricesStream.MessageReceived += OnMarketPricesStreamMessageReceived;
                    OrdersStream = StreamingClient.BuildOrdersListener();
                    OrdersStream.MessageReceived += OnOrdersStreamMessageReceived;

                    Dispatcher.BeginInvoke(() => listBox1.Items.Add("getting account info"));
                    RpcClient.AccountInformation.BeginGetClientAndTradingAccount(ar2 =>
                    {
                        Account = RpcClient.AccountInformation.EndGetClientAndTradingAccount(ar2);

                        Dispatcher.BeginInvoke(() => listBox1.Items.Add("getting market info"));
                        RpcClient.Market.BeginGetMarketInformation(MarketId.ToString(), ar3 =>
                        {
                            Market = RpcClient.Market.EndGetMarketInformation(ar3).MarketInformation;
                            Dispatcher.BeginInvoke(() => button1.IsEnabled = true);
                        }, null);
                    }, null);
                });
            }, null);
        }
Ejemplo n.º 36
0
        private void BuildClients()
        {
            //Hook up a logger for the CIAPI.CS libraries
            LogManager.CreateInnerLogger = (logName, logLevel, showLevel, showDateTime, showLogName, dateTimeFormat)
                         => new SimpleDebugAppender(logName, logLevel, showLevel, showDateTime, showLogName, dateTimeFormat);

            Dispatcher.BeginInvoke(() => listBox1.Items.Add("creating rpc client"));
            RpcClient = new Client(RPC_URI, STREAM_URI, "CI-WP7");
           
            RpcClient.BeginLogIn(USERNAME, PASSWORD, ar =>
            {
                _logger .Info("ending login");
                var session = RpcClient.EndLogIn(ar);

                ThreadPool.QueueUserWorkItem(_ =>
                {
                    Dispatcher.BeginInvoke(() => listBox1.Items.Add("creating listeners"));
                    StreamingClient = RpcClient.CreateStreamingClient();
                    MarketPricesStream = StreamingClient.BuildPricesListener(new[] { MarketId });
                    MarketPricesStream.MessageReceived += OnMarketPricesStreamMessageReceived;
                    OrdersStream = StreamingClient.BuildOrdersListener();
                    OrdersStream.MessageReceived += OnOrdersStreamMessageReceived;

                    Dispatcher.BeginInvoke(() => listBox1.Items.Add("getting account info"));
                    RpcClient.AccountInformation.BeginGetClientAndTradingAccount(ar2 =>
                    {
                        Account = RpcClient.AccountInformation.EndGetClientAndTradingAccount(ar2);

                        Dispatcher.BeginInvoke(() => listBox1.Items.Add("getting market info"));
                        RpcClient.Market.BeginGetMarketInformation(MarketId.ToString(), ar3 =>
                        {
                            Market = RpcClient.Market.EndGetMarketInformation(ar3).MarketInformation;
                            Dispatcher.BeginInvoke(() => button1.IsEnabled = true);
                        }, null);
                    }, null);
                });
            }, null);
        }
Ejemplo n.º 37
0
        public void CreatingASession()
        {
            //Interaction with the API is done via a top level "client" object
            //that holds details about your connection.

            //You need to initialise the client with a valid endpoint
            _rpcClient = new Rpc.Client(Settings.RpcUri, Settings.StreamingUri, AppKey);

            //And then create a session by creating a username & password
            //You can get test credentials by requesting them at https://ciapipreprod.cityindextest9.co.uk/CIAPI.docs/#content.test-credentials


            try
            {
                _rpcClient.LogIn(USERNAME, PASSWORD);
            }
            catch (ReliableHttpException apiException)
            {
                KoanAssert.Fail(string.Format("cannot login because {0}", apiException.Message));
            }

            KoanAssert.That(_rpcClient.Session != "", "after logging in, you should have a valid session");
        }
Ejemplo n.º 38
0
        public void CreatingASession()
        {
            //Interaction with the API is done via a top level "client" object 
            //that holds details about your connection.
            
            //You need to initialise the client with a valid endpoint
            _rpcClient = new Rpc.Client(Settings.RpcUri, Settings.StreamingUri, AppKey);
            
            //And then create a session by creating a username & password
            //You can get test credentials by requesting them at https://ciapipreprod.cityindextest9.co.uk/CIAPI.docs/#content.test-credentials
  

            try
            {
                _rpcClient.LogIn(USERNAME, PASSWORD);
            }
            catch (ReliableHttpException apiException)
            {
                KoanAssert.Fail(string.Format("cannot login because {0}", apiException.Message));
            }

            KoanAssert.That(_rpcClient.Session != "", "after logging in, you should have a valid session");
        }
Ejemplo n.º 39
0
        // Constructor
        public MainPage()
        {
            InitializeComponent();
            CIAPIButton.IsEnabled = false;


            // creating a single rpc client for an application is a better
            // approximation of the intended usage.

            client = new Client(new Uri(StaticTestConfig.RpcUrl), new Uri(StaticTestConfig.StreamingUrl), StaticTestConfig.AppKey);
            listBox1.Items.Add("Trying to connect..");


            client.BeginLogIn(StaticTestConfig.ApiUsername, StaticTestConfig.ApiPassword,
                              response => Dispatcher.BeginInvoke(new Action(() =>
                              {
                                  client.EndLogIn(response);

                                  listBox1.Items.Add(string.Format("Connected: {0}", !string.IsNullOrEmpty(client.Session)));
                                  CIAPIButton.IsEnabled = true;
                              }), null), null);

        }
        private void BuildClients()
        {
            Dispatcher.BeginInvoke(() => listBox1.Items.Add("creating rpc client"));
            RpcClient = new Client(RpcUri, StreamingUri, "CI-WP7");
            RpcClient.BeginLogIn(UerName, Password, ar =>
            {
                try
                {
                    RpcClient.EndLogIn(ar);

                    ThreadPool.QueueUserWorkItem(_ =>
                    {
                        Dispatcher.BeginInvoke(() => listBox1.Items.Add("creating listeners"));
                        StreamingClient = RpcClient.CreateStreamingClient();
                        PriceListener = StreamingClient.BuildPricesListener(MarketId);
                        PriceListener.MessageReceived += OnMessageReceived;

                        Dispatcher.BeginInvoke(() => listBox1.Items.Add("getting account info"));
                        RpcClient.AccountInformation.BeginGetClientAndTradingAccount(ar2 =>
                        {
                            Account = RpcClient.AccountInformation.EndGetClientAndTradingAccount(ar2);

                            Dispatcher.BeginInvoke(() => listBox1.Items.Add("getting market info"));
                            RpcClient.Market.BeginGetMarketInformation(MarketId.ToString(), ar3 =>
                            {
                                Market = RpcClient.Market.EndGetMarketInformation(ar3).MarketInformation;
                                Dispatcher.BeginInvoke(() => Button1.IsEnabled = true);
                            }, null);
                        }, null);
                    });
                }
                catch (Exception ex)
                {
                    Dispatcher.BeginInvoke(() => listBox1.Items.Add("exception caught: " + ex));
                }
            }, null);
        }
Ejemplo n.º 41
0
        public void FetchNews_async()
        {
            var ctx  = new CIAPI.Rpc.Client(RPC_URI, STREAMING_URI, AppKey);
            var gate = new AutoResetEvent(false);

            ctx.BeginLogIn(USERNAME, PASSWORD, a =>
            {
                ctx.EndLogIn(a);

                ctx.News.BeginListNewsHeadlinesWithSource("dj", "UK", 10, newsResult =>
                {
                    ListNewsHeadlinesResponseDTO news = ctx.News.EndListNewsHeadlinesWithSource(newsResult);

                    //do something with the news

                    ctx.BeginLogOut(result =>
                    {
                        gate.Set();
                    }, null);
                }, null);
            }, null);

            gate.WaitOne();
        }
Ejemplo n.º 42
0
        public void Test()
        {


            var authenticatedClient = new CIAPI.Rpc.Client(new Uri(apiUrl));
            authenticatedClient.LogIn(userName, password);


            var adapter = new FaultTolerantLsClientAdapter(streamingUrl, authenticatedClient.UserName, authenticatedClient.Session, dataAdapter);

            adapter.StatusUpdate += AdapterStatusUpdate;
            adapter.Start();
            var listener = adapter.BuildListener<PriceDTO>(topic);
            listener.MessageReceived += ListenerMessageReceived;

            new ManualResetEvent(false).WaitOne(10000);

            adapter.Stop();
            adapter.Start();
            new ManualResetEvent(false).WaitOne(10000);
            
            adapter.Stop();
        
        }
Ejemplo n.º 43
0
        private CIAPI.Rpc.Client BuildClientAndSetupResponse(string expectedJson)
        {

            TestRequestFactory factory = new TestRequestFactory();
            var requestController = new RequestController(TimeSpan.FromSeconds(0), 2, factory, new NullJsonExceptionFactory(), new  ThrottedRequestQueue(TimeSpan.FromSeconds(5), 30, 10, "data"), new ThrottedRequestQueue(TimeSpan.FromSeconds(3), 1, 3, "trading"));

            var ctx = new CIAPI.Rpc.Client(new Uri(TestConfig.RpcUrl), requestController);
            factory.CreateTestRequest(expectedJson);
            return ctx;
        }
Ejemplo n.º 44
0
        public void NonRetryableExceptionFailsInsteadOfRetrying()
        {
            Console.WriteLine("NonRetryableExceptionFailsInsteadOfRetrying");

            var requestFactory = new TestRequestFactory();

            var ctx = new Client(new Uri(TestConfig.RpcUrl), new RequestCache(), requestFactory, _standardThrottleScopes, 3);
            requestFactory.CreateTestRequest("", TimeSpan.FromMilliseconds(300), null, null, new WebException("(401) Unauthorized"));

            Assert.Throws<ApiException>(() => ctx.LogIn("foo", "bar"));
        }
Ejemplo n.º 45
0
        public void ShouldThrowExceptionIfRequestTimesOut()
        {
            var requestFactory = new TestRequestFactory
                                     {
                                         RequestTimeout = TimeSpan.FromSeconds(1)
                                     };

            var ctx = new Client(new Uri(TestConfig.RpcUrl), new RequestCache(), requestFactory, _standardThrottleScopes, 3);
            requestFactory.CreateTestRequest(LoggedIn, TimeSpan.FromSeconds(300));

            Assert.Throws<ApiException>(() => ctx.LogIn("foo", "bar"));
        }
Ejemplo n.º 46
0
 // Code to execute when the application is launching (eg, from Start)
 // This code will not execute when the application is reactivated
 private void Application_Launching(object sender, LaunchingEventArgs e)
 {
     ctx = new CIAPI.Rpc.Client(new Uri("http://ec2-174-129-8-69.compute-1.amazonaws.com/RESTWebServices/"));
 }
Ejemplo n.º 47
0
        public void CanGetNewsHeadlinesAsync()
        {

            var requestFactory = new TestRequestFactory();

            var throttleScopes = new Dictionary<string, IThrottedRequestQueue>
                {
                    {"data", new ThrottedRequestQueue(TimeSpan.FromSeconds(5), 30, 10)},
                    {"trading", new ThrottedRequestQueue(TimeSpan.FromSeconds(3), 1, 10)}
                };

            requestFactory.CreateTestRequest(NewsHeadlines14);

            var ctx = new CIAPI.Rpc.Client(new Uri(TestConfig.ApiUrl), new RequestCache(), requestFactory, throttleScopes, 3)
            {
                UserName = TestConfig.ApiUsername,
                SessionId = TestConfig.ApiTestSessionId
            };


            ctx.BeginListNewsHeadlines("UK", 14, ar =>
                {
                    EnqueueCallback(() =>
                                        {
                                            ListNewsHeadlinesResponseDTO response = ctx.EndListNewsHeadlines(ar);
                                            Assert.AreEqual(14, response.Headlines.Length);
                                        });
                    EnqueueTestComplete();
                }, null);

        }
Ejemplo n.º 48
0
 private void BuildClients()
 {
     Dispatcher.BeginInvoke(() => statusUpdatesListBox.Items.Add("creating rpc client"));
     RpcClient = new Client(RPC_URI, STREAMING_URI, AppKey);
     RpcClient.BeginLogIn(USERNAME, PASSWORD, InitializeStreamingClient, null);
 }