1
0
mirror of https://github.com/JKorf/CryptoExchange.Net synced 2025-06-10 17:36:19 +00:00

Merge pull request #11 from mql4coder/master

Proxy authentication added
This commit is contained in:
Jan Korf 2019-02-12 08:47:59 +01:00 committed by GitHub
commit cacc096111
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 31 additions and 3 deletions

View File

@ -11,7 +11,7 @@ namespace CryptoExchange.Net.Interfaces
WebHeaderCollection Headers { get; set; }
string Method { get; set; }
TimeSpan Timeout { get; set; }
void SetProxy(string host, int port);
void SetProxy(string host, int port, string login, string password);
string ContentType { get; set; }
string Content { get; set; }

View File

@ -13,6 +13,16 @@ namespace CryptoExchange.Net.Objects
/// </summary>
public int Port { get; }
/// <summary>
/// The login of the proxy
/// </summary>
public string Login { get; }
/// <summary>
/// The password of the proxy
/// </summary>
public string Password { get; }
/// <summary>
/// Create new settings for a proxy
/// </summary>
@ -26,5 +36,22 @@ namespace CryptoExchange.Net.Objects
Host = host;
Port = port;
}
/// <inheritdoc />
/// <summary>
/// Create new settings for a proxy
/// </summary>
/// <param name="host">The proxy hostname/ip</param>
/// <param name="port">The proxy port</param>
/// <param name="login">The proxy login</param>
/// <param name="password">The proxy password</param>
public ApiProxy(string host, int port, string login, string password) : this(host, port)
{
if (string.IsNullOrEmpty(login) || string.IsNullOrEmpty(password))
throw new ArgumentException("Proxy login or password not filled");
Login = login;
Password = password;
}
}
}

View File

@ -54,9 +54,10 @@ namespace CryptoExchange.Net.Requests
public Uri Uri => request.RequestUri;
public void SetProxy(string host, int port)
public void SetProxy(string host, int port, string login, string password)
{
request.Proxy = new WebProxy(host, port);
if(!string.IsNullOrEmpty(login) && !string.IsNullOrEmpty(password)) request.Proxy.Credentials = new NetworkCredential(login, password);
}
public async Task<Stream> GetRequestStream()

View File

@ -129,7 +129,7 @@ namespace CryptoExchange.Net
if (apiProxy != null)
{
log.Write(LogVerbosity.Debug, "Setting proxy");
request.SetProxy(apiProxy.Host, apiProxy.Port);
request.SetProxy(apiProxy.Host, apiProxy.Port, apiProxy.Login, apiProxy.Password);
}
foreach (var limiter in RateLimiters)