public async Task ConnectTest()
        {
            var url = BitstampValues.ApiWebsocketUrl;

            using (var communicator = new BitstampWebsocketCommunicator(url))
            {
                HeartbeatResponse received = null;
                var receivedEvent          = new ManualResetEvent(false);

                using (var client = new BitstampWebsocketClient(communicator))
                {
                    client.Streams.HeartbeatStream.Subscribe(pong =>
                    {
                        received = pong;
                        receivedEvent.Set();
                    });

                    await communicator.Start();

                    client.Send(new SubscribeRequest("btcusd", Channel.Heartbeat));

                    receivedEvent.WaitOne(TimeSpan.FromSeconds(90));

                    Assert.NotNull(received);
                }
            }
        }
Example #2
0
        private static async Task<ICryptoOrderBook> StartBitstamp(string pair, bool optimized, bool l2Optimized)
        {
            var url = BitstampValues.ApiWebsocketUrl;
            var communicator = new BitstampWebsocketCommunicator(url) { Name = "Bitstamp" };
            var client = new BitstampWebsocketClient(communicator);

            var source = new BitstampOrderBookSource(client);
            var orderBook = l2Optimized ? 
                new CryptoOrderBookL2(pair, source) : 
                (ICryptoOrderBook)new CryptoOrderBook(pair, source);

            if (optimized)
            {
                ConfigureOptimized(source, orderBook);
            }

            _ = communicator.Start();

            // Send subscription request to order book data
            client.Send(new Bitstamp.Client.Websocket.Requests.SubscribeRequest(
                pair,
                Channel.OrderBook
            ));

            return orderBook;
        }
Example #3
0
        private static async Task Main(string[] args)
        {
            InitLogging();

            AppDomain.CurrentDomain.ProcessExit   += CurrentDomainOnProcessExit;
            AssemblyLoadContext.Default.Unloading += DefaultOnUnloading;
            Console.CancelKeyPress += ConsoleOnCancelKeyPress;

            Console.WriteLine("|=======================|");
            Console.WriteLine("|    COINBASE CLIENT    |");
            Console.WriteLine("|=======================|");
            Console.WriteLine();

            Log.Debug("====================================");
            Log.Debug("              STARTING              ");
            Log.Debug("====================================");


            var url = BitstampValues.ApiWebsocketUrl;

            using (var communicator = new BitstampWebsocketCommunicator(url))
            {
                communicator.Name = "Bitstamp-1";
                //communicator.ReconnectTimeoutMs = (int)TimeSpan.FromMinutes(1).TotalMilliseconds;

                using (var client = new BitstampWebsocketClient(communicator))
                {
                    SubscribeToStreams(client);

                    communicator.ReconnectionHappened.Subscribe(async type =>
                    {
                        Log.Information($"Reconnection happened, type: {type}, resubscribing..");
                        await SendSubscriptionRequests(client);
                    });

                    await communicator.Start();

                    ExitEvent.WaitOne();
                }
            }

            Log.Debug("====================================");
            Log.Debug("              STOPPING              ");
            Log.Debug("====================================");
            Log.CloseAndFlush();
        }
        private static (ITradeSource, IWebsocketClient) GetBitstamp(string pair)
        {
            var url          = BitstampValues.ApiWebsocketUrl;
            var communicator = new BitstampWebsocketCommunicator(url)
            {
                Name = "Bitstamp"
            };
            var client = new BitstampWebsocketClient(communicator);

            var source = new BitstampTradeSource(client);

            communicator.ReconnectionHappened.Subscribe(x =>
            {
                client.Send(new Bitstamp.Client.Websocket.Requests.SubscribeRequest(
                                pair,
                                Channel.Ticker
                                ));
            });

            return(source, communicator);
        }
Example #5
0
        public async Task OnStarting_ShouldGetInfoResponse()
        {
            var url = BitstampValues.ApiWebsocketUrl;

            using (var communicator = new BitstampWebsocketCommunicator(url))
            {
                string received      = null;
                var    receivedEvent = new ManualResetEvent(false);

                communicator.MessageReceived.Subscribe(msg =>
                {
                    received = msg.Text;
                    receivedEvent.Set();
                });

                await communicator.Start();

                communicator.Send("invalid test request");

                receivedEvent.WaitOne(TimeSpan.FromSeconds(30));

                Assert.NotNull(received);
            }
        }