Beispiel #1
0
        /// <summary>
        /// Get a list of Trades for an Account.
        /// </summary>
        /// <param name="instrument">The instrument to filter the requested Trades by.</param>
        /// <param name="ids">List of Trade IDs to retrieve. </param>
        /// <param name="state">The state to filter the requested Trades by. [default=OPEN].</param>
        /// <param name="count">The maximum number of Trades to return. [default=50, maximum=500]</param>
        /// <param name="beforeID">The maximum Trade ID to return. If not provided the most recent Trades in the Account are returned.</param>
        /// <returns></returns>
        public async Task <List <Trade> > GetTrades(
            InstrumentName instrument,
            List <TradeID> ids      = null,
            ETradeStateFilter state = ETradeStateFilter.OPEN,
            int count        = 50,
            TradeID beforeID = null
            )
        {
            #region queryNVC
            NameValueCollection queryNVC = new NameValueCollection()
            {
                { "state", state.ToString() },
                { "count", count.ToString() }
            };
            if (ids != null)
            {
                queryNVC["ids"] = string.Join(",", ids);
            }
            if (instrument != null)
            {
                queryNVC["instrument"] = instrument;
            }
            if (beforeID != null)
            {
                queryNVC["beforeID"] = beforeID;
            }
            #endregion

            string path  = string.Format("accounts/{0}/trades", AccountID);
            string query = QueryFromNVC(queryNVC);

            using (HttpResponseMessage response = await RequestAsync(EHostAPIType.REST, HttpMethod.Get, path, query))
            {
                if (response.StatusCode != HttpStatusCode.OK)
                {
                    throw new HttpRequestException(JObject.Parse(await response.Content.ReadAsStringAsync())["errorMessage"].ToString());
                }

                using (Stream stream = await response.Content.ReadAsStreamAsync())
                {
                    string jsonString = JObject.Parse(await new StreamReader(stream).ReadToEndAsync())["trades"].ToString();
                    return(JsonConvert.DeserializeObject <List <Trade> >(jsonString));
                }
            }
        }
 public TradeStateFilter(ETradeStateFilter value)
 {
     this.Value = value;
 }