3

I want to retrieve ticks from Poloniex in real time. They use wamp for that. I installed via nugget WampSharp and found this code :

  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

Do you have an idea where is the problem

thank you in advance

RiggsFolly
  • 93,638
  • 21
  • 103
  • 149
ronki
  • 43
  • 4

2 Answers2

2

The Poloniex service seems not to be able to handle so many connections. That's why you get the HTTP 502 bad gateway error. 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.

darkl
  • 569
  • 2
  • 13
  • how can you tell that this is the issue ? meaning how do you know the fault lays with burden on their service ? – eran otzap Sep 18 '17 at 13:14
  • 1
    https://www.reddit.com/r/BitcoinMarkets/comments/6a634t/poloniex_api/?utm_source=amp&utm_medium=comment_list – darkl Sep 19 '17 at 07:59
0

Get rid of the Console.WriteLine it is interfering with your code.

KyloRen
  • 2,691
  • 5
  • 29
  • 59
  • Ok but the error arrive two line before at await channel.open() Do you think the console.writeline can bug my open? If yes how can i write the output Thank you – ronki Sep 09 '17 at 16:35