2017-09-09 75 views
3

我想實時從Poloniex中檢索報價。他們使用wamp。我通過金塊WampSharp安裝,發現這個代碼:HTTP 502錯誤的網關C#與poloniex上的瓦爾

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(); 
    } 

但在伺機channel.open不管()我有以下錯誤:HHTP 502網關

你有一個想法,哪裏是問題

預先感謝您

+0

你解決了這個問題嗎? –

+0

你可以試試這個要點。 https://gist.github.com/darkl/bc545b04c8d557246ef34eb4d7e8baea – darkl

+0

謝謝你的作品,你會添加一個答案,或者我應該把它自己的線程? – ronki

回答

2

Poloniex服務似乎無法處理如此多的連接。這就是爲什麼你會得到HTTP 502錯誤的網關錯誤。您可以嘗試使用重新連接機制以嘗試定期連接。

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代碼示例。

+0

你怎麼能說這是問題? 這意味着您如何知道故障會給他們的服務帶來負擔? –

+1

https://github.com/BitBotFactory/poloniexlendingbot/issues/327 – darkl

+1

https://www.reddit.com/r/BitcoinMarkets/comments/6a634t/poloniex_api/?utm_source=amp&utm_medium=comment_list – darkl

0

擺脫Console.WriteLine它與你的代碼干擾。

+0

好吧,但錯誤到達之前等待channel.open() 前兩行你認爲console.writeline可以錯誤地打開我嗎? 如果是的話我怎麼能寫出輸出 謝謝 – ronki

相關問題