/// <summary> /// Places an order /// </summary> /// <param name="accountId">The account to place the order for</param> /// <param name="symbol">The symbol to place the order for</param> /// <param name="orderType">The type of the order</param> /// <param name="amount">The amount of the order</param> /// <param name="price">The price of the order. Should be omitted for market orders</param> /// <returns></returns> public async Task <WebCallResult <long> > PlaceOrderAsync(long accountId, string symbol, HuobiOrderType orderType, decimal amount, decimal?price = null) { if (orderType == HuobiOrderType.StopLimitBuy || orderType == HuobiOrderType.StopLimitSell) { return(WebCallResult <long> .CreateErrorResult(new ArgumentError("Stop limit orders not supported by API"))); } var parameters = new Dictionary <string, object> { { "account-id", accountId }, { "amount", amount }, { "symbol", symbol }, { "type", JsonConvert.SerializeObject(orderType, new OrderTypeConverter(false)) } }; // If precision of the symbol = 1 (eg has to use whole amounts, 1,2,3 etc) Huobi doesn't except the .0 postfix (1.0) for amount // Issue at the Huobi side if (amount % 1 == 0) { parameters["amount"] = amount.ToString(CultureInfo.InvariantCulture); } parameters.AddOptionalParameter("price", price); var result = await ExecuteRequest <HuobiBasicResponse <long> >(GetUrl(PlaceOrderEndpoint, "1"), "POST", parameters, true).ConfigureAwait(false); return(new WebCallResult <long>(result.ResponseStatusCode, result.ResponseHeaders, result.Data?.Data ?? 0, result.Error)); }
/// <summary> /// Places an order /// </summary> /// <param name="accountId">The account to place the order for</param> /// <param name="symbol">The symbol to place the order for</param> /// <param name="orderType">The type of the order</param> /// <param name="amount">The amount of the order</param> /// <param name="price">The price of the order. Should be omitted for market orders</param> /// <returns></returns> public WebCallResult <long> PlaceOrder(long accountId, string symbol, HuobiOrderType orderType, decimal amount, decimal?price = null) => PlaceOrderAsync(accountId, symbol, orderType, amount, price).Result;
/// <summary> /// Places an order /// </summary> /// <param name="accountId">The account to place the order for</param> /// <param name="symbol">The symbol to place the order for</param> /// <param name="orderType">The type of the order</param> /// <param name="amount">The amount of the order</param> /// <param name="price">The price of the order. Should be omitted for market orders</param> /// <param name="ct">Cancellation token</param> /// <returns></returns> public async Task <WebCallResult <long> > PlaceOrderAsync(long accountId, string symbol, HuobiOrderType orderType, decimal amount, decimal?price = null, CancellationToken ct = default) { symbol = symbol.ValidateHuobiSymbol(); if (orderType == HuobiOrderType.StopLimitBuy || orderType == HuobiOrderType.StopLimitSell) { throw new ArgumentException("Stop limit orders not supported by API"); } var parameters = new Dictionary <string, object> { { "account-id", accountId }, { "amount", amount }, { "symbol", symbol }, { "type", JsonConvert.SerializeObject(orderType, new OrderTypeConverter(false)) } }; // If precision of the symbol = 1 (eg has to use whole amounts, 1,2,3 etc) Huobi doesn't except the .0 postfix (1.0) for amount // Issue at the Huobi side if (amount % 1 == 0) { parameters["amount"] = amount.ToString(CultureInfo.InvariantCulture); } parameters.AddOptionalParameter("price", price); return(await SendHuobiRequest <long>(GetUrl(PlaceOrderEndpoint, "1"), HttpMethod.Post, ct, parameters, true).ConfigureAwait(false)); }
/// <summary> /// Places an order /// </summary> /// <param name="accountId">The account to place the order for</param> /// <param name="symbol">The symbol to place the order for</param> /// <param name="orderType">The type of the order</param> /// <param name="amount">The amount of the order</param> /// <param name="price">The price of the order. Should be omitted for market orders</param> /// <returns></returns> public async Task <CallResult <long> > PlaceOrderAsync(long accountId, string symbol, HuobiOrderType orderType, decimal amount, decimal?price = null) { var parameters = new Dictionary <string, object> { { "account-id", accountId }, { "amount", amount }, { "symbol", symbol }, { "type", JsonConvert.SerializeObject(orderType, new OrderTypeConverter(false)) } }; parameters.AddOptionalParameter("price", price); var result = await ExecuteRequest <HuobiBasicResponse <long> >(GetUrl(PlaceOrderEndpoint, "1"), "POST", parameters, true).ConfigureAwait(false); return(new CallResult <long>(result.Data?.Data ?? 0, result.Error)); }
/// <summary> /// Places an order /// </summary> /// <param name="accountId">The account to place the order for</param> /// <param name="symbol">The symbol to place the order for</param> /// <param name="orderType">The type of the order</param> /// <param name="amount">The amount of the order</param> /// <param name="price">The price of the order. Should be omitted for market orders</param> /// <param name="ct">Cancellation token</param> /// <returns></returns> public WebCallResult <long> PlaceOrder(long accountId, string symbol, HuobiOrderType orderType, decimal amount, decimal?price = null, CancellationToken ct = default) => PlaceOrderAsync(accountId, symbol, orderType, amount, price, ct).Result;