示例#1
0
        public virtual Order Deserialize(string json, IKucoinApiUser user)
        {
            Throw.IfNullOrWhiteSpace(json, nameof(json));
            Throw.IfNull(user, nameof(user));

            return(FillOrder(new Order(user), JObject.Parse(json)));
        }
示例#2
0
        public Task SubscribeAndStreamAsync(IKucoinApiUser user, Action <AccountInfoCacheEventArgs> callback, CancellationToken token = default)
        {
            Throw.IfNull(user, nameof(user));

            base.LinkTo(Client, callback);

            return(Client.SubscribeAndStreamAsync(user, ClientCallback, token));
        }
示例#3
0
        public virtual IEnumerable <Order> DeserializeMany(string json, IKucoinApiUser user)
        {
            Throw.IfNullOrWhiteSpace(json, nameof(json));
            Throw.IfNull(user, nameof(user));

            return(JArray.Parse(json)
                   .Select(item => FillOrder(new Order(user), item))
                   .ToArray());
        }
示例#4
0
        public override void Subscribe(string listenKey, IKucoinApiUser user, Action <UserDataEventArgs> callback)
        {
            Throw.IfNull(user, nameof(user));

            // Ensure only one user is subscribed.
            if (ListenKeys.Count > 0 && !ListenKeys.Single().Value.Equals(user))
            {
                throw new InvalidOperationException($"{nameof(SingleUserDataWebSocketClient)}: Can only subscribe to a single a user.");
            }

            base.Subscribe(listenKey, user, callback);
        }
示例#5
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="user">The user.</param>
        /// <param name="commissions">The account commissions.</param>
        /// <param name="status">The account status.</param>
        /// <param name="time">The update time.</param>
        /// <param name="balances">The account balances.</param>
        public AccountInfo(IKucoinApiUser user, AccountCommissions commissions, AccountStatus status, DateTime time, IEnumerable <AccountBalance> balances = null)
        {
            Throw.IfNull(user, nameof(user));
            Throw.IfNull(commissions, nameof(commissions));
            Throw.IfNull(status, nameof(status));

            User        = user;
            Commissions = commissions;
            Status      = status;
            Time        = time;

            Balances = balances ?? new AccountBalance[] { };
        }
示例#6
0
        public async Task SignAsync(KucoinHttpRequest request, IKucoinApiUser user, CancellationToken token = default)
        {
            Throw.IfNull(request, nameof(request));
            Throw.IfNull(user, nameof(user));

            var timestamp = TimestampProvider != null
                ? await TimestampProvider.GetTimestampAsync(this, token).ConfigureAwait(false)
                : DateTimeOffset.UtcNow.ToUnixTimeMilliseconds();

            request.AddParameter("timestamp", timestamp);

            var signature = user.Sign(request.TotalParams);

            request.AddParameter("signature", signature);
        }
示例#7
0
        public virtual void Subscribe(string listenKey, IKucoinApiUser user, Action <UserDataEventArgs> callback)
        {
            Throw.IfNullOrWhiteSpace(listenKey, nameof(listenKey));
            Throw.IfNull(user, nameof(user));

            Logger?.LogDebug($"{nameof(UserDataWebSocketClient)}.{nameof(Subscribe)}: \"{listenKey}\" (callback: {(callback == null ? "no" : "yes")}).  [thread: {Thread.CurrentThread.ManagedThreadId}]");

            // Subscribe callback (if provided) to listen key.
            SubscribeStream(listenKey, callback);

            // If listen key is new.
            // ReSharper disable once InvertIf
            if (!ListenKeys.ContainsKey(listenKey))
            {
                // If a listen key exists with user.
                if (ListenKeys.Any(_ => _.Value.Equals(user)))
                {
                    throw new InvalidOperationException($"{nameof(UserDataWebSocketClient)}.{nameof(Subscribe)}: A listen key is already subscribed for this user.");
                }

                // Add listen key and user (for stream event handling).
                ListenKeys[listenKey] = user;
            }
        }
示例#8
0
        /// <summary>
        /// Send in a new order.
        /// </summary>
        /// <param name="client"></param>
        /// <param name="user"></param>
        /// <param name="symbol"></param>
        /// <param name="side"></param>
        /// <param name="type"></param>
        /// <param name="quantity"></param>
        /// <param name="price"></param>
        /// <param name="newClientOrderId">A unique id for the order. Automatically generated if not sent.</param>
        /// <param name="timeInForce"></param>
        /// <param name="stopPrice">Used with STOP_LOSS, STOP_LOSS_LIMIT, TAKE_PROFIT, and TAKE_PROFIT_LIMIT orders.</param>
        /// <param name="icebergQty">Used with iceberg orders.</param>
        /// <param name="recvWindow"></param>
        /// <param name="isTestOnly">If true, test new order creation and signature/recvWindow; creates and validates a new order but does not send it into the matching engine.</param>
        /// <param name="newOrderRespType">Set the response JSON.</param>
        /// <param name="token"></param>
        /// <returns></returns>
        public static async Task <string> PlaceOrderAsync(this IKucoinHttpClient client, IKucoinApiUser user, string symbol, OrderSide side, OrderType type, decimal quantity, decimal price, string newClientOrderId = null, TimeInForce?timeInForce = null, decimal stopPrice = 0, decimal icebergQty = 0, long recvWindow = default, bool isTestOnly = false, PlaceOrderResponseType newOrderRespType = PlaceOrderResponseType.Result, CancellationToken token = default)
        {
            Throw.IfNull(client, nameof(client));
            Throw.IfNull(user, nameof(user));
            Throw.IfNullOrWhiteSpace(symbol, nameof(symbol));

            if (quantity <= 0)
            {
                throw new ArgumentException("Order quantity must be greater than 0.", nameof(quantity));
            }

            if (recvWindow <= 0)
            {
                recvWindow = client.Options.RecvWindowDefault ?? 0;
            }

            if (user.RateLimiter != null)
            {
                await user.RateLimiter.DelayAsync(token : token)
                .ConfigureAwait(false);
            }

            var request = new KucoinHttpRequest($"/api/v3/order{(isTestOnly ? "/test" : string.Empty)}")
            {
                ApiKey = user.ApiKey
            };

            request.AddParameter("symbol", symbol.FormatSymbol());
            request.AddParameter("side", side.ToString().ToUpperInvariant());
            request.AddParameter("type", type.AsString());
            request.AddParameter("newOrderRespType", newOrderRespType.ToString().ToUpperInvariant());
            request.AddParameter("quantity", quantity);

            if (price > 0)
            {
                request.AddParameter("price", price);
            }

            if (timeInForce.HasValue)
            {
                request.AddParameter("timeInForce", timeInForce.ToString().ToUpperInvariant());
            }

            if (!string.IsNullOrWhiteSpace(newClientOrderId))
            {
                request.AddParameter("newClientOrderId", newClientOrderId);
            }

            if (stopPrice > 0)
            {
                request.AddParameter("stopPrice", stopPrice);
            }

            if (icebergQty > 0)
            {
                // Automatically set time-in-force to GTC if not set.
                if (!timeInForce.HasValue)
                {
                    timeInForce = TimeInForce.GTC;
                }

                if (timeInForce != TimeInForce.GTC)
                {
                    throw new KucoinApiException("Any order with an icebergQty MUST have timeInForce set to GTC.");
                }

                request.AddParameter("icebergQty", icebergQty);
            }

            if (recvWindow > 0)
            {
                request.AddParameter("recvWindow", recvWindow);
            }

            await client.SignAsync(request, user, token)
            .ConfigureAwait(false);

            return(await client.PostAsync(request, token)
                   .ConfigureAwait(false));
        }
示例#9
0
        /// <summary>
        /// Cancel an active order.
        /// </summary>
        /// <param name="client"></param>
        /// <param name="user"></param>
        /// <param name="symbol"></param>
        /// <param name="orderId"></param>
        /// <param name="origClientOrderId"></param>
        /// <param name="newClientOrderId">Used to uniquely identify this cancel. Automatically generated by default.</param>
        /// <param name="recvWindow"></param>
        /// <param name="token"></param>
        /// <returns></returns>
        public static async Task <string> CancelOrderAsync(this IKucoinHttpClient client, IKucoinApiUser user, string symbol, long orderId = KucoinApi.NullId, string origClientOrderId = null, string newClientOrderId = null, long recvWindow = default, CancellationToken token = default)
        {
            Throw.IfNull(client, nameof(client));
            Throw.IfNull(user, nameof(user));
            Throw.IfNullOrWhiteSpace(symbol, nameof(symbol));

            if (orderId < 0 && string.IsNullOrWhiteSpace(origClientOrderId))
            {
                throw new ArgumentException($"Either '{nameof(orderId)}' or '{nameof(origClientOrderId)}' must be provided, but both were invalid.");
            }

            if (recvWindow <= 0)
            {
                recvWindow = client.Options.RecvWindowDefault ?? 0;
            }

            if (user.RateLimiter != null)
            {
                await user.RateLimiter.DelayAsync(token : token)
                .ConfigureAwait(false);
            }

            var request = new KucoinHttpRequest("/api/v3/order")
            {
                ApiKey = user.ApiKey
            };

            request.AddParameter("symbol", symbol.FormatSymbol());

            if (orderId >= 0)
            {
                request.AddParameter("orderId", orderId);
            }

            if (!string.IsNullOrWhiteSpace(origClientOrderId))
            {
                request.AddParameter("origClientOrderId", origClientOrderId);
            }

            if (!string.IsNullOrWhiteSpace(newClientOrderId))
            {
                request.AddParameter("newClientOrderId", newClientOrderId);
            }

            if (recvWindow > 0)
            {
                request.AddParameter("recvWindow", recvWindow);
            }

            await client.SignAsync(request, user, token)
            .ConfigureAwait(false);

            return(await client.DeleteAsync(request, token)
                   .ConfigureAwait(false));
        }
示例#10
0
        /// <summary>
        /// Get the account status.
        /// </summary>
        /// <param name="client"></param>
        /// <param name="user"></param>
        /// <param name="token"></param>
        /// <returns></returns>
        public static async Task <string> GetAccountStatusAsync(this IKucoinHttpClient client, IKucoinApiUser user, CancellationToken token = default)
        {
            Throw.IfNull(client, nameof(client));

            if (client.RateLimiter != null)
            {
                await client.RateLimiter.DelayAsync(token : token)
                .ConfigureAwait(false);
            }

            var request = new KucoinHttpRequest("/wapi/v3/accountStatus.html")
            {
                ApiKey = user.ApiKey
            };

            await client.SignAsync(request, user, token)
            .ConfigureAwait(false);

            return(await client.GetAsync(request, token)
                   .ConfigureAwait(false));
        }
示例#11
0
        /// <summary>
        /// Close out a user data stream.
        /// </summary>
        /// <param name="client"></param>
        /// <param name="user"></param>
        /// <param name="listenKey"></param>
        /// <param name="token"></param>
        /// <returns></returns>
        public static Task <string> UserStreamCloseAsync(this IKucoinHttpClient client, IKucoinApiUser user, string listenKey, CancellationToken token = default)
        {
            Throw.IfNull(user, nameof(user));

            return(UserStreamCloseAsync(client, user.ApiKey, listenKey, token));
        }
示例#12
0
        /// <summary>
        /// Get the deposit history.
        /// </summary>
        /// <param name="client"></param>
        /// <param name="user"></param>
        /// <param name="asset"></param>
        /// <param name="status"></param>
        /// <param name="startTime"></param>
        /// <param name="endTime"></param>
        /// <param name="recvWindow"></param>
        /// <param name="token"></param>
        /// <returns></returns>
        public static async Task <string> GetDepositsAsync(this IKucoinHttpClient client, IKucoinApiUser user, string asset = null, DepositStatus?status = null, long startTime = default, long endTime = default, long recvWindow = default, CancellationToken token = default)
        {
            Throw.IfNull(client, nameof(client));
            Throw.IfNull(user, nameof(user));

            if (recvWindow <= 0)
            {
                recvWindow = client.Options.RecvWindowDefault ?? 0;
            }

            if (client.RateLimiter != null)
            {
                await client.RateLimiter.DelayAsync(token : token)
                .ConfigureAwait(false);
            }

            var request = new KucoinHttpRequest("/wapi/v3/depositHistory.html")
            {
                ApiKey = user.ApiKey
            };

            if (!string.IsNullOrWhiteSpace(asset))
            {
                request.AddParameter("asset", asset.FormatSymbol());
            }

            if (status.HasValue)
            {
                request.AddParameter("status", (int)status);
            }

            if (startTime > 0)
            {
                request.AddParameter("startTime", startTime);
            }

            if (endTime > 0)
            {
                request.AddParameter("endTime", endTime);
            }

            if (recvWindow > 0)
            {
                request.AddParameter("recvWindow", recvWindow);
            }

            await client.SignAsync(request, user, token)
            .ConfigureAwait(false);

            return(await client.GetAsync(request, token)
                   .ConfigureAwait(false));
        }
示例#13
0
 protected StopLimitOrder(IKucoinApiUser user)
     : base(user)
 {
 }
 /// <summary>
 ///
 /// </summary>
 /// <param name="manager"></param>
 /// <param name="user"></param>
 /// <param name="token"></param>
 /// <returns></returns>
 public static Task SubscribeAndStreamAsync(this IUserDataWebSocketManager manager, IKucoinApiUser user, CancellationToken token)
 => manager.SubscribeAndStreamAsync(user, null, token);
示例#15
0
        /// <summary>
        /// Get trades for a specific account and symbol.
        /// </summary>
        /// <param name="client"></param>
        /// <param name="user"></param>
        /// <param name="symbol"></param>
        /// <param name="fromId">TradeId to fetch from. Default gets most recent trades.</param>
        /// <param name="limit">Default 500; max 500.</param>
        /// <param name="recvWindow"></param>
        /// <param name="token"></param>
        /// <returns></returns>
        public static async Task <string> GetAccountTradesAsync(this IKucoinHttpClient client, IKucoinApiUser user, string symbol, long fromId = KucoinApi.NullId, int limit = default, long recvWindow = default, CancellationToken token = default)
        {
            Throw.IfNull(client, nameof(client));
            Throw.IfNull(user, nameof(user));
            Throw.IfNullOrWhiteSpace(symbol, nameof(symbol));

            if (recvWindow <= 0)
            {
                recvWindow = client.Options.RecvWindowDefault ?? 0;
            }

            if (client.RateLimiter != null)
            {
                await client.RateLimiter.DelayAsync(5, token)
                .ConfigureAwait(false);
            }

            var request = new KucoinHttpRequest("/api/v3/myTrades")
            {
                ApiKey = user.ApiKey
            };

            request.AddParameter("symbol", symbol.FormatSymbol());

            if (fromId >= 0)
            {
                request.AddParameter("fromId", fromId);
            }

            if (limit > 0)
            {
                request.AddParameter("limit", limit);
            }

            if (recvWindow > 0)
            {
                request.AddParameter("recvWindow", recvWindow);
            }

            await client.SignAsync(request, user, token)
            .ConfigureAwait(false);

            return(await client.GetAsync(request, token)
                   .ConfigureAwait(false));
        }
示例#16
0
 public TakeProfitOrder(IKucoinApiUser user)
     : base(user)
 {
 }
示例#17
0
 public StopLossLimitOrder(IKucoinApiUser user)
     : base(user)
 {
 }
 /// <summary>
 ///
 /// </summary>
 /// <param name="cache"></param>
 /// <param name="user"></param>
 /// <param name="token"></param>
 /// <returns></returns>
 public static Task SubscribeAndStreamAsync(this IAccountInfoCache cache, IKucoinApiUser user, CancellationToken token)
 => cache.SubscribeAndStreamAsync(user, null, token);
示例#19
0
        /// <summary>
        /// Get older (non-compressed) trades.
        /// </summary>
        /// <param name="api"></param>
        /// <param name="user"></param>
        /// <param name="symbol"></param>
        /// <param name="fromId"></param>
        /// <param name="limit"></param>
        /// <param name="token"></param>
        /// <returns></returns>
        public static Task <IEnumerable <Trade> > GetTradesFromAsync(this IKucoinApi api, IKucoinApiUser user, string symbol, long fromId, int limit = default, CancellationToken token = default)
        {
            Throw.IfNull(api, nameof(api));
            Throw.IfNull(user, nameof(user));

            return(api.GetTradesFromAsync(user.ApiKey, symbol, fromId, limit, token));
        }
示例#20
0
 public MarketOrder(IKucoinApiUser user)
     : base(user)
 {
 }
示例#21
0
        /// <summary>
        /// Get all open orders on a symbol or all symbols.
        /// </summary>
        /// <param name="client"></param>
        /// <param name="user"></param>
        /// <param name="symbol"></param>
        /// <param name="recvWindow"></param>
        /// <param name="token"></param>
        /// <returns></returns>
        public static async Task <string> GetOpenOrdersAsync(this IKucoinHttpClient client, IKucoinApiUser user, string symbol = null, long recvWindow = default, CancellationToken token = default)
        {
            Throw.IfNull(client, nameof(client));
            Throw.IfNull(user, nameof(user));

            if (recvWindow <= 0)
            {
                recvWindow = client.Options.RecvWindowDefault ?? 0;
            }

            if (client.RateLimiter != null)
            {
                var tradingSymbols = Symbol.Cache.Values.Count(s => s.Status == SymbolStatus.Trading);

                await client.RateLimiter
                .DelayAsync(string.IsNullOrWhiteSpace(symbol) && tradingSymbols > 1?tradingSymbols / 2 : 1, token)
                .ConfigureAwait(false);
            }

            var request = new KucoinHttpRequest("/api/v3/openOrders")
            {
                ApiKey = user.ApiKey
            };

            if (!string.IsNullOrWhiteSpace(symbol))
            {
                request.AddParameter("symbol", symbol.FormatSymbol());
            }

            if (recvWindow > 0)
            {
                request.AddParameter("recvWindow", recvWindow);
            }

            await client.SignAsync(request, user, token)
            .ConfigureAwait(false);

            return(await client.GetAsync(request, token)
                   .ConfigureAwait(false));
        }
示例#22
0
 public LimitOrder(IKucoinApiUser user)
     : base(user)
 {
 }
示例#23
0
        /// <summary>
        /// Get current account information.
        /// </summary>
        /// <param name="client"></param>
        /// <param name="user"></param>
        /// <param name="recvWindow"></param>
        /// <param name="token"></param>
        /// <returns></returns>
        public static async Task <string> GetAccountInfoAsync(this IKucoinHttpClient client, IKucoinApiUser user, long recvWindow = default, CancellationToken token = default)
        {
            Throw.IfNull(client, nameof(client));
            Throw.IfNull(user, nameof(user));

            if (recvWindow <= 0)
            {
                recvWindow = client.Options.RecvWindowDefault ?? 0;
            }

            if (client.RateLimiter != null)
            {
                await client.RateLimiter.DelayAsync(5, token)
                .ConfigureAwait(false);
            }

            var request = new KucoinHttpRequest("/api/v3/account")
            {
                ApiKey = user.ApiKey
            };

            if (recvWindow > 0)
            {
                request.AddParameter("recvWindow", recvWindow);
            }

            await client.SignAsync(request, user, token)
            .ConfigureAwait(false);

            return(await client.GetAsync(request, token)
                   .ConfigureAwait(false));
        }
示例#24
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="user"></param>
        /// <param name="symbol"></param>
        /// <param name="id"></param>
        /// <param name="clientOrderId"></param>
        /// <param name="price"></param>
        /// <param name="originalQuantity"></param>
        /// <param name="executedQuantity"></param>
        /// <param name="status"></param>
        /// <param name="timeInForce"></param>
        /// <param name="orderType"></param>
        /// <param name="orderSide"></param>
        /// <param name="stopPrice"></param>
        /// <param name="icebergQuantity"></param>
        /// <param name="time"></param>
        /// <param name="isWorking"></param>
        /// <param name="fills"></param>
        public Order(
            IKucoinApiUser user,
            string symbol,
            long id,
            string clientOrderId,
            decimal price,
            decimal originalQuantity,
            decimal executedQuantity,
            OrderStatus status,
            TimeInForce timeInForce,
            OrderType orderType,
            OrderSide orderSide,
            decimal stopPrice,
            decimal icebergQuantity,
            DateTime time,
            bool isWorking,
            IEnumerable <Fill> fills = null)
            : this(user)
        {
            Throw.IfNullOrWhiteSpace(symbol, nameof(symbol));

            if (id < 0)
            {
                throw new ArgumentException($"{nameof(Order)}: ID must not be less than 0.", nameof(id));
            }

            if (price < 0)
            {
                throw new ArgumentException($"{nameof(Order)}: price must not be less than 0.", nameof(price));
            }
            if (stopPrice < 0)
            {
                throw new ArgumentException($"{nameof(Order)}: price must not be less than 0.", nameof(stopPrice));
            }

            if (originalQuantity < 0)
            {
                throw new ArgumentException($"{nameof(Order)}: quantity must not be less than 0.", nameof(originalQuantity));
            }
            if (executedQuantity < 0)
            {
                throw new ArgumentException($"{nameof(Order)}: quantity must not be less than 0.", nameof(executedQuantity));
            }
            if (icebergQuantity < 0)
            {
                throw new ArgumentException($"{nameof(Order)}: quantity must not be less than 0.", nameof(icebergQuantity));
            }

            Symbol           = symbol.FormatSymbol();
            Id               = id;
            ClientOrderId    = clientOrderId;
            Price            = price;
            OriginalQuantity = originalQuantity;
            ExecutedQuantity = executedQuantity;
            Status           = status;
            TimeInForce      = timeInForce;
            Type             = orderType;
            Side             = orderSide;
            StopPrice        = stopPrice;
            IcebergQuantity  = icebergQuantity;
            Time             = time;
            IsWorking        = isWorking;

            Fills = fills ?? new Fill[] { };
        }
示例#25
0
        /// <summary>
        /// Submit a withdraw request.
        /// </summary>
        /// <param name="client"></param>
        /// <param name="user"></param>
        /// <param name="asset"></param>
        /// <param name="address"></param>
        /// <param name="addressTag"></param>
        /// <param name="amount"></param>
        /// <param name="name">A description of the address (optional).</param>
        /// <param name="recvWindow"></param>
        /// <param name="token"></param>
        /// <returns></returns>
        public static async Task <string> WithdrawAsync(this IKucoinHttpClient client, IKucoinApiUser user, string asset, string address, string addressTag, decimal amount, string name = null, long recvWindow = default, CancellationToken token = default)
        {
            Throw.IfNull(client, nameof(client));
            Throw.IfNull(user, nameof(user));
            Throw.IfNullOrWhiteSpace(asset, nameof(asset));
            Throw.IfNullOrWhiteSpace(address, nameof(address));

            if (amount <= 0)
            {
                throw new ArgumentException("Withdraw amount must be greater than 0.", nameof(amount));
            }

            if (recvWindow <= 0)
            {
                recvWindow = client.Options.RecvWindowDefault ?? 0;
            }

            if (client.RateLimiter != null)
            {
                await client.RateLimiter.DelayAsync(token : token)
                .ConfigureAwait(false);
            }

            var request = new KucoinHttpRequest("/wapi/v3/withdraw.html")
            {
                ApiKey = user.ApiKey
            };

            request.AddParameter("asset", asset.FormatSymbol());
            request.AddParameter("address", address);
            request.AddParameter("amount", amount);

            if (!string.IsNullOrWhiteSpace(addressTag))
            {
                request.AddParameter("addressTag", addressTag);
            }

            if (!string.IsNullOrWhiteSpace(name))
            {
                request.AddParameter("name", name);
            }

            if (recvWindow > 0)
            {
                request.AddParameter("recvWindow", recvWindow);
            }

            await client.SignAsync(request, user, token)
            .ConfigureAwait(false);

            return(await client.PostAsync(request, token)
                   .ConfigureAwait(false));
        }
示例#26
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="user"></param>
        public WithdrawRequest(IKucoinApiUser user)
        {
            Throw.IfNull(user, nameof(user));

            User = user;
        }
示例#27
0
 /// <summary>
 /// Subscribe listen key and user (w/o callback).
 /// </summary>
 /// <param name="client"></param>
 /// <param name="listenKey"></param>
 /// <param name="user"></param>
 public static void Subscribe(this IUserDataWebSocketClient client, string listenKey, IKucoinApiUser user)
 => client.Subscribe(listenKey, user, null);
示例#28
0
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="user"></param>
        protected ClientOrder(IKucoinApiUser user)
        {
            Throw.IfNull(user, nameof(user));

            User = user;
        }
示例#29
0
        /// <summary>
        /// Internal constructor.
        /// </summary>
        internal Order(IKucoinApiUser user)
        {
            Throw.IfNull(user, nameof(user));

            User = user;
        }
示例#30
0
        /// <summary>
        /// Get the deposit address for an asset.
        /// </summary>
        /// <param name="client"></param>
        /// <param name="user"></param>
        /// <param name="asset"></param>
        /// <param name="token"></param>
        /// <returns></returns>
        public static async Task <string> GetDepositAddressAsync(this IKucoinHttpClient client, IKucoinApiUser user, string asset, CancellationToken token = default)
        {
            Throw.IfNull(client, nameof(client));
            Throw.IfNullOrWhiteSpace(asset, nameof(asset));

            if (client.RateLimiter != null)
            {
                await client.RateLimiter.DelayAsync(token : token)
                .ConfigureAwait(false);
            }

            var request = new KucoinHttpRequest("/wapi/v3/depositAddress.html")
            {
                ApiKey = user.ApiKey
            };

            request.AddParameter("asset", asset.FormatSymbol());

            await client.SignAsync(request, user, token)
            .ConfigureAwait(false);

            return(await client.GetAsync(request, token)
                   .ConfigureAwait(false));
        }