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 void SetupFixture()
 {
     _rpcClient       = BuildRpcClient();
     _streamingClient = _rpcClient.CreateStreamingClient();
     _CFDmarketId     = GetAvailableCFDMarkets(_rpcClient)[0].MarketId;
     _accounts        = _rpcClient.AccountInformation.GetClientAndTradingAccount();
 }
 public void SetupFixture()
 {
     _rpcClient = BuildRpcClient();
     _streamingClient = _rpcClient.CreateStreamingClient();
     _CFDmarketId = GetAvailableCFDMarkets(_rpcClient)[0].MarketId;
     _accounts = _rpcClient.AccountInformation.GetClientAndTradingAccount();
 }
示例#4
0
 private static int GetTradingAccountId(Client client, int marketId, AccountInformationResponseDTO accountInfo)
 {
     GetMarketInformationResponseDTO marketInfo = client.Market.GetMarketInformation(marketId.ToString());
     bool isCfd = marketInfo.MarketInformation.Name.EndsWith("CFD");
     ApiTradingAccountDTO tradingAccount = isCfd
                                               ? accountInfo.TradingAccounts[0]
                                               : accountInfo.TradingAccounts[1];
     return tradingAccount.TradingAccountId;
 }
示例#5
0
 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 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();
 }
示例#7
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);
        }
示例#8
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);
        }
        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);
        }
示例#10
0
        private int Trade(Client client, AccountInformationResponseDTO accountInfo, int marketId, PriceDTO price,
            decimal quantity, string direction, IEnumerable<int> closeOrderIds)
        {
            var tradeRequest = new NewTradeOrderRequestDTO
            {
                MarketId = marketId,
                Quantity = quantity,
                Direction = direction,
                TradingAccountId = accountInfo.SpreadBettingAccount.TradingAccountId,
                AuditId = price.AuditId,
                BidPrice = price.Bid,
                OfferPrice = price.Offer,
                Close = closeOrderIds.ToArray(),
            };

            var resp = client.TradesAndOrders.Trade(tradeRequest);

            if (resp.OrderId == 0)
            {
                client.MagicNumberResolver.ResolveMagicNumbers(resp);
                var message = GetResponseDescription(resp);
                throw new ApplicationException(message);
            }

            return resp.OrderId;
        }