Exemplo n.º 1
0
        private static void DoPolling()
        {
            var client = new Client(Const.RPC_URI, Const.STREAMING_URI, "Test.{B4E415A7-C453-4867-BDD1-C77ED345777B}");
            try
            {
                client.AppKey = "Test";
                client.StartMetrics();

                client.LogIn(Const.USERNAME, Const.PASSWORD);

                for (int i = 0; i < 10; i++)
                {
                    var accountInfo = client.AccountInformation.GetClientAndTradingAccount();
                    client.TradesAndOrders.ListOpenPositions(accountInfo.CFDAccount.TradingAccountId);
                    Thread.Sleep(1000);
                }

                client.LogOut();
            }
            catch (Exception exc)
            {
                Trace.WriteLine(exc);
            }
            finally
            {
                client.Dispose();
            }
        }
Exemplo n.º 2
0
        public MainPage()
        {


            InitializeComponent();

            Dispatcher.BeginInvoke(() =>
            {
                StartButton.IsEnabled = false;
                StopButton.IsEnabled = false;
            });


            // need to set up the serializer to be used by stream listeners
            StreamingClientFactory.SetSerializer(new Serializer());

            // build an rpc client and log it in.
            rpcClient = new Client(new Uri(StaticTestConfig.RpcUrl), new Uri(StaticTestConfig.StreamingUrl), StaticTestConfig.AppKey);
            
            rpcClient.StartMetrics();
            // get a session from the rpc client
            rpcClient.BeginLogIn(StaticTestConfig.ApiUsername, StaticTestConfig.ApiPassword, ar =>
                {
                    rpcClient.EndLogIn(ar);

                    rpcClient.MagicNumberResolver.PreloadMagicNumbersAsync();

                    Debug.WriteLine("creating client");

                    // build a streaming client.
                    _streamingClient = StreamingClientFactory.CreateStreamingClient(new Uri(StaticTestConfig.StreamingUrl), StaticTestConfig.ApiUsername, rpcClient.Session);

                    Debug.WriteLine("connecting client");

                    // note: due to internal changes the 'connect' method
                    // name is a misnomer: no actual network activity is occuring,
                    // only the building of the necessary client connections for 
                    // each of the published data adapters. Actual connection is 
                    // performed on demand for each adapter. This minimizes startup time.

                    // the upside to this is that there is no need to run .Connect in a separate thread.



                    Debug.WriteLine("client connected");


                    // from this point there should be no need to stop, disconnect or dispose of the 
                    // client instance. But if you choose to disconnect a StreamingClient, it should
                    // be disposed and reinstantiated. it is a one use object at this point as this is 
                    // the only usage pattern presented in the sample code.

                    Dispatcher.BeginInvoke(() =>
                        {
                            listBox1.Items.Add("logged in");


                            StartButton.IsEnabled = true;
                            StopButton.IsEnabled = false;
                        });

                }, null);

        }