Example #1
0
 public CloseTradeResponse CloseTradeAllUnits(AccountId accountId, TradeSpecifier tradeSpecifier)
 => Execute <CloseTradeResponse>(new CloseTradeEndpoint()
 {
     AccountId      = accountId,
     TradeSpecifier = tradeSpecifier,
     CloseAll       = true
 });
Example #2
0
        /// <summary>
        /// Create, replace and cancel a Trade’s dependent Orders (Take Profit, Stop Loss and Trailing Stop Loss) through the Trade itself.
        /// </summary>
        /// <param name="specifier"></param>
        /// <param name="clientExtensions"></param>
        /// <returns></returns>
        public async Task <dynamic> PutTradeOrder(TradeSpecifier specifier, PutTradeOrderRequest request)
        {
            JObject jObject = JObject.FromObject(
                request,
                SerializerSetting
                );

            string path     = string.Format("accounts/{0}/trades/{1}/orders", AccountID, specifier);
            string query    = null;
            string jsonBody = JsonConvert.SerializeObject(jObject, Formatting.Indented);

            using (HttpResponseMessage response = await RequestAsync(EHostAPIType.REST, HttpMethod.Put, path, query, jsonBody))
            {
                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 = await new StreamReader(stream).ReadToEndAsync();
                    return(JsonConvert.DeserializeObject <dynamic>(jsonString, ErrorHandlingSetting));
                }
            }
        }
Example #3
0
 public CloseTradeResponse CloseTradeByAmount(AccountId accountId, TradeSpecifier tradeSpecifier, decimal units)
 => Execute <CloseTradeResponse>(new CloseTradeEndpoint()
 {
     AccountId      = accountId,
     TradeSpecifier = tradeSpecifier,
     CloseAmount    = units
 });
Example #4
0
        /// <summary>
        /// Get the details of a specific Trade in an Account.
        /// </summary>
        /// <param name="specifier">Specifier for the Trade [required].</param>
        /// <returns></returns>
        public async Task <Trade> GetSpecificTrade(TradeSpecifier specifier)
        {
            string path  = string.Format("accounts/{0}/trades/{1}", AccountID, specifier);
            string query = null;

            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())["trade"].ToString();
                    return(JsonConvert.DeserializeObject <Trade>(jsonString, ErrorHandlingSetting));
                }
            }
        }
Example #5
0
        /// <summary>
        /// Close (partially or fully) a specific open Trade in an Account
        /// </summary>
        /// <param name="specifier">Specifier for the Trade [required].</param>
        /// <param name="units">
        /// Indication of how much of the Trade to close. Either the string “ALL”
        /// (indicating that all of the Trade should be closed), or a DecimalNumber
        /// representing the number of units of the open Trade to Close using a
        /// TradeClose MarketOrder. The units specified must always be positive, and
        /// the magnitude of the value cannot exceed the magnitude of the Trade’s
        /// open units.
        /// </param>
        /// <returns></returns>
        public async Task <dynamic> PutCloseTrade(TradeSpecifier specifier, string units = "ALL")
        {
            NameValueCollection queryNVC = new NameValueCollection()
            {
                { "units", units }
            };
            string path  = string.Format("accounts/{0}/trades/{1}/close", AccountID, specifier);
            string query = QueryFromNVC(queryNVC);

            using (HttpResponseMessage response = await RequestAsync(EHostAPIType.REST, HttpMethod.Put, 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())["trade"].ToString();
                    return(JsonConvert.DeserializeObject <Trade>(jsonString, ErrorHandlingSetting));
                }
            }
        }
Example #6
0
        public SetTradeOrdersResponse UpdateTradeOrder(AccountId accountId, TradeSpecifier tradeSpecifier, IExitOrderDetail exitOrderDetail)
        {
            SetTradeOrdersEndpoint endpoint = new SetTradeOrdersEndpoint()
            {
                AccountId      = accountId,
                TradeSpecifier = tradeSpecifier
            };

            if (exitOrderDetail is StopLossDetails)
            {
                endpoint.StopLoss = (StopLossDetails)exitOrderDetail;
            }
            else if (exitOrderDetail is TakeProfitDetails)
            {
                endpoint.TakeProfit = (TakeProfitDetails)exitOrderDetail;
            }
            else if (exitOrderDetail is TrailingStopLossDetails)
            {
                endpoint.TrailingStopLoss = (TrailingStopLossDetails)exitOrderDetail;
            }

            return(Execute <SetTradeOrdersResponse>(endpoint));
        }
Example #7
0
 /// <summary>
 /// Close (partially or fully) a specific open Trade in an Account
 /// </summary>
 /// <param name="specifier">Specifier for the Trade [required].</param>
 /// <param name="units">
 /// Indication of how much of the Trade to close. Either the string “ALL”
 /// (indicating that all of the Trade should be closed), or a DecimalNumber
 /// representing the number of units of the open Trade to Close using a
 /// TradeClose MarketOrder. The units specified must always be positive, and
 /// the magnitude of the value cannot exceed the magnitude of the Trade’s
 /// open units.
 /// </param>
 /// <returns></returns>
 public async Task <dynamic> PutCloseTrade(TradeSpecifier specifier, double units)
 {
     return(await PutCloseTrade(specifier, units.ToString()));
 }
Example #8
0
 public UpdateTradeClientExtensionsResponse UpdateTradeClientExtensions(AccountId accountId, TradeSpecifier tradeSpecifier, ClientExtensions newExtensions)
 => Execute <UpdateTradeClientExtensionsResponse>(new UpdateTradeClientExtensionsEndpoint()
 {
     AccountId             = accountId,
     TradeSpecifier        = tradeSpecifier,
     TradeClientExtensions = newExtensions
 });
Example #9
0
 public GetTradeResponse GetTrade(AccountId accountId, TradeSpecifier tradeSpecifier)
 => Execute <GetTradeResponse>(new GetTradeEndpoint()
 {
     AccountId      = accountId,
     TradeSpecifier = tradeSpecifier
 });