JKorf / Binance.Net

A C# .netstandard client library for the Binance REST and Websocket Spot and Futures API focusing on clear usage and models
https://jkorf.github.io/Binance.Net/
MIT License
1.02k stars 420 forks source link

Proxy is not working with CryptoExchange.Net 6.2.1 and Binance.net 9.1.6 #1317

Closed jdponomarev closed 6 months ago

jdponomarev commented 7 months ago

Describe the bug Since I upgraded to CryptoExchange.Net 6.2.1 and Binance.net 9.1.6, my traffic is not coming through proxy anymore. Same issue for Kucoin.net and Kraken.net after I updated to the latest version, no traffic going through my proxy.

To Reproduce Initialise Binance like this, with proxy credentials that are 100% wrong: BinanceRestClient.SetDefaultOptions(options => { options.Proxy = new ApiProxy("123", 123, "123", "123"); }); services.AddScoped<IBinanceRestClient, BinanceRestClient>();

Expected behavior This should fail every for call, but it still works, even thought I can see Client Options have Proxy on the client. If I set up correct proxy details it is expected to use the proxy, but it doesn't

JKorf commented 7 months ago

Hi, I tried this but seems to work with this minimal example:

BinanceRestClient.SetDefaultOptions(options => { options.Proxy = new ApiProxy("123", 123, "123", "123"); }); 
var services = new ServiceCollection();
services.AddScoped<IBinanceRestClient, BinanceRestClient>();
var provider = services.BuildServiceProvider();

var client = provider.GetRequiredService<IBinanceRestClient>();
await client.SpotApi.ExchangeData.GetBookPricesAsync();

This throws an exception since the proxy is an invalid uri. Can you provide a minimal reproduction scenario?

jdponomarev commented 7 months ago

hey @JKorf I've tried to create a minimal example project with this issue, but couldn't... A minimal example like yours works for me.

In my project it just does pick it up when configured in ConfigureServices at Startup.cs with BinanceRestClient.SetDefaultOptions. I can see other options are set up correctly, and the proxy is actually set too, but is not used and doesn't throw errors on invalid configuration.

I actually ended up creating clients like this and it works perfect for me:

_binanceClient = new BinanceRestClient((options =>
{
    options.Environment = BinanceEnvironment.Live;
    options.ApiCredentials = new ApiCredentials(binanceSettings.ApiKey, binanceSettings.ApiSecret);
    options.Proxy = new ApiProxy(configuration["Proxy:host"], int.Parse(configuration["Proxy:port"]),
            configuration["Proxy:login"], configuration["Proxy:password"]);
}));

I'm using other CryptoExchange.Net libraries too (all at latest versions). I'll let you know if I'm able to figure it out

JKorf commented 6 months ago

If you manage to reproduce it with an example please let me know, for now I'll close this