private HttpRequestMessage BuildAuthenticatedRequestAsync(BittrexRequest request) { var query = new NameValueCollection { { "apikey", this.key }, { "nonce", (DateTime.UtcNow.ToUnixTimestamp() * 100000).ToString() }, request.Parameters }.ToQueryString(); var builder = new UriBuilder(BaseUrl) { Path = request.RelativeUrl, Query = query }; var requestMessage = new HttpRequestMessage(HttpMethod.Get, builder.Uri); requestMessage.Headers.Add("User-Agent", "bittrex-dotnet"); var hash = this.HashString(builder.Uri.ToString(), this.secret); requestMessage.Headers.Add("apisign", hash); return(requestMessage); }
public async Task <BittrexResponse <T> > SendRequestAsync <T>(BittrexRequest request) { using (var http = new HttpClient()) { var requestMessage = request.Api == BittrexApi.Public ? this.BuildUnauthenticatedRequestAsync(request) : this.BuildAuthenticatedRequestAsync(request); var response = await http.SendAsync(requestMessage); var content = await response.Content.ReadAsStringAsync(); if (!response.IsSuccessStatusCode) { var error = JsonConvert.DeserializeObject <BittrexResponse>(content); throw new BittrexException(error.Message); } var value = JsonConvert.DeserializeObject <BittrexResponse <T> >(content); if (!value.Success) { throw new BittrexException(value.Message); } return(value); } }
public static async Task <Balance[]> GetBalancesAsync(this BittrexClient client) { var request = new BittrexRequest { Api = BittrexApi.Account, RelativeUrl = "api/v1.1/account/getbalances" }; var response = await client.SendRequestAsync <Balance[]>(request); return(response.Result); }
public static async Task <Market[]> GetMarketsAsync(this BittrexClient client) { var request = new BittrexRequest { Api = BittrexApi.Public, RelativeUrl = "api/v1.1/public/getmarkets" }; var response = await client.SendRequestAsync <Market[]>(request); return(response.Result); }
private HttpRequestMessage BuildUnauthenticatedRequestAsync(BittrexRequest request) { var builder = new UriBuilder(BaseUrl) { Path = request.RelativeUrl, }; if (request.Parameters.Count > 0) { builder.Query = request.Parameters.ToQueryString(); } var requestMessage = new HttpRequestMessage(HttpMethod.Get, builder.Uri); requestMessage.Headers.Add("User-Agent", "bittrex-dotnet"); return(requestMessage); }