Exemple #1
0
        public async Task <WebCallResult <Order> > PlaceOrderAsync(PlaceOrderRequest placeOrderRequest, CancellationToken ct = default)
        {
            placeOrderRequest.Symbol.ValidateNotNull(nameof(placeOrderRequest.Symbol));
            var parameters = placeOrderRequest.AsDictionary();
            var result     = await SendRequestAsync <Order>(GetUrl(OrderEndpoint), HttpMethod.Post, ct, parameters, true, false).ConfigureAwait(false);

            if (result.Success)
            {
                OnOrderPlaced?.Invoke(result.Data);
            }
            return(result);
        }
Exemple #2
0
        /// <summary>
        /// Place a new order
        /// </summary>
        /// <param name="symbol">The symbol the order is on</param>
        /// <param name="side">The side of the order</param>
        /// <param name="type">The type of the order</param>
        /// <param name="quantity">The quantity of the order</param>
        /// <param name="clientOrderId">A client id to reference the order by</param>
        /// <param name="price">Price of the order:
        /// Limit=limit price,
        /// StopLoss=stop loss price,
        /// TakeProfit=take profit price,
        /// StopLossProfit=stop loss price,
        /// StopLossProfitLimit=stop loss price,
        /// StopLossLimit=stop loss trigger price,
        /// TakeProfitLimit=take profit trigger price,
        /// TrailingStop=trailing stop offset,
        /// TrailingStopLimit=trailing stop offset,
        /// StopLossAndLimit=stop loss price,
        /// </param>
        /// <param name="secondaryPrice">Secondary price of an order:
        /// StopLossProfit/StopLossProfitLimit=take profit price,
        /// StopLossLimit/TakeProfitLimit=triggered limit price,
        /// TrailingStopLimit=triggered limit offset,
        /// StopLossAndLimit=limit price</param>
        /// <param name="leverage">Desired leverage</param>
        /// <param name="startTime">Scheduled start time</param>
        /// <param name="expireTime">Expiration time</param>
        /// <param name="validateOnly">Only validate inputs, don't actually place the order</param>
        /// <param name="twoFactorPassword">Password or authentication app code if enabled</param>
        /// <param name="ct">Cancellation token</param>
        /// <returns>Placed order info</returns>
        public async Task <WebCallResult <KrakenPlacedOrder> > PlaceOrderAsync(
            string symbol,
            OrderSide side,
            OrderType type,
            decimal quantity,
            uint?clientOrderId       = null,
            decimal?price            = null,
            decimal?secondaryPrice   = null,
            decimal?leverage         = null,
            DateTime?startTime       = null,
            DateTime?expireTime      = null,
            bool?validateOnly        = null,
            string?twoFactorPassword = null,
            CancellationToken ct     = default)
        {
            symbol.ValidateKrakenSymbol();
            var parameters = new Dictionary <string, object>()
            {
                { "pair", symbol },
                { "type", JsonConvert.SerializeObject(side, new OrderSideConverter(false)) },
                { "ordertype", JsonConvert.SerializeObject(type, new OrderTypeConverter(false)) },
                { "volume", quantity.ToString(CultureInfo.InvariantCulture) },
                { "trading_agreement", "agree" }
            };

            parameters.AddOptionalParameter("price", price?.ToString(CultureInfo.InvariantCulture));
            parameters.AddOptionalParameter("userref", clientOrderId);
            parameters.AddOptionalParameter("price2", secondaryPrice?.ToString(CultureInfo.InvariantCulture));
            parameters.AddOptionalParameter("otp", twoFactorPassword ?? _otp);
            parameters.AddOptionalParameter("leverage", leverage?.ToString(CultureInfo.InvariantCulture));
            parameters.AddOptionalParameter("starttm", startTime.HasValue ? JsonConvert.SerializeObject(startTime.Value, new TimestampSecondsConverter()) : null);
            parameters.AddOptionalParameter("expiretm", expireTime.HasValue ? JsonConvert.SerializeObject(expireTime.Value, new TimestampSecondsConverter()) : null);
            if (validateOnly == true)
            {
                parameters.AddOptionalParameter("validate", true);
            }
            var result = await Execute <KrakenPlacedOrder>(GetUri("0/private/AddOrder"), HttpMethod.Post, ct, parameters, true).ConfigureAwait(false);

            if (result)
            {
                OnOrderPlaced?.Invoke(result.Data);
            }
            return(result);
        }
 internal void InvokeOrderPlaced(OrderId id)
 {
     OnOrderPlaced?.Invoke(id);
 }