Exemplo n.º 1
0
        public void GenerateAPIException()
        {
            var client = new Client("https://ciapi.cityindex.com/tradingapi", "ciapi.portable");

            var t = client.LoginAsync("foo", "bar");

            try
            {
                t.Wait();
            }
            catch (AggregateException ex)
            {
                // TODO: make sure exceptions are constructed consistently so that
                // end user can easily respond.
                // probably a good strategy is when we catch and exception in the client,
                // if it is an aggregate with a single inner, just set exception to the inner, not the aggregate.

                var flattened = ex.Flatten();
                Debugger.Break();

            }
        }
Exemplo n.º 2
0
        public void CanLoginToCI()
        {
            var client = new Client("https://ciapi.cityindex.com/tradingapi", "ciapi.portable");


            var loginTask = client.LoginAsync("xx663766", "password1");

            // simple block till completion. Async completion can be used by getting the awaiter or setting a .ContinueWith task

            loginTask.Wait();

            // the response dto is available in loginTask.Result if 
            // you want to check passwordchangerequired etc but the client
            // has already intercepted the response and set it's SessionId
            // and fetched user's AccountInformation


            Assert.AreEqual("xx663766", client.Username);
            Assert.IsNotNullOrEmpty(client.SessionId);
            Assert.IsNotNull(client.CurrentAccountInformation);

            var logOutTask = client.LogOutAsync();

            logOutTask.Wait();


            Assert.IsNull(client.SessionId);
            Assert.IsNull(client.Username);
            Assert.IsNull(client.CurrentAccountInformation);
        }
Exemplo n.º 3
0
        /// <summary>
        ///  [DESCRIPTION MISSING]
        /// </summary>
        public Client(string rpcUri, string appKey)
        {
        AppKey=appKey;
        _client=this;
        ApiBaseUrl = rpcUri;

            this. Authentication = new _Authentication(this);
            this. PriceHistory = new _PriceHistory(this);
            this. News = new _News(this);
            this. CFDMarkets = new _CFDMarkets(this);
            this. SpreadMarkets = new _SpreadMarkets(this);
            this. Market = new _Market(this);
            this. Preference = new _Preference(this);
            this. TradesAndOrders = new _TradesAndOrders(this);
            this. AccountInformation = new _AccountInformation(this);
            this. Messaging = new _Messaging(this);
            this. Watchlist = new _Watchlist(this);
            this. ClientApplication = new _ClientApplication(this);
        }
Exemplo n.º 4
0
 /// <summary>
 ///  [DESCRIPTION MISSING]
 /// </summary>
     public _Preference(Client client){ this._client = client;}
Exemplo n.º 5
0
 /// <summary>
 ///  [DESCRIPTION MISSING]
 /// </summary>
     public _SpreadMarkets(Client client){ this._client = client;}
Exemplo n.º 6
0
 /// <summary>
 ///  [DESCRIPTION MISSING]
 /// </summary>
     public _Market(Client client){ this._client = client;}
Exemplo n.º 7
0
 /// <summary>
 ///  [DESCRIPTION MISSING]
 /// </summary>
     public _News(Client client){ this._client = client;}
Exemplo n.º 8
0
 /// <summary>
 ///  [DESCRIPTION MISSING]
 /// </summary>
     public _Authentication(Client client){ this._client = client;}
Exemplo n.º 9
0
 /// <summary>
 ///  [DESCRIPTION MISSING]
 /// </summary>
     public _ClientApplication(Client client){ this._client = client;}
Exemplo n.º 10
0
 /// <summary>
 ///  [DESCRIPTION MISSING]
 /// </summary>
     public _PriceHistory(Client client){ this._client = client;}
Exemplo n.º 11
0
 /// <summary>
 ///  [DESCRIPTION MISSING]
 /// </summary>
     public _Watchlist(Client client){ this._client = client;}
Exemplo n.º 12
0
 /// <summary>
 ///  [DESCRIPTION MISSING]
 /// </summary>
     public _Messaging(Client client){ this._client = client;}
Exemplo n.º 13
0
 /// <summary>
 ///  [DESCRIPTION MISSING]
 /// </summary>
     public _AccountInformation(Client client){ this._client = client;}
Exemplo n.º 14
0
        public void CanEnqueueRequestAsync()
        {
            var entry = new Entry
                {
                    Request = new Request
                        {
                            Method = "POST",
                            Url = "http://posttestserver.com/post.php?dump&a={a}",
                            QueryString = new QueryString
                                {
                                    new NameValuePair
                                        {
                                            Name = "a",
                                            Value = "avalue"
                                        }
                                },
                            PostData = new PostData
                                {
                                    MimeType = "text/plain",
                                    Params = new Parameters
                                        {
                                            // naked
                                            new NameValuePair {Name = string.Empty, Value = "fooo"},
                                            //named
                                            new NameValuePair {Name = "param", Value = "paramValue"}
                                        }
                                },
                            Headers = new Headers
                                {
                                    new NameValuePair
                                        {
                                            Name = "arbitrary-header",
                                            Value = "header value"
                                        }
                                }
                        }
                };


            var client = new Client("https://ciapi.cityindex.com/tradingapi", "ciapi.portable");

            Task<Entry> t = client.EnqueueRequestAsync(entry);

            // this will throw if exceptions occur in task
            t.Wait();



            Entry result = t.Result;

            Response response = result.Response;


            string responseText = response.Content.Text;

            Assert.AreEqual(response.Content.Size, responseText.Length);

            Assert.IsTrue(responseText.Contains("HTTP_ARBITRARY_HEADER = header value\n"));
            Assert.IsTrue(responseText.Contains("CONTENT_TYPE = text/plain\n"));
            Assert.IsTrue(responseText.Contains("QUERY_STRING = dump&a=avalue\n"));
            Assert.IsTrue(responseText.Contains("== Begin post body ==\nfooo&param=paramValue\n== End post body ==\n"));
            // 
        }
Exemplo n.º 15
0
 /// <summary>
 ///  [DESCRIPTION MISSING]
 /// </summary>
     public _CFDMarkets(Client client){ this._client = client;}
Exemplo n.º 16
0
        // Constructor
        public MainPage()
        {
            InitializeComponent();

            Client = new Client("http://ciapi.cityindex.com/tradingapi", "portable app");
        }
Exemplo n.º 17
0
 /// <summary>
 ///  [DESCRIPTION MISSING]
 /// </summary>
     public _TradesAndOrders(Client client){ this._client = client;}