public static IKucoinClient CreateResponseClient <T>(T response, KucoinClientOptions options = null) { var client = (KucoinClient)CreateClient(options); SetResponse(client, JsonConvert.SerializeObject(response)); return(client); }
public async Task <AccountInfo> GetAccountInfoAsync(User user, CancellationToken cancellationToken) { if (user == null) { throw new ArgumentNullException(nameof(user)); } var options = new KucoinClientOptions { ApiCredentials = new KucoinApiCredentials(user.ApiKey, user.ApiSecret, user.ApiPassPhrase) }; var accountInfo = new AccountInfo { User = user, Exchange = Exchange.Kucoin }; using (var kucoinClient = new KucoinClient(options)) { var accounts = await kucoinClient.GetAccountsAsync(accountType : KucoinAccountType.Trade).ConfigureAwait(false); foreach (var balance in accounts.Data) { accountInfo.Balances.Add(new AccountBalance { Asset = balance.Currency, Free = balance.Available, Locked = balance.Holds }); } } return(accountInfo); }
public static IKucoinClient CreateResponseClient(string response, KucoinClientOptions options = null) { var client = (KucoinClient)CreateClient(options); SetResponse(client, response); return(client); }
public static WebCallResult <KucoinTick> getTicketKuCoin(string symbol) { KucoinClientOptions clientOptions = new KucoinClientOptions(); clientOptions.ApiCredentials = new KucoinApiCredentials(KCAPIKEY, APISecretKucoin, KCAPIPASSPHRASE); KucoinClient kucoin = new KucoinClient(clientOptions); return(kucoin.GetTicker(symbol)); }
public static WebCallResult <KucoinFullOrderBook> getOrderBookKuCoin(string symbol, string side) { KucoinClientOptions clientOptions = new KucoinClientOptions(); clientOptions.ApiCredentials = new KucoinApiCredentials(KCAPIKEY, APISecretKucoin, KCAPIPASSPHRASE); KucoinClient kucoin = new KucoinClient(clientOptions); return(kucoin.GetOrderBook(symbol)); }
public static IKucoinClient CreateClient(KucoinClientOptions options = null) { IKucoinClient client; client = options != null ? new KucoinClient(options) : new KucoinClient(new KucoinClientOptions() { LogVerbosity = LogVerbosity.Debug }); client.RequestFactory = Mock.Of <IRequestFactory>(); return(client); }
public async Task <string> CancelOrderAsync(User user, string symbol, string orderId, string newClientOrderId = null, long recWindow = 0, CancellationToken cancellationToken = default(CancellationToken)) { var options = new KucoinClientOptions { ApiCredentials = new KucoinApiCredentials(user.ApiKey, user.ApiSecret, user.ApiPassPhrase) }; var kucoinClient = new KucoinClient(options); var result = await kucoinClient.CancelOrderAsync(orderId).ConfigureAwait(false); return(result.Data.CancelledOrderIds.First()); }
public async Task <IEnumerable <Order> > GetOpenOrdersAsync(User user, string symbol = null, long recWindow = 0, Action <Exception> exception = null, CancellationToken cancellationToken = default) { if (user == null) { throw new ArgumentNullException(nameof(user)); } var options = new KucoinClientOptions { ApiCredentials = new KucoinApiCredentials(user.ApiKey, user.ApiSecret, user.ApiPassPhrase) }; using (var kucoinClient = new KucoinClient(options)) { var results = await kucoinClient.GetOrdersAsync(null, null, null, null, null, KucoinOrderStatus.Active).ConfigureAwait(false); var orders = (from o in results.Data.Items select new Order { User = user, Symbol = o.Symbol, Exchange = Exchange.Kucoin, Id = o.Id, ClientOrderId = o.ClientOrderId, Price = o.Price, OriginalQuantity = o.Quantity, TimeInForce = o.TimeInForce.ToTradeViewTimeInForce(), Type = o.Type.ToTradeViewOrderType(), Side = o.Side.ToTradeViewOrderSide(), StopPrice = o.StopPrice, IcebergQuantity = o.VisibleIcebergSize, Time = o.CreatedAt, //Fills = o.Fills?.Select(f => new Interface.Model.Fill //{ // Price = f.Price, // Quantity = f.Quantity, // Commission = f.Commission, // CommissionAsset = f.CommissionAsset, // TradeId = f.TradeId //}) }).ToList(); return(orders); } }
internal KucoinClientFutures(KucoinClientOptions options) : base("Kucoin[Futures]", options, options.FuturesApiCredentials == null ? null : new KucoinAuthenticationProvider(options.FuturesApiCredentials)) { BaseAddress = options.FuturesBaseAddress; }
public async Task <Order> PlaceOrder(User user, ClientOrder clientOrder, long recWindow = 0, CancellationToken cancellationToken = default) { if (user == null) { throw new ArgumentNullException(nameof(user)); } if (clientOrder == null) { throw new ArgumentNullException(nameof(clientOrder)); } var options = new KucoinClientOptions { ApiCredentials = new KucoinApiCredentials(user.ApiKey, user.ApiSecret, user.ApiPassPhrase) }; using (var kucoinClient = new KucoinClient(options)) { var placeOrderResult = await kucoinClient.PlaceOrderAsync( clientOrder.Symbol, clientOrder.Side.ToKucoinOrderSide(), clientOrder.Type.ToKucoinNewOrderType(), clientOrder.Price, clientOrder.Quantity, null, clientOrder.TimeInForce.ToKucoinTimeInForce(), null, null, null, null, null, null, null, clientOrder.StopPrice, null, null ).ConfigureAwait(false); if (!placeOrderResult.Success) { throw new Exception($"Error Code : {placeOrderResult.Error.Code} Message : {placeOrderResult.Error.Message}"); } var orderResult = await kucoinClient.GetOrderAsync(placeOrderResult.Data.OrderId).ConfigureAwait(false); if (orderResult.Success) { var order = new Order { User = user, Exchange = Exchange.Kucoin, Symbol = orderResult.Data.Symbol, //Id = orderResult.Data.Id, ClientOrderId = orderResult.Data.ClientOrderId, Price = orderResult.Data.Price, OriginalQuantity = orderResult.Data.Quantity, TimeInForce = orderResult.Data.TimeInForce.ToTradeViewTimeInForce(), Type = orderResult.Data.Type.ToTradeViewOrderType(), Side = orderResult.Data.Side.ToTradeViewOrderSide(), StopPrice = orderResult.Data.StopPrice, IcebergQuantity = orderResult.Data.VisibleIcebergSize, Time = orderResult.Data.CreatedAt }; return(order); } else { throw new Exception($"Error Code : {orderResult.Error.Code} Message : {orderResult.Error.Message}"); } } }
/// <summary> /// Sets the default options to use for new clients /// </summary> /// <param name="options">The options to use for new clients</param> public static void SetDefaultOptions(KucoinClientOptions options) { defaultOptions = options; }
/// <summary> /// Create a new instance of the KucoinClient with the provided options /// </summary> public KucoinClient(KucoinClientOptions options) { Spot = new KucoinClientSpot(options); Futures = new KucoinClientFutures(options); Margin = new KucoinClientMargin(options); }
internal KucoinClientMargin(KucoinClientOptions options) : base("Kucoin[Margin]", options, options.ApiCredentials == null ? null : new KucoinAuthenticationProvider(options.ApiCredentials)) { }