/// <summary> /// /// </summary> /// <param name="client"></param> /// <param name="symbol"></param> /// <param name="interval"></param> /// <param name="limit"></param> /// <param name="token"></param> /// <returns></returns> public static async Task <string> GetLatestCandlesAsync(this ICryptocoreHttpClient client, Symbol symbol, CandleInterval interval, int limit = 100, CancellationToken token = default) { Throw.IfNull(client, nameof(client)); Throw.IfNull(symbol, nameof(symbol)); var request = new CryptocoreHttpRequest($"/v1/data/ohlcv/{symbol}/latest"); request.AddParameter("period_id", interval.ConvertToString()); if (limit > 0) { request.AddParameter("limit", limit); } return(await client.GetAsync(request, token) .ConfigureAwait(false)); }
/// <summary> /// /// </summary> /// <param name="client"></param> /// <param name="user"></param> /// <param name="symbol"></param> /// <param name="orderId"></param> /// <param name="token"></param> /// <returns></returns> public static async Task <string> CancelAsync(this ICryptocoreHttpClient client, ICryptocoreApiUser user, Symbol symbol, string orderId, CancellationToken token = default) { Throw.IfNull(client, nameof(client)); Throw.IfNull(user, nameof(user)); Throw.IfNull(symbol, nameof(symbol)); Throw.IfNullOrWhiteSpace(orderId, nameof(orderId)); var request = new CryptocoreHttpRequest($"/v1/orders/{symbol.Exchange}/{symbol}/active/{orderId}") { ApiKey = user.ApiKey }; return(await client.DeleteAsync(request, token) .ConfigureAwait(false)); }
/// <summary> /// /// </summary> /// <param name="client"></param> /// <param name="symbol"></param> /// <param name="interval"></param> /// <param name="start"></param> /// <param name="end"></param> /// <param name="token"></param> /// <returns></returns> public static async Task <string> GetHistoricalCandlesAsync(this ICryptocoreHttpClient client, Symbol symbol, CandleInterval interval, DateTime start, DateTime end = default, CancellationToken token = default) { Throw.IfNull(client, nameof(client)); Throw.IfNull(symbol, nameof(symbol)); var request = new CryptocoreHttpRequest($"/v1/data/ohlcv/{symbol}/history"); request.AddParameter("period_id", interval.ConvertToString()); request.AddParameter("time_start", start.ToTimestamp()); if (end != default) { request.AddParameter("time_end", end.ToTimestamp()); } return(await client.GetAsync(request, token) .ConfigureAwait(false)); }
/// <summary> /// /// </summary> /// <param name="client"></param> /// <param name="symbol"></param> /// <param name="token"></param> /// <returns></returns> public static async Task <string> GetLatestQuoteAsync(this ICryptocoreHttpClient client, Symbol symbol, CancellationToken token = default) { Throw.IfNull(client, nameof(client)); Throw.IfNull(symbol, nameof(symbol)); return(await client.GetAsync($"/v1/data/quotes/{symbol}/latest", token) .ConfigureAwait(false)); }