/// <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 }
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); } }
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); }
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(); } }
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(); }
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(); }
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(); } }
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); }
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); }
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); }
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); }
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); }
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); }
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(); }
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(); }
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); }
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(); }
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(); }
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); }
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); }
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); }
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); }
// 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(); }
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(); }
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); }
// 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() { //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); }
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); }
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"); }
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); }
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(); }
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(); }
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; }
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")); }
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")); }
// 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/")); }
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); }
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); }