diff --git a/CryptoExchange.Net/Authentication/AuthenticationProvider.cs b/CryptoExchange.Net/Authentication/AuthenticationProvider.cs index 5c54462..eaf4d4a 100644 --- a/CryptoExchange.Net/Authentication/AuthenticationProvider.cs +++ b/CryptoExchange.Net/Authentication/AuthenticationProvider.cs @@ -47,7 +47,7 @@ namespace CryptoExchange.Net.Authentication /// public abstract void AuthenticateUriRequest( RestApiClient apiClient, - ref Uri uri, + Uri uri, HttpMethod method, SortedDictionary parameters, Dictionary headers, diff --git a/CryptoExchange.Net/Clients/BaseRestClient.cs b/CryptoExchange.Net/Clients/BaseRestClient.cs index 6a7ab4f..f7c6efd 100644 --- a/CryptoExchange.Net/Clients/BaseRestClient.cs +++ b/CryptoExchange.Net/Clients/BaseRestClient.cs @@ -300,7 +300,7 @@ namespace CryptoExchange.Net if (apiClient.AuthenticationProvider != null) { if(parameterPosition == HttpMethodParameterPosition.InUri) - apiClient.AuthenticationProvider.AuthenticateUriRequest(apiClient, ref uri, method, sortedParameters, headers, signed, arraySerialization); + apiClient.AuthenticationProvider.AuthenticateUriRequest(apiClient, uri, method, sortedParameters, headers, signed, arraySerialization); else apiClient.AuthenticationProvider.AuthenticateBodyRequest(apiClient, uri, method, sortedParameters, headers, signed, arraySerialization); } @@ -309,15 +309,7 @@ namespace CryptoExchange.Net { // Add the auth parameters to the uri, start with a new URI to be able to sort the parameters including the auth parameters if (sortedParameters.Count != length) - { - var uriBuilder = new UriBuilder(); - uriBuilder.Scheme = uri.Scheme; - uriBuilder.Host = uri.Host; - uriBuilder.Path = uri.AbsolutePath; - uri = uriBuilder.Uri; - foreach(var parameter in sortedParameters) - uri = uri.AddQueryParmeter(parameter.Key, parameter.Value.ToString()); - } + uri = uri.SetParameters(sortedParameters); } var request = RequestFactory.Create(method, uri, requestId); diff --git a/CryptoExchange.Net/ExtensionMethods.cs b/CryptoExchange.Net/ExtensionMethods.cs index 5e39b28..1cf4ab0 100644 --- a/CryptoExchange.Net/ExtensionMethods.cs +++ b/CryptoExchange.Net/ExtensionMethods.cs @@ -165,26 +165,6 @@ namespace CryptoExchange.Net return formData.ToString(); } - /// - /// Add parameter to URI - /// - /// - /// - /// - /// - public static Uri AddQueryParmeter(this Uri uri, string name, string value) - { - var httpValueCollection = HttpUtility.ParseQueryString(uri.Query); - - httpValueCollection.Remove(name); - httpValueCollection.Add(name, value); - - var ub = new UriBuilder(uri); - ub.Query = httpValueCollection.ToString(); - - return ub.Uri; - } - /// /// Get the string the secure string is representing @@ -433,6 +413,47 @@ namespace CryptoExchange.Net } return path; } + + /// + /// Create a new uri with the provided parameters as query + /// + /// + /// + /// + public static Uri SetParameters(this Uri baseUri, SortedDictionary parameters) + { + var uriBuilder = new UriBuilder(); + uriBuilder.Scheme = baseUri.Scheme; + uriBuilder.Host = baseUri.Host; + uriBuilder.Path = baseUri.AbsolutePath; + var httpValueCollection = HttpUtility.ParseQueryString(string.Empty); + foreach (var parameter in parameters) + httpValueCollection.Add(parameter.Key, parameter.Value.ToString()); + uriBuilder.Query = httpValueCollection.ToString(); + return uriBuilder.Uri; + } + + + /// + /// Add parameter to URI + /// + /// + /// + /// + /// + public static Uri AddQueryParmeter(this Uri uri, string name, string value) + { + var httpValueCollection = HttpUtility.ParseQueryString(uri.Query); + + httpValueCollection.Remove(name); + httpValueCollection.Add(name, value); + + var ub = new UriBuilder(uri); + ub.Query = httpValueCollection.ToString(); + + return ub.Uri; + } + } } diff --git a/CryptoExchange.Net/Objects/Options.cs b/CryptoExchange.Net/Objects/Options.cs index 9116da5..27565c4 100644 --- a/CryptoExchange.Net/Objects/Options.cs +++ b/CryptoExchange.Net/Objects/Options.cs @@ -278,7 +278,7 @@ namespace CryptoExchange.Net.Objects /// /// Whether or not to automatically sync the local time with the server time /// - public bool AutoTimestamp { get; set; } = true; + public bool AutoTimestamp { get; set; } /// /// ctor