public void SubscribeToNewsHeadlineStream() { //First we need a valid session, obtained from the Rpc client var ctx = new CIAPI.Rpc.Client(RPC_URI, STREAMING_URI,AppKey); 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 = ctx.CreateStreamingClient(); //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(); }
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); }
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); }
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 SubscribeToNewsHeadlineStream() { //First we need a valid session, obtained from the Rpc client var ctx = new CIAPI.Rpc.Client(RPC_URI, STREAMING_URI, AppKey); 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 = ctx.CreateStreamingClient(); //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(); }