/// <summary> /// /// </summary> /// <param name="client"></param> /// <param name="user"></param> /// <param name="exchange"></param> /// <param name="start"></param> /// <param name="end"></param> /// <param name="limit"></param> /// <param name="token"></param> /// <returns></returns> public static async Task <string> GetOrdersHistoryAsync(this ICryptocoreHttpClient client, ICryptocoreApiUser user, string exchange, DateTime start, DateTime end = default, int limit = 100, CancellationToken token = default) { Throw.IfNull(client, nameof(client)); Throw.IfNull(user, nameof(user)); Throw.IfNullOrWhiteSpace(exchange, nameof(exchange)); var request = new CryptocoreHttpRequest($"/v1/orders/{exchange}/history") { ApiKey = user.ApiKey }; request.AddParameter("time_start", start.ToTimestamp()); if (end != default) { request.AddParameter("time_end", end.ToTimestamp()); } if (limit > 0) { request.AddParameter("limit", limit); } return(await client.GetAsync(request, token) .ConfigureAwait(false)); }
public async Task <Order> PlaceAsync(ICryptocoreApiUser user, Symbol symbol, OrderType type, OrderSide side, decimal price, decimal quantity, CancellationToken token = default) { var json = await HttpClient.PlaceAsync(user, symbol, type, side, price, quantity, token) .ConfigureAwait(false); try { return(_orderSerialization.DeserializeOrder(json)); } catch (Exception e) { throw NewFailedToParseJsonException(nameof(GetExchangesAsync), json, e); } }
public async Task <Order> GetOrderAsync(ICryptocoreApiUser user, string exchange, string orderId, CancellationToken token = default) { var json = await HttpClient.GetOrderAsync(user, exchange, orderId, token) .ConfigureAwait(false); try { return(_orderSerialization.DeserializeOrder(json)); } catch (Exception e) { throw NewFailedToParseJsonException(nameof(GetExchangesAsync), json, e); } }
public async Task <IEnumerable <Balance> > GetLatestBalancesAsync(ICryptocoreApiUser user, string exchange, CancellationToken token = default) { var json = await HttpClient.GetLatestBalancesAsync(user, exchange, token) .ConfigureAwait(false); try { return(_balanceSerialization.DeserializeBalances(json)); } catch (Exception e) { throw NewFailedToParseJsonException(nameof(GetExchangesAsync), json, e); } }
/// <summary> /// /// </summary> /// <param name="client"></param> /// <param name="user"></param> /// <param name="exchange"></param> /// <param name="token"></param> /// <returns></returns> public static async Task <string> GetLatestBalancesAsync(this ICryptocoreHttpClient client, ICryptocoreApiUser user, string exchange, CancellationToken token = default) { Throw.IfNull(client, nameof(client)); Throw.IfNull(user, nameof(user)); var request = new CryptocoreHttpRequest($"/v1/account/balances/{exchange}/latest") { ApiKey = user.ApiKey }; return(await client.GetAsync(request, token) .ConfigureAwait(false)); }
public async Task <IEnumerable <Order> > GetOrdersHistoryAsync(ICryptocoreApiUser user, string exchange, DateTime start, DateTime end = default, int limit = 100, CancellationToken token = default) { var json = await HttpClient.GetOrdersHistoryAsync(user, exchange, start, end, limit, token) .ConfigureAwait(false); try { return(_orderSerialization.DeserializeOrders(json)); } catch (Exception e) { throw NewFailedToParseJsonException(nameof(GetExchangesAsync), json, e); } }
/// <summary> /// /// </summary> /// <param name="client"></param> /// <param name="user"></param> /// <param name="exchange"></param> /// <param name="token"></param> /// <returns></returns> public static async Task <string> GetActiveOrdersAsync(this ICryptocoreHttpClient client, ICryptocoreApiUser user, string exchange, CancellationToken token = default) { Throw.IfNull(client, nameof(client)); Throw.IfNull(user, nameof(user)); Throw.IfNullOrWhiteSpace(exchange, nameof(exchange)); var request = new CryptocoreHttpRequest($"/v1/orders/{exchange}/active") { ApiKey = user.ApiKey }; return(await client.GetAsync(request, token) .ConfigureAwait(false)); }
/// <summary> /// /// </summary> /// <param name="client"></param> /// <param name="user"></param> /// <param name="symbol"></param> /// <param name="type"></param> /// <param name="side"></param> /// <param name="price"></param> /// <param name="quantity"></param> /// <param name="token"></param> /// <returns></returns> public static async Task <string> PlaceAsync(this ICryptocoreHttpClient client, ICryptocoreApiUser user, Symbol symbol, OrderType type, OrderSide side, decimal price, decimal quantity, CancellationToken token = default) { Throw.IfNull(client, nameof(client)); Throw.IfNull(user, nameof(user)); Throw.IfNull(symbol, nameof(symbol)); var request = new CryptocoreHttpRequest($"/v1/orders/{symbol.Exchange}/{symbol}") { ApiKey = user.ApiKey }; request.AddParameter("type", type.ConvertToString()); request.AddParameter("side", side.ConvertToString()); request.AddParameter("price", price); request.AddParameter("quantity", quantity); return(await client.PostAsync(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)); }