coinbasepro-csharp
coinbasepro-csharp copied to clipboard
No WebSocket Response
Hello!
I just want to preface by letting you know that I am not very experienced in any of this...
Hopefully this isn't user error, but I can't seem to get a response from any event available with the websocket. I have received bid/ask information using the REST API (var result = await client.ProductsService.GetProductTickerAsync("ADA-USD");
), but the websocket status only ever says "connecting" and never invokes any event. I guess my actual question is: has anything changed or are there any known issues as to why this may not be working? Or is this most likely an error on my part? Thanks for any help!
hi @dsconsole283 the websocket seems to be working on my end. Here is an example snippet you can try. You should fill in the authenticator with your sandbox credentials and use the readme if you need some help with that.
(https://github.com/dougdellolio/coinbasepro-csharp#how-to-use)
Example code:
public class Program
{
public static void Main(string[] args)
{
//fill this in with your own authenticator
var authenticator = new Authenticator(...);
//create the CoinbasePro client using the sandbox
var coinbaseProClient = new CoinbaseProClient(authenticator, true);
//subscribe to the ticker channel type
var productTypes = new List<string> { "BTC-USD" };
var channels = new List<ChannelType> { ChannelType.Full };
var webSocket = coinbaseProClient.WebSocket;
webSocket.Start(productTypes, channels);
webSocket.OnDoneReceived += (sender, e) =>
{
Print(e);
};
Console.ReadKey();
}
private static void Print(WebfeedEventArgs<Done> webfeedEventArgs)
{
Console.WriteLine("OrderId = " + webfeedEventArgs.LastOrder.OrderId);
Console.WriteLine("Price = " + webfeedEventArgs.LastOrder.Price);
Console.WriteLine("Reason = " + webfeedEventArgs.LastOrder.Reason);
Console.WriteLine("Remaining Size = " + webfeedEventArgs.LastOrder.RemainingSize);
Console.WriteLine("Side = " + webfeedEventArgs.LastOrder.Side);
Console.WriteLine("==============");
}
}
Thank you so much! I'll give it a try. It's strange because my code is similar except for the subscriber method.. I basically just cemented the understanding of events today, so I have some refining to do. Thanks again! PS I'm looking for a C# friend/mentor if anyone sees this and is generous enough to lend their time!
Not sure if this is the right spot for this, but I always eventually get this disconnect exception
It doesn't point to any lines in my own code, so I'm assuming it's an unhandled exception in the library??
Hey @dsconsole283 you seem like a right ol' chum. I can mentor you in the world of programming. I am, as they say, an expert. A Grand Champ in programming if you will. So just let me know.