Exemplo n.º 1
0
 public ReplaceOrderResponse ReplaceOrder(AccountId accountId, OrderSpecifier orderSpecifier, OrderRequest newOrder)
 => Execute <ReplaceOrderResponse>(new ReplaceOrderEndpoint()
 {
     AccountId      = accountId,
     OrderSpecifier = orderSpecifier,
     Order          = newOrder
 });
Exemplo n.º 2
0
        /// <summary>
        /// Replace an Order in an Account by simultaneously cancelling it and creating a replacement Order
        /// </summary>
        /// <param name="orderRequest">Specification of the replacing Order</param>
        /// <param name="orderSpecifier">The specification of an Order as referred to by clients. Either the Order’s OANDA-assigned OrderID or the Order’s client-provided ClientID prefixed by the “@” symbol</param>
        /// <returns></returns>
        public async Task <dynamic> PutReplaceOrder(OrderRequest orderRequest, OrderSpecifier orderSpecifier)
        {
            string path  = string.Format("accounts/{0}/orders/{1}", AccountID, orderSpecifier);
            string query = null;

            JObject jObject = JObject.FromObject(
                new { order = orderRequest },
                SerializerSetting
                );

            string jsonBody = JsonConvert.SerializeObject(jObject, JsonSerializerSetting);

            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));
                }
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Get details for a single Order in an Account.
        /// </summary>
        /// <param name="orderSpecifier">The Order Specifier [required].</param>
        /// <returns></returns>
        public async Task <Order> GetSpecificOrder(OrderSpecifier orderSpecifier)
        {
            string path  = string.Format("accounts/{0}/orders/{1}", AccountID, orderSpecifier);
            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())["order"].ToString();
                    return(JsonConvert.DeserializeObject <Order>(jsonString, ErrorHandlingSetting));
                }
            }
        }
Exemplo n.º 4
0
 public UpdateOrderClientExtensionsResponse UpdateOrderClientExtensions(AccountId accountId, OrderSpecifier orderSpecifier,
                                                                        ClientExtensions clientExtensions = null, ClientExtensions tradeClientExtensions = null)
 => Execute <UpdateOrderClientExtensionsResponse>(new UpdateOrderClientExtensionsEndpoint()
 {
     AccountId             = accountId,
     OrderSpecifier        = orderSpecifier,
     ClientExtensions      = clientExtensions,
     TradeClientExtensions = tradeClientExtensions
 });
Exemplo n.º 5
0
 public CancelPendingOrderResponse CancelOrder(AccountId accountId, OrderSpecifier orderSpecifier)
 => Execute <CancelPendingOrderResponse>(new CancelPendingOrderEndpoint()
 {
     AccountId      = accountId,
     OrderSpecifier = orderSpecifier
 });
Exemplo n.º 6
0
 public GetOrderDetailsResponse GetOrderDetails(AccountId accountId, OrderSpecifier orderSpecifier)
 => Execute <GetOrderDetailsResponse>(new GetOrderEndpoint()
 {
     AccountId      = accountId,
     OrderSpecifier = orderSpecifier
 });