mirror of
https://github.com/JKorf/CryptoExchange.Net
synced 2025-06-10 01:16:24 +00:00
Added support for array parameters (e.g. field[]=a&field[]=b)
This commit is contained in:
parent
861a69c043
commit
b0cf1a899e
@ -104,11 +104,27 @@ namespace CryptoExchange.Net
|
||||
}
|
||||
|
||||
string paramString = null;
|
||||
if (parameters != null) {
|
||||
if (parameters != null)
|
||||
{
|
||||
paramString = "with parameters ";
|
||||
int paramCount = 1;
|
||||
foreach (var param in parameters)
|
||||
paramString += $"{param.Key}={param.Value}, ";
|
||||
{
|
||||
string paramValue = param.Value.ToString();
|
||||
if (param.Value.GetType().IsArray)
|
||||
paramValue = string.Format("[{0}]", string.Join(", ", ((object[])param.Value).Select(p => p.ToString())));
|
||||
|
||||
paramString += $"{param.Key}={paramValue}";
|
||||
|
||||
if (paramCount < parameters.Count)
|
||||
paramString += ", ";
|
||||
else
|
||||
paramString += ".";
|
||||
|
||||
paramCount++;
|
||||
}
|
||||
}
|
||||
|
||||
log.Write(LogVerbosity.Debug, $"Sending {(signed ? "signed" : "")} request to {request.Uri} {(paramString ?? "")}");
|
||||
var result = await ExecuteRequest(request).ConfigureAwait(false);
|
||||
return result.Error != null ? new CallResult<T>(null, result.Error) : Deserialize<T>(result.Data);
|
||||
@ -123,7 +139,26 @@ namespace CryptoExchange.Net
|
||||
if (!uriString.EndsWith("?"))
|
||||
uriString += "?";
|
||||
|
||||
uriString += $"{string.Join("&", parameters.Select(s => $"{s.Key}={s.Value}"))}";
|
||||
var arraysParameters = parameters.Where(p => p.Value.GetType().IsArray).ToList();
|
||||
if (arraysParameters != null && arraysParameters.Count() > 0)
|
||||
{
|
||||
bool isFirstEntry = true;
|
||||
arraysParameters.ForEach((arrayEntry) =>
|
||||
{
|
||||
if (!isFirstEntry)
|
||||
uriString += "&";
|
||||
|
||||
List<object> values = ((object[])arrayEntry.Value).ToList();
|
||||
uriString += $"{string.Join("&", values.Select(v => $"{arrayEntry.Key}[]={v}"))}";
|
||||
|
||||
isFirstEntry = false;
|
||||
});
|
||||
|
||||
if (parameters.Count - arraysParameters.Count > 0)
|
||||
uriString += "&";
|
||||
}
|
||||
|
||||
uriString += $"{string.Join("&", parameters.Where(p => !p.Value.GetType().IsArray).Select(s => $"{s.Key}={s.Value}"))}";
|
||||
}
|
||||
|
||||
if (authProvider != null)
|
||||
@ -257,6 +292,10 @@ namespace CryptoExchange.Net
|
||||
d = properties.SingleOrDefault(p => p.ToLower() == token.Key.ToLower());
|
||||
if (d == null && !(type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Dictionary<,>)))
|
||||
{
|
||||
// Checking if missing properties is voluntary
|
||||
// True : If entire class is handled by a JsonConveter
|
||||
bool isManuallyDeserialized = type.GetCustomAttribute<JsonConverterAttribute>(true) != null;
|
||||
if (!isManuallyDeserialized)
|
||||
log.Write(LogVerbosity.Warning, $"Didn't find property `{token.Key}` in object of type `{type.Name}`");
|
||||
isDif = true;
|
||||
continue;
|
||||
|
Loading…
x
Reference in New Issue
Block a user