dougdellolio / coinbasepro-csharp

The unofficial .NET/C# client library for the Coinbase Pro/GDAX API
MIT License
192 stars 90 forks source link

No WebSocket Response #296

Open dsconsole283 opened 3 years ago

dsconsole283 commented 3 years ago

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!

dougdellolio commented 3 years ago

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("==============");
        }
    }
dsconsole283 commented 3 years ago

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!

dsconsole283 commented 2 years ago

Not sure if this is the right spot for this, but I always eventually get this disconnect exception

Screenshot 2021-11-11 061508

It doesn't point to any lines in my own code, so I'm assuming it's an unhandled exception in the library??

nickwhitley commented 2 years ago

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.