I've seen some people using HttpUtility.UrlEncode
on each one of the parameters. Do I need to do the same in the GetCashBalanceAsync
method below which uses RestSharp?
private static string BuildQueryString(Dictionary<string, object> queryParameters)
{
return string.Join("&", queryParameters.Select(kvp =>
string.Format("{0}={1}", kvp.Key, HttpUtility.UrlEncode(kvp.Value.ToString()))));
}
Code
public async Task<AccountInformation?> GetCashBalanceAsync()
{
var queryString = $"timestamp={GetNonce()}";
var endpoint = $"/api/v3/account?{queryString}&signature={AuthenticationToken(queryString)}";
RestRequest request = new(endpoint);
request.AddHeader("X-MBX-APIKEY", _apiKey);
var response = await ExecuteRestRequestAsync(request).ConfigureAwait(false);
if (response.StatusCode != HttpStatusCode.OK)
{
throw new Exception(
$"GetCashBalance: request failed: [{(int)response.StatusCode}] {response.StatusDescription}, Content: {response.Content}, ErrorMessage: {response.ErrorMessage}");
}
var deserialized = JsonSerializer.Deserialize<AccountInformation>(response.Content!);
return deserialized;
}