I'm trying to connect to Poloniex. To connect, I'm using WynthShop and this code:
public class Program
{
public static void Main(string[] args)
{
var channelFactory = new DefaultWampChannelFactory();
var channel = channelFactory.CreateJsonChannel("wss://api.poloniex.com", "realm1");
channel.Open().GetAwaiter().GetResult();
var tickerSubject = channel.RealmProxy.Services.GetSubject("ticker");
var cancellationTokenSource = new CancellationTokenSource();
using (var subscr = tickerSubject.Subscribe(evt =>
{
var currencyPair = evt.Arguments[0].Deserialize<string>();
var last = evt.Arguments[1].Deserialize<decimal>();
Console.WriteLine($"Currencypair: {currencyPair}, Last: {last}");
}))
{
Console.WriteLine("Press a key to exit");
Console.ReadKey();
cancellationTokenSource.Cancel();
}
}
}
But unfortunately I get the error "Unable to connect to the remote server". Maybe someone knows how to solve the problem with the connection. Also I tried to use the following code, but also fails to connect:
public class Program
{
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();
}
}
When you read the API doc, you can read:
WAMP = The Web Application Messaging Protocol
So you will have to chose a C# lib compatible with WAMP protocol, you may take a look here to find an comptable implementation.
In your case you may use WampSharp which is compatible with C#
I create the websocket myself specifying the SSL/TLS versions i can support