mirror of
https://github.com/JKorf/CryptoExchange.Net
synced 2025-06-07 16:06:15 +00:00
small adjustments
This commit is contained in:
parent
825a3d1f90
commit
488eb1cd48
@ -11,8 +11,8 @@ namespace CryptoExchange.Net.Authentication
|
|||||||
this.credentials = credentials;
|
this.credentials = credentials;
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract string AddAuthenticationToUriString(string uri);
|
public abstract string AddAuthenticationToUriString(string uri, bool signed);
|
||||||
public abstract IRequest AddAuthenticationToRequest(IRequest request);
|
public abstract IRequest AddAuthenticationToRequest(IRequest request, bool signed);
|
||||||
|
|
||||||
protected string ByteToString(byte[] buff)
|
protected string ByteToString(byte[] buff)
|
||||||
{
|
{
|
||||||
|
@ -25,7 +25,15 @@ namespace CryptoExchange.Net
|
|||||||
|
|
||||||
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
|
public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
|
||||||
{
|
{
|
||||||
return Mapping.Single(v => v.Value.ToLower() == reader.Value.ToString().ToLower()).Key;
|
var val = Mapping.Single(v => v.Value == reader.Value.ToString()).Key;
|
||||||
|
if (val != null)
|
||||||
|
return val;
|
||||||
|
return Mapping.Single(v => v.Value.ToLower() == reader.Value.ToString().ToLower());
|
||||||
|
}
|
||||||
|
|
||||||
|
public T ReadString(string data)
|
||||||
|
{
|
||||||
|
return Mapping.Single(v => v.Value == data).Key;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override bool CanConvert(Type objectType)
|
public override bool CanConvert(Type objectType)
|
||||||
|
5
Error.cs
5
Error.cs
@ -46,4 +46,9 @@
|
|||||||
{
|
{
|
||||||
public UnknownError(string message) : base(5, "Unknown error occured " + message) { }
|
public UnknownError(string message) : base(5, "Unknown error occured " + message) { }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class ArgumentError : Error
|
||||||
|
{
|
||||||
|
public ArgumentError(string message) : base(5, "Invalid parameter: " + message) { }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -90,8 +90,7 @@ namespace CryptoExchange.Net
|
|||||||
uriString += $"{string.Join("&", parameters.Select(s => $"{s.Key}={s.Value}"))}";
|
uriString += $"{string.Join("&", parameters.Select(s => $"{s.Key}={s.Value}"))}";
|
||||||
}
|
}
|
||||||
|
|
||||||
if (signed)
|
uriString = authProvider.AddAuthenticationToUriString(uriString, signed);
|
||||||
uriString = authProvider.AddAuthenticationToUriString(uriString);
|
|
||||||
|
|
||||||
var request = RequestFactory.Create(uriString);
|
var request = RequestFactory.Create(uriString);
|
||||||
request.Method = method;
|
request.Method = method;
|
||||||
@ -99,8 +98,7 @@ namespace CryptoExchange.Net
|
|||||||
if (apiProxy != null)
|
if (apiProxy != null)
|
||||||
request.SetProxy(apiProxy.Host, apiProxy.Port);
|
request.SetProxy(apiProxy.Host, apiProxy.Port);
|
||||||
|
|
||||||
if (signed)
|
request = authProvider.AddAuthenticationToRequest(request, signed);
|
||||||
request = authProvider.AddAuthenticationToRequest(request);
|
|
||||||
|
|
||||||
foreach (var limiter in rateLimiters)
|
foreach (var limiter in rateLimiters)
|
||||||
{
|
{
|
||||||
@ -132,8 +130,25 @@ namespace CryptoExchange.Net
|
|||||||
catch (WebException we)
|
catch (WebException we)
|
||||||
{
|
{
|
||||||
var response = (HttpWebResponse)we.Response;
|
var response = (HttpWebResponse)we.Response;
|
||||||
string infoMessage = response == null ? "No response from server" : $"Status: {response.StatusCode}-{response.StatusDescription}, Message: {we.Message}";
|
string responseData = null;
|
||||||
return new CallResult<string>(null, new WebError(infoMessage));
|
try
|
||||||
|
{
|
||||||
|
var reader = new StreamReader(response.GetResponseStream());
|
||||||
|
responseData = reader.ReadToEnd();
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
string infoMessage = "No response from server";
|
||||||
|
if (response == null)
|
||||||
|
return new CallResult<string>(null, new WebError(infoMessage));
|
||||||
|
|
||||||
|
if (responseData != null)
|
||||||
|
infoMessage = "Server returned error: " + responseData;
|
||||||
|
else
|
||||||
|
infoMessage = $"Status: {response.StatusCode}-{response.StatusDescription}, Message: {we.Message}";
|
||||||
|
return new CallResult<string>(null, new ServerError(infoMessage));
|
||||||
}
|
}
|
||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
@ -151,7 +166,11 @@ namespace CryptoExchange.Net
|
|||||||
if (obj is JObject o)
|
if (obj is JObject o)
|
||||||
CheckObject(typeof(T), o);
|
CheckObject(typeof(T), o);
|
||||||
else
|
else
|
||||||
CheckObject(typeof(T), (JObject) ((JArray) obj)[0]);
|
{
|
||||||
|
var ary = (JArray) obj;
|
||||||
|
if (ary.HasValues && ary[0] is JObject jObject)
|
||||||
|
CheckObject(typeof(T).GetElementType(), jObject);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return new CallResult<T>(obj.ToObject<T>(), null);
|
return new CallResult<T>(obj.ToObject<T>(), null);
|
||||||
@ -177,28 +196,32 @@ namespace CryptoExchange.Net
|
|||||||
if (ignore != null)
|
if (ignore != null)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
properties.Add(attr == null ? prop.Name.ToLower() : ((JsonPropertyAttribute) attr).PropertyName.ToLower());
|
properties.Add(attr == null ? prop.Name : ((JsonPropertyAttribute) attr).PropertyName);
|
||||||
}
|
}
|
||||||
foreach (var token in obj)
|
foreach (var token in obj)
|
||||||
{
|
{
|
||||||
var d = properties.SingleOrDefault(p => p == token.Key.ToLower());
|
var d = properties.SingleOrDefault(p => p == token.Key);
|
||||||
if (d == null)
|
if (d == null)
|
||||||
log.Write(LogVerbosity.Warning, $"Didn't find property `{token.Key}` in object of type `{type.Name}`");
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
properties.Remove(d);
|
d = properties.SingleOrDefault(p => p.ToLower() == token.Key.ToLower());
|
||||||
|
if (d == null)
|
||||||
var propType = GetProperty(d, props)?.PropertyType;
|
|
||||||
if (propType == null)
|
|
||||||
continue;
|
|
||||||
if (!IsSimple(propType) && propType != typeof(DateTime))
|
|
||||||
{
|
{
|
||||||
if(propType.IsArray && token.Value.HasValues && ((JArray)token.Value).Any() && ((JArray)token.Value)[0] is JObject)
|
log.Write(LogVerbosity.Warning, $"Didn't find property `{token.Key}` in object of type `{type.Name}`");
|
||||||
CheckObject(propType.GetElementType(), (JObject)token.Value[0]);
|
continue;
|
||||||
else if(token.Value is JObject)
|
|
||||||
CheckObject(propType, (JObject)token.Value);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
properties.Remove(d);
|
||||||
|
|
||||||
|
var propType = GetProperty(d, props)?.PropertyType;
|
||||||
|
if (propType == null)
|
||||||
|
continue;
|
||||||
|
if (!IsSimple(propType) && propType != typeof(DateTime))
|
||||||
|
{
|
||||||
|
if(propType.IsArray && token.Value.HasValues && ((JArray)token.Value).Any() && ((JArray)token.Value)[0] is JObject)
|
||||||
|
CheckObject(propType.GetElementType(), (JObject)token.Value[0]);
|
||||||
|
else if(token.Value is JObject)
|
||||||
|
CheckObject(propType, (JObject)token.Value);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach(var prop in properties)
|
foreach(var prop in properties)
|
||||||
@ -217,7 +240,7 @@ namespace CryptoExchange.Net
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (((JsonPropertyAttribute) attr).PropertyName.ToLower() == name)
|
if (((JsonPropertyAttribute) attr).PropertyName == name)
|
||||||
return prop;
|
return prop;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user