简体   繁体   English

HTTP 502坏网关c#与poloniex上的wamp

[英]HTTP 502 bad gateway c# with wamp on poloniex

I want to retrieve ticks from Poloniex in real time. 我想实时检索Poloniex的滴答声。 They use wamp for that. 他们使用wamp。 I installed via nugget WampSharp and found this code : 我通过nugget WampSharp安装并找到了这段代码:

  static async void MainAsync(string[] args)
    {

        var channelFactory = new DefaultWampChannelFactory();
        var channel = channelFactory.CreateMsgpackChannel("wss://api.poloniex.com", "realm1");
        await channel.Open();

        var realmProxy = channel.RealmProxy;

        Console.WriteLine("Connection established");

        int received = 0;
        IDisposable subscription = null;

        subscription =
            realmProxy.Services.GetSubject("ticker")
                      .Subscribe(x =>
                      {
                          Console.WriteLine("Got Event: " + x);

                          received++;

                          if (received > 5)
                          {
                              Console.WriteLine("Closing ..");
                              subscription.Dispose();
                          }
                      });

        Console.ReadLine();
    }

but no matter at the await channel.open() I have the following error : HHTP 502 bad gateway 但无论在等待channel.open()我有以下错误:HHTP 502坏网关

Do you have an idea where is the problem 你知道问题出在哪里吗?

thank you in advance 先感谢您

The Poloniex service seems not to be able to handle so many connections. Poloniex服务似乎无法处理这么多连接。 That's why you get the HTTP 502 bad gateway error. 这就是为什么你得到HTTP 502错误的网关错误。 You can try to use the reconnector mechanism in order to try connecting periodically. 您可以尝试使用重新连接器机制以尝试定期连接。

static void Main(string[] args)
{
    var channelFactory = new DefaultWampChannelFactory();
    var channel = channelFactory.CreateJsonChannel("wss://api.poloniex.com", "realm1");

    Func<Task> connect = async () =>
    {
        await Task.Delay(30000);

        await channel.Open();

        var tickerSubject = channel.RealmProxy.Services.GetSubject("ticker");

        var subscription = tickerSubject.Subscribe(evt =>
        {
            var currencyPair = evt.Arguments[0].Deserialize<string>();
            var last = evt.Arguments[1].Deserialize<decimal>();
            Console.WriteLine($"Currencypair: {currencyPair}, Last: {last}");
        },
        ex => {
            Console.WriteLine($"Oh no! {ex}");
        });
    };

    WampChannelReconnector reconnector =
        new WampChannelReconnector(channel, connect);

    reconnector.Start();

    Console.WriteLine("Press a key to exit");
    Console.ReadKey();
}

This is based on this code sample. 这是基于代码示例。

摆脱Console.WriteLine它干扰你的代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM