public void RecordNewDataForCIAPI() { var rpcClient = new Client(new Uri("https://ciapi.cityindex.com/tradingapi"), new Uri("https://push.cityindex.com"), "foobardotnet"); // start recording requests var stream = new MemoryStream(); var streamRecorder = new StreamRecorder(rpcClient, stream); streamRecorder.Start(); rpcClient.LogIn("secret", "secret"); var accountInfo = rpcClient.AccountInformation.GetClientAndTradingAccount(); rpcClient.SpreadMarkets.ListSpreadMarkets("", "", accountInfo.ClientAccountId, 100, false); rpcClient.News.ListNewsHeadlinesWithSource("dj", "UK", 10); rpcClient.Market.GetMarketInformation(MarketId.ToString()); rpcClient.PriceHistory.GetPriceBars(MarketId.ToString(), "MINUTE", 1, "20"); rpcClient.TradesAndOrders.ListOpenPositions(accountInfo.SpreadBettingAccount.TradingAccountId); rpcClient.LogOut(); streamRecorder.Stop(); stream.Position = 0; using (var fileStream = File.Create("recorded_requests.txt")) { stream.WriteTo(fileStream); } }
public void HowToUseRecorderWithStream() { var rpcClient = new Client(Settings.RpcUri, Settings.StreamingUri, AppKey); // start recording requests var stream = new MemoryStream(); var streamRecorder = new StreamRecorder(rpcClient, stream); // open an array on the stream streamRecorder.Start(); rpcClient.LogIn(Settings.RpcUserName, Settings.RpcPassword); // get some headlines var headlines = rpcClient.News.ListNewsHeadlinesWithSource("dj", "UK", 100); // get a story id from one of the headlines var storyId = headlines.Headlines[0].StoryId; // get the body of the story var storyDetail = rpcClient.News.GetNewsDetail("dj", storyId.ToString()); Assert.IsNotNullOrEmpty(storyDetail.NewsDetail.Story, "story was empty?"); rpcClient.LogOut(); // close the array in the stream streamRecorder.Stop(); stream.Position = 0; var output = Encoding.UTF8.GetString(stream.ToArray()); List<RequestInfoBase> requests = rpcClient.Serializer.DeserializeObject<List<RequestInfoBase>>(output); Assert.IsTrue(output.Contains("\"Target\": \"https://ciapi.cityindex.com/tradingapi/session\"")); }