coinbasepro-csharp icon indicating copy to clipboard operation
coinbasepro-csharp copied to clipboard

No WebSocket Response

Open dsconsole283 opened this issue 3 years ago • 5 comments

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!

dsconsole283 avatar Oct 04 '21 18:10 dsconsole283

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

dougdellolio avatar Oct 04 '21 18:10 dougdellolio

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 avatar Oct 04 '21 21:10 dsconsole283

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??

dsconsole283 avatar Nov 11 '21 14:11 dsconsole283

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.

nickwhitley avatar Aug 10 '22 18:08 nickwhitley