public void SetupFixture() { _rpcClient = BuildRpcClient(); _streamingClient = _rpcClient.CreateStreamingClient(); _CFDmarketId = GetAvailableCFDMarkets(_rpcClient)[0].MarketId; _accounts = _rpcClient.AccountInformation.GetClientAndTradingAccount(); }
public void CanUseFiddlerSessionsToServeRpcCalls() { var parser = new Parser(); // parse saved sessions into collection of session objects string path = @"..\..\..\TestingInfrastructure\Fiddler\5_Full.txt"; var sessions = parser.ParseFile(path); var engine = new FiddlerRequestEngine(sessions); var server = new TestServer(true); string recordedUrl = "https://ciapi.cityindex.com/tradingapi"; server.ProcessRequest += (s, e) => { string requestMethod = e.Request.Method; string requestUrl = recordedUrl + e.Request.Url; var session = engine.FindSession(requestMethod, requestUrl); if (session == null) { e.Response = new ServerBase.ResponseInfo { Status = "404 Not Found" }; } else { e.Response = new ServerBase.ResponseInfo { Headers = new NameValueCollection(session.Response.Headers), Status = session.Response.StatusCode + " " + session.Response.Status, Body = session.Response.Body }; } }; server.Start(); var rpcClient = new Client(new Uri("http://localhost.:" + server.Port), new Uri("http://localhost.:" + server.Port), AppKey); rpcClient.LogIn(Settings.RpcUserName, Settings.RpcPassword); AccountInformationResponseDTO accounts = rpcClient.AccountInformation.GetClientAndTradingAccount(); rpcClient.TradesAndOrders.ListOpenPositions(accounts.TradingAccounts[0].TradingAccountId); rpcClient.LogOut(); rpcClient.Dispose(); server.Stop(); }
public override void FixtureSetup() { base.FixtureSetup(); // hmmmm... only one fixture setup allowed. _rpcClient = BuildRpcClient(); _streamingClient = _rpcClient.CreateStreamingClient(); _CFDmarketId = MarketFixture.GetAvailableCFDMarkets(_rpcClient)[0].MarketId; _accounts = _rpcClient.AccountInformation.GetClientAndTradingAccount(); }
private void GetAccountsButton_Click(object sender, EventArgs e) { _accounts = _client.AccountInformation.GetClientAndTradingAccount(); apiTradingAccountDTOBindingSource.DataSource = _accounts.TradingAccounts; OpenPositionsGroupBox.Enabled = true; ClientAccountsGroupBox.Enabled = true; LogInGroupBox.Enabled = false; LogOutButton.Enabled = true; }
public void CanListOpenPositions() { var rpcClient = BuildRpcClient("CanListOpenPositions"); AccountInformationResponseDTO accounts = rpcClient.AccountInformation.GetClientAndTradingAccount(); rpcClient.TradesAndOrders.ListOpenPositions(accounts.TradingAccounts[0].TradingAccountId); rpcClient.LogOut(); rpcClient.Dispose(); }
public void CanListSpreadMarkets() { var rpcClient = BuildRpcClient(); AccountInformationResponseDTO accounts = rpcClient.AccountInformation.GetClientAndTradingAccount(); // TODO: publish somewhere that search term is a 'StartsWith' not a 'Contains' var response = rpcClient.SpreadMarkets.ListSpreadMarkets("GBP/USD", null, accounts.ClientAccountId, 100, false); Assert.Greater(response.Markets.Length, 0); }
/// <summary> /// /// </summary> /// <param name="username"></param> /// <param name="session"></param> public void LogInUsingSession(string username, string session) { try { this.UserName = username; this.Session = session; AccountInformationResponseDTO d = this.AccountInformation.GetClientAndTradingAccount(); } catch { Session = null; throw; } }
public void CanListCFDMarkets() { var rpcClient = BuildRpcClient(); AccountInformationResponseDTO accounts = rpcClient.AccountInformation.GetClientAndTradingAccount(); var response = rpcClient.CFDMarkets.ListCfdMarkets("USD", null, accounts.ClientAccountId, 500, false); Assert.Greater(response.Markets.Length, 0, "no markets returned"); rpcClient.LogOut(); rpcClient.Dispose(); }
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); }
public void CanListSpreadMarkets() { try { var rpcClient = BuildRpcClient(); AccountInformationResponseDTO accounts = rpcClient.AccountInformation.GetClientAndTradingAccount(); // TODO: publish somewhere that search term is a 'StartsWith' not a 'Contains' // #APIBUG GBP/USD fails - still have problem with path separators in params, even when url encoded var response = rpcClient.SpreadMarkets.ListSpreadMarkets("GBP/USD", null, accounts.ClientAccountId, 100, false); Assert.Greater(response.Markets.Length, 0); rpcClient.LogOut(); rpcClient.Dispose(); } catch (Exception exception) { Assert.Fail("\r\n{0}", GetErrorInfo(exception)); } }
public void noid() { var gate = new AutoResetEvent(false); new Thread(() => { try { var rpcClient = BuildRpcClient(); AccountInformationResponseDTO accounts = rpcClient.AccountInformation.GetClientAndTradingAccount(); var x = rpcClient.TradesAndOrders.ListOpenPositions(accounts.TradingAccounts[0].TradingAccountId); rpcClient.LogOut(); rpcClient.Dispose(); } finally { gate.Set(); } }).Start(); gate.WaitOne(); }
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 CanUpdateTrade() { var rpcClient = BuildRpcClient(); AccountInformationResponseDTO accounts = rpcClient.AccountInformation.GetClientAndTradingAccount(); PriceDTO marketInfo = GetMarketInfo(_CFDmarketId); var trade = new NewTradeOrderRequestDTO() { AuditId = marketInfo.AuditId, AutoRollover = false, BidPrice = marketInfo.Bid, Close = null, Currency = null, Direction = "buy", IfDone = null, MarketId = marketInfo.MarketId, OfferPrice = marketInfo.Offer, Quantity = 1, QuoteId = null, TradingAccountId = accounts.CFDAccount.TradingAccountId }; var order = rpcClient.TradesAndOrders.Trade(trade); rpcClient.MagicNumberResolver.ResolveMagicNumbers(order); Assert.AreEqual("Accepted", order.Status_Resolved); var update = new UpdateTradeOrderRequestDTO { OrderId = order.OrderId, MarketId = trade.MarketId, Currency = trade.Currency, IfDone = new[] { new ApiIfDoneDTO { Stop = new ApiStopLimitOrderDTO { TriggerPrice = marketInfo.Offer + 10, Direction = "sell", IfDone = null, MarketId = marketInfo.MarketId, Quantity = 1, TradingAccountId = accounts.CFDAccount.TradingAccountId } } }, AuditId = trade.AuditId, AutoRollover = trade.AutoRollover, BidPrice = trade.BidPrice, Close = trade.Close, Direction = trade.Direction, OfferPrice = trade.OfferPrice, Quantity = trade.Quantity, QuoteId = trade.QuoteId, TradingAccountId = trade.TradingAccountId }; var response = rpcClient.TradesAndOrders.UpdateTrade(update); }
public void CanConsumeTradeMarginStream() { var tradeMarginListener = _streamingClient.BuildTradeMarginListener(); // set up a handler to respond to stream events var gate = new AutoResetEvent(false); TradeMarginDTO actual = null; Stopwatch sw = new Stopwatch(); sw.Start(); tradeMarginListener.MessageReceived += (s, e) => { Console.WriteLine( "-----------------------------------------------"); sw.Stop(); actual = e.Data; Console.WriteLine("event received in {0} seconds", TimeSpan.FromMilliseconds(sw.ElapsedMilliseconds)); Console.WriteLine(actual.ToStringWithValues()); Console.WriteLine( "-----------------------------------------------"); gate.Set(); }; // place a trade to give the margin listener something to listen to AccountInformationResponseDTO accounts = _authenticatedClient.AccountInformation.GetClientAndTradingAccount(); PriceDTO marketInfo = GetMarketInfo(80905); NewTradeOrderRequestDTO trade = new NewTradeOrderRequestDTO() { AuditId = marketInfo.AuditId, AutoRollover = false, BidPrice = marketInfo.Bid, Close = null, Currency = null, Direction = "buy", IfDone = null, MarketId = marketInfo.MarketId, OfferPrice = marketInfo.Offer, Quantity = 1, QuoteId = null, TradingAccountId = accounts.SpreadBettingAccount.TradingAccountId }; var response = _authenticatedClient.TradesAndOrders.Trade(trade); gate.WaitOne(50000); _streamingClient.TearDownListener(tradeMarginListener); // close the tradeMarginListener //marketInfo = GetMarketInfo(80905); //int orderId = response.OrderId; //trade = new NewTradeOrderRequestDTO() //{ // AuditId = marketInfo.AuditId, // AutoRollover = false, // BidPrice = marketInfo.Bid, // Close = new int[] { orderId }, // Currency = null, // Direction = "sell", // IfDone = null, // MarketId = marketInfo.MarketId, // OfferPrice = marketInfo.Offer, // Quantity = 1, // QuoteId = null, // TradingAccountId = accounts.SpreadBettingAccount.TradingAccountId //}; //_authenticatedClient.TradesAndOrders.Trade(trade); Assert.IsNotNull(actual, "did not get a streaming event"); }