public async Task ConnectToSource_ShouldHandleOrderBookCorrectly()
        {
            var url = FtxValues.ApiWebsocketUrl;

            using (var communicator = new FtxWebsocketCommunicator(url))
            {
                using (var client = new FtxWebsocketClient(communicator))
                {
                    var pair = "BTC-PERP";

                    var source    = new FtxOrderBookSource(client);
                    var orderBook = new CryptoOrderBook(pair, source);

                    await communicator.Start();

                    client.Send(new BookSubscribeRequest(pair));

                    await Task.Delay(TimeSpan.FromSeconds(5));

                    Assert.True(orderBook.BidPrice > 0);
                    Assert.True(orderBook.AskPrice > 0);

                    Assert.NotEmpty(orderBook.BidLevels);
                    Assert.NotEmpty(orderBook.AskLevels);
                }
            }
        }
Пример #2
0
        private static async Task <ICryptoOrderBook> StartFtx(string pair, bool optimized, bool l2Optimized)
        {
            var url          = FtxValues.ApiWebsocketUrl;
            var communicator = new FtxWebsocketCommunicator(url)
            {
                Name = "Ftx"
            };
            var client = new FtxWebsocketClient(communicator);

            var source    = new FtxOrderBookSource(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 BookSubscribeRequest(pair));

            return(orderBook);
        }
Пример #3
0
        static void Main(string[] args)
        {
            InitLogging();

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

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

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

            var url = FtxValues.ApiWebsocketUrl;

            using (var communicator = new FtxWebsocketCommunicator(url))
            {
                communicator.Name             = "Ftx-1";
                communicator.ReconnectTimeout = TimeSpan.FromMinutes(10);
                communicator.ReconnectionHappened.Subscribe(type =>
                                                            Log.Information($"Reconnection happened, type: {type.Type}"));

                using (var client = new FtxWebsocketClient(communicator))
                {
                    _ = StartPinging(client);

                    SendSubscriptionRequests(client).Wait();

                    SubscribeToStreams(client);

                    communicator.Start();

                    ExitEvent.WaitOne();
                }
            }

            Log.Debug("====================================");
            Log.Debug("              STOPPING              ");
            Log.Debug("====================================");
            Log.CloseAndFlush();
        }