public async Task StartAsync(CancellationToken cancellationToken)
        {
            Session = await CreateSession();

            _disposable = new CompositeDisposable(
                Session,
                Session.Worker.Subscribe());
        }
        public async Task StartAsync(CancellationToken cancellationToken)
        {
            Session = await CreateSession();

            _disposable = new CompositeDisposable(
                // because publisher could be disabled in settings we call this implicitly
                Session.Worker.Subscribe(),
                Session);
        }
        private async Task <OrderBooksSession> CreateSession()
        {
            _converter = new InstrumentsConverter(await _restClient.GetInstruments());

            var orderBooks = _converter
                             .KrakenInstruments
                             .Select(i => PullOrderBooks(i, _settings.TimeoutBetweenQueries))
                             .Merge();

            return(OrderBooksSession.FromRawOrderBooks(
                       orderBooks,
                       _settings,
                       _logFactory));
        }
        private async Task <OrderBooksSession> CreateSession()
        {
            var exchangeInfo = await _client.GetExchangeInfo();

            var assets = exchangeInfo.Assets.ToArray();

            var streams = string.Join("/", assets.Select(x => $"{WebUtility.UrlEncode(x)?.ToLower()}@depth"));

            var orderBooks = ReadDepthUpdates(
                new ObservableWebSocket(
                    $"wss://stream.binance.com:9443/stream?streams={streams}",
                    x => _log.Info(x)))
                             .GroupBy(x => x.Asset)
                             .SelectMany(CombineWithSnapshot);

            return(OrderBooksSession.FromRawOrderBooks(orderBooks, _settings, _lf));
        }
Beispiel #5
0
        public OrderbookPublishingService(
            ILogFactory lf,
            CexIoAdapterSettings settings)
        {
            _log               = lf.CreateLog(this);
            _logFactory        = lf;
            _orderBookSettings = settings.OrderBooks;

            var rawOrderBooks = GetRawOrderBooks();

            Session = OrderBooksSession.FromRawOrderBooks(
                rawOrderBooks,
                settings.ToCommonSettings(),
                lf);

            Session.TickPrices.Subscribe(x =>
            {
                foreach (var tickPrice in x)
                {
                    InternalMetrics.QuoteOutCount
                    .WithLabels(tickPrice.Asset)
                    .Inc();

                    InternalMetrics.QuoteOutSidePrice
                    .WithLabels(tickPrice.Asset, "ask")
                    .Set((double)tickPrice.Ask);

                    InternalMetrics.QuoteOutSidePrice
                    .WithLabels(tickPrice.Asset, "bid")
                    .Set((double)tickPrice.Bid);

                    InternalMetrics.OrderBookOutCount
                    .WithLabels(tickPrice.Asset)
                    .Inc();

                    InternalMetrics.OrderBookOutDelayMilliseconds
                    .WithLabels(tickPrice.Asset)
                    .Set((DateTime.UtcNow - tickPrice.Timestamp).TotalMilliseconds);
                }
            });
        }
Beispiel #6
0
        public async Task StartAsync(CancellationToken cancellationToken)
        {
            _log.WriteInfo(nameof(OrderbookPublishingService), "",
                           $"Listening orderbook for instruments: {string.Join(", ", _instruments)}, " +
                           "you can find supported instruments in documentation: https://www.bitstamp.net/websocket/");

            var orderbooks = Observable.Using(
                () => new DisposablePusher("de504dc5763aeef9ff52", _log),
                p => _instruments.Select(i => ProcessOrderBooks(p, i)).Merge());

            Session = orderbooks.FromRawOrderBooks(
                _instruments,
                new OrderBookProcessingSettings
            {
                AllowedAnomalisticAssets      = new string[0],
                MaxEventPerSecondByInstrument = _orderbookSettings.MaxEventPerSecondByInstrument,
                OrderBookDepth = 100,
                OrderBooks     = new RmqOutput
                {
                    ConnectionString = _rmqSettings.OrderBooks.ConnectionString,
                    Durable          = false,
                    Enabled          = _rmqSettings.OrderBooks.Enabled,
                    Exchanger        = _rmqSettings.OrderBooks.Exchanger
                },
                TickPrices = new RmqOutput
                {
                    ConnectionString = _rmqSettings.TickPrices.ConnectionString,
                    Durable          = false,
                    Enabled          = _rmqSettings.TickPrices.Enabled,
                    Exchanger        = _rmqSettings.TickPrices.Exchanger
                }
            },
                _logFactory);

            _subscription = new CompositeDisposable(
                Session,
                Session.Worker.Subscribe());
        }
 public OrderBooksController(OrderbookPublishingService obService)
 {
     Session = obService.Session;
 }
        public async Task StartAsync(CancellationToken cancellationToken)
        {
            OrderBooksSession = await CreateWorker();

            _worker = OrderBooksSession.Worker.Subscribe();
        }
Beispiel #9
0
 public OrderBooksController(OrderBooksPublishingService service)
 {
     Session = service.Session;
 }