private async Task <BinanceResponse <T> > MakeRequestAsync <T>(HttpRequestMessage httpRequestMessage) { BinanceResponse <T> result = new BinanceResponse <T>(); if (this.forbidAllRequests) { result.ErrorCode = BinanceErrors.REQUEST_FORBIDDEN_MANUALLY; result.ErrorMessage = $"All requests are forbidden manual. Approximate time to release - {CalculateRemainingForbiddenTime()}"; return(result); } var response = await this.httpClient.SendAsync(httpRequestMessage); var json = await response.Content.ReadAsStringAsync(); if (response.IsSuccessStatusCode) { result.Content = JsonConvert.DeserializeObject <T>(json); } else { result = JsonConvert.DeserializeObject <BinanceResponse <T> >(json); } return(result); }
public BinanceResponse <AccountInformationDto> AccountInfo() { var response = new BinanceResponse <AccountInformationDto>() { Status = OutcomeStatus.OK }; var request = new RestRequest("/api/v3/account", Method.GET); request.AddHeader("X-MBX-APIKEY", apiKey); request.AddOrUpdateParameter(new Parameter("timestamp", ServerTime().ServerTimestamp, ParameterType.QueryString)); AddSignature(request); IRestResponse requestResponse = Client.Execute(request); if (!requestResponse.IsSuccessful) { response.Status = OutcomeStatus.Failed; response.Notifications.Add(Notification.AddError($"Status {requestResponse.StatusCode}: {requestResponse.StatusDescription}")); var error = JsonConvert.DeserializeObject <ErrorMessageDto>(requestResponse.Content, CamelCaseResolver); response.Notifications.Add(Notification.AddError($"Error: {error.Code} - {error.Msg}")); return(response); } var trade = JsonConvert.DeserializeObject <AccountInformationDto>(requestResponse.Content, CamelCaseResolver); response.ResponseDto = trade; return(response); }