From 889222beb6b51a35b144783675e7cc24e6679327 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?No=C3=A9=20Comte?= Date: Thu, 2 Aug 2018 13:33:53 +0200 Subject: [PATCH 1/5] Fix typo --- CryptoExchange.Net/Authentication/ApiCredentials.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CryptoExchange.Net/Authentication/ApiCredentials.cs b/CryptoExchange.Net/Authentication/ApiCredentials.cs index 721735f..a34f5af 100644 --- a/CryptoExchange.Net/Authentication/ApiCredentials.cs +++ b/CryptoExchange.Net/Authentication/ApiCredentials.cs @@ -26,7 +26,7 @@ namespace CryptoExchange.Net.Authentication /// The private key used for signing public ApiCredentials(SecureString privateKey) { - PrivateKey = Key; + PrivateKey = privateKey; } /// From 48dc4dbd940c4c2ed220146f23cbffc5afe8a349 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?No=C3=A9=20Comte?= Date: Thu, 2 Aug 2018 13:35:07 +0200 Subject: [PATCH 2/5] Allow inputs such as double, long, (...) instead of string only --- CryptoExchange.Net/Converters/TimestampSecondsConverter.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CryptoExchange.Net/Converters/TimestampSecondsConverter.cs b/CryptoExchange.Net/Converters/TimestampSecondsConverter.cs index 297ded6..b05ce26 100644 --- a/CryptoExchange.Net/Converters/TimestampSecondsConverter.cs +++ b/CryptoExchange.Net/Converters/TimestampSecondsConverter.cs @@ -13,7 +13,7 @@ namespace CryptoExchange.Net.Converters public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { - var t = double.Parse((string)reader.Value, CultureInfo.InvariantCulture); + var t = double.Parse((string)reader.Value.ToString(), CultureInfo.InvariantCulture); return new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc).AddSeconds(t); } From 2ff2912fb381c7cdaf92069bf704c6fafe62325a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?No=C3=A9=20Comte?= Date: Thu, 2 Aug 2018 13:44:27 +0200 Subject: [PATCH 3/5] Removed unnecessary cast --- CryptoExchange.Net/Converters/TimestampSecondsConverter.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CryptoExchange.Net/Converters/TimestampSecondsConverter.cs b/CryptoExchange.Net/Converters/TimestampSecondsConverter.cs index b05ce26..b7a11d0 100644 --- a/CryptoExchange.Net/Converters/TimestampSecondsConverter.cs +++ b/CryptoExchange.Net/Converters/TimestampSecondsConverter.cs @@ -13,7 +13,7 @@ namespace CryptoExchange.Net.Converters public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer) { - var t = double.Parse((string)reader.Value.ToString(), CultureInfo.InvariantCulture); + var t = double.Parse(reader.Value.ToString(), CultureInfo.InvariantCulture); return new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc).AddSeconds(t); } From 9030ffd333fc6c867b6397c3893f0f9286404363 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?No=C3=A9=20Comte?= Date: Thu, 2 Aug 2018 14:48:36 +0200 Subject: [PATCH 4/5] Added a flexible way to write in request body --- CryptoExchange.Net/ExchangeClient.cs | 10 ++++++++++ CryptoExchange.Net/Interfaces/IRequest.cs | 5 +++++ CryptoExchange.Net/Requests/Request.cs | 6 ++++++ 3 files changed, 21 insertions(+) diff --git a/CryptoExchange.Net/ExchangeClient.cs b/CryptoExchange.Net/ExchangeClient.cs index 6bf89cd..dafa5c2 100644 --- a/CryptoExchange.Net/ExchangeClient.cs +++ b/CryptoExchange.Net/ExchangeClient.cs @@ -143,6 +143,7 @@ namespace CryptoExchange.Net var request = RequestFactory.Create(uriString); request.Method = method; + request.Parameters = parameters; if (authProvider != null) request = authProvider.AddAuthenticationToRequest(request, signed); @@ -155,6 +156,15 @@ namespace CryptoExchange.Net var returnedData = ""; try { + if (request.WriteCustomBody && + request.CustomBody != null && request.CustomBody.Length > 0) + { + using (var requestStream = await request.GetRequestStream()) + { + requestStream.Write(request.CustomBody, 0, request.CustomBody.Length); + } + } + var response = await request.GetResponse().ConfigureAwait(false); using (var reader = new StreamReader(response.GetResponseStream())) { diff --git a/CryptoExchange.Net/Interfaces/IRequest.cs b/CryptoExchange.Net/Interfaces/IRequest.cs index ec5219b..d984f18 100644 --- a/CryptoExchange.Net/Interfaces/IRequest.cs +++ b/CryptoExchange.Net/Interfaces/IRequest.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.IO; using System.Net; using System.Threading.Tasks; @@ -10,6 +11,10 @@ namespace CryptoExchange.Net.Interfaces Uri Uri { get; } WebHeaderCollection Headers { get; set; } string Method { get; set; } + Dictionary Parameters { get; set; } + + byte[] CustomBody { get; set; } + bool WriteCustomBody { get; set; } void SetProxy(string host, int port); diff --git a/CryptoExchange.Net/Requests/Request.cs b/CryptoExchange.Net/Requests/Request.cs index e2471a3..b381797 100644 --- a/CryptoExchange.Net/Requests/Request.cs +++ b/CryptoExchange.Net/Requests/Request.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.IO; using System.Net; using System.Threading.Tasks; @@ -44,6 +45,11 @@ namespace CryptoExchange.Net.Requests set => request.Method = value; } + public Dictionary Parameters { get; set; } + + public byte[] CustomBody { get; set; } + public bool WriteCustomBody { get; set; } = false; + public Uri Uri => request.RequestUri; public void SetProxy(string host, int port) From 91fb08f75dff65a513cd368778dbe3735d3bf5a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?No=C3=A9=20Comte?= Date: Thu, 2 Aug 2018 14:48:36 +0200 Subject: [PATCH 5/5] Revert "Added a flexible way to write in request body" This reverts commit 9030ffd333fc6c867b6397c3893f0f9286404363. --- CryptoExchange.Net/ExchangeClient.cs | 10 ---------- CryptoExchange.Net/Interfaces/IRequest.cs | 5 ----- CryptoExchange.Net/Requests/Request.cs | 6 ------ 3 files changed, 21 deletions(-) diff --git a/CryptoExchange.Net/ExchangeClient.cs b/CryptoExchange.Net/ExchangeClient.cs index dafa5c2..6bf89cd 100644 --- a/CryptoExchange.Net/ExchangeClient.cs +++ b/CryptoExchange.Net/ExchangeClient.cs @@ -143,7 +143,6 @@ namespace CryptoExchange.Net var request = RequestFactory.Create(uriString); request.Method = method; - request.Parameters = parameters; if (authProvider != null) request = authProvider.AddAuthenticationToRequest(request, signed); @@ -156,15 +155,6 @@ namespace CryptoExchange.Net var returnedData = ""; try { - if (request.WriteCustomBody && - request.CustomBody != null && request.CustomBody.Length > 0) - { - using (var requestStream = await request.GetRequestStream()) - { - requestStream.Write(request.CustomBody, 0, request.CustomBody.Length); - } - } - var response = await request.GetResponse().ConfigureAwait(false); using (var reader = new StreamReader(response.GetResponseStream())) { diff --git a/CryptoExchange.Net/Interfaces/IRequest.cs b/CryptoExchange.Net/Interfaces/IRequest.cs index d984f18..ec5219b 100644 --- a/CryptoExchange.Net/Interfaces/IRequest.cs +++ b/CryptoExchange.Net/Interfaces/IRequest.cs @@ -1,5 +1,4 @@ using System; -using System.Collections.Generic; using System.IO; using System.Net; using System.Threading.Tasks; @@ -11,10 +10,6 @@ namespace CryptoExchange.Net.Interfaces Uri Uri { get; } WebHeaderCollection Headers { get; set; } string Method { get; set; } - Dictionary Parameters { get; set; } - - byte[] CustomBody { get; set; } - bool WriteCustomBody { get; set; } void SetProxy(string host, int port); diff --git a/CryptoExchange.Net/Requests/Request.cs b/CryptoExchange.Net/Requests/Request.cs index b381797..e2471a3 100644 --- a/CryptoExchange.Net/Requests/Request.cs +++ b/CryptoExchange.Net/Requests/Request.cs @@ -1,5 +1,4 @@ using System; -using System.Collections.Generic; using System.IO; using System.Net; using System.Threading.Tasks; @@ -45,11 +44,6 @@ namespace CryptoExchange.Net.Requests set => request.Method = value; } - public Dictionary Parameters { get; set; } - - public byte[] CustomBody { get; set; } - public bool WriteCustomBody { get; set; } = false; - public Uri Uri => request.RequestUri; public void SetProxy(string host, int port)