public Task ConfirmAsync(Guid tradeId)
 {
     return(_publisher.ProduceAsync(new TradeResponse
     {
         TraderId = tradeId.ToString(),
         Status = TradeStatus.Confirmed,
         StatusReason = string.Empty,
         Timestamp = Timestamp.FromDateTime(DateTime.UtcNow)
     }));
 }
示例#2
0
        public async Task SimplePublish()
        {
            const string expected = "GetDefaultHost message";

            _publisher.Start();

            SetupNormalQueue();

            await _publisher.ProduceAsync(expected);

            var result = ReadFromQueue();

            Assert.That(result, Is.EqualTo(expected));
        }
示例#3
0
        public async Task PublishAsync(PaymentRequestDetailsMessage message)
        {
            await _log.WriteInfoAsync(nameof(PaymentRequestPublisher), nameof(PublishAsync), $"message = {message.ToJson()}",
                                      "Publishing payment request status update message");

            await _publisher.ProduceAsync(message);
        }
        public static IObservable <Unit> PublishToRmq <T>(
            this IObservable <T> source,
            string connectionString,
            string exchanger,
            ILogFactory logFactory,
            bool isDurable)
        {
            const string prefix = "lykke.";

            if (exchanger.StartsWith(prefix))
            {
                exchanger = exchanger.Substring(prefix.Length);
            }

            var settings = RabbitMqSubscriptionSettings.CreateForPublisher(
                connectionString,
                exchanger);

            settings.IsDurable = isDurable;

            var connection
                = new RabbitMqPublisher <T>(logFactory, settings)
                  .SetSerializer(new JsonMessageSerializer <T>())
                  .SetPublishStrategy(new DefaultFanoutPublishStrategy(settings))
                  .PublishSynchronously()
                  .Start();

            return(source.SelectMany(async x =>
            {
                await connection.ProduceAsync(x);
                return Unit.Default;
            }));
        }
        public async Task PublishAsync(OrderBook message)
        {
            if (_publisher == null || !_publishingSettings.Enabled)
            {
                return;
            }

            try
            {
                await _publisher.ProduceAsync(message);
            }
            catch (Exception e)
            {
                var logMessage = $"OrderBookPublisher.PublishAsync() exception: ${e}.";

                if (e.Message.Contains("isn't started yet"))
                {
                    _log.Debug(logMessage);
                }
                else
                {
                    _log.Warning(logMessage);
                }
            }
        }
示例#6
0
        public async Task PublishAsync(TickPrice message)
        {
            if (_publisher == null || !_settting.Enabled)
            {
                return;
            }

            try
            {
                await _publisher.ProduceAsync(message);
            }
            catch (Exception e)
            {
                var logMessage = $"TickPricePublisher.PublishAsync() exception: ${e}.";

                if (e.Message.Contains("isn't started yet"))
                {
                    _log.Info(logMessage);
                }
                else
                {
                    _log.Warning(logMessage);
                }
            }
        }
示例#7
0
        private Task PublishV2Async(IEnumerable <CandleUpdateResult> updates)
        {
            var @event = new CandlesUpdatedEvent
            {
                ContractVersion = Contract.Constants.ContractVersion,
                UpdateTimestamp = DateTime.UtcNow,
                Candles         = updates
                                  .Select(c => new CandleUpdate
                {
                    IsLatestChange        = c.IsLatestChange,
                    ChangeTimestamp       = c.Candle.LatestChangeTimestamp,
                    AssetPairId           = c.Candle.AssetPairId,
                    PriceType             = c.Candle.PriceType,
                    TimeInterval          = c.Candle.TimeInterval,
                    CandleTimestamp       = c.Candle.Timestamp,
                    Open                  = c.Candle.Open,
                    Close                 = c.Candle.Close,
                    Low                   = c.Candle.Low,
                    High                  = c.Candle.High,
                    TradingVolume         = c.Candle.TradingVolume,
                    TradingOppositeVolume = c.Candle.TradingOppositeVolume,
                    IsLatestCandle        = true,
                    LastTradePrice        = 0
                })
                                  .ToArray()
            };

            lock (_publisher)
            {
                // HACK: Actually ProduceAsync is not async, so lock works well

                return(_publisher.ProduceAsync(@event));
            }
        }
示例#8
0
        public async Task PublishAsync(IInvoiceConfirmation invoiceConfirmation)
        {
            Validate(invoiceConfirmation);

            await _publisher.ProduceAsync(invoiceConfirmation);

            _log.Info("Invoice confirmation is published.", invoiceConfirmation);
        }
示例#9
0
 public Task Handle(T message)
 {
     if (!_enabled)
     {
         return(Task.CompletedTask);
     }
     lock (_sync)
     {
         return(_rabbitPublisher.ProduceAsync(message));
     }
 }
 public Task PublishAsync(Quote quote)
 {
     return(_publisher.ProduceAsync(new TickPrice
     {
         Asset = quote.AssetPair,
         Ask = quote.Ask,
         Bid = quote.Bid,
         Timestamp = quote.Time,
         Source = $"LiquidityEngine{_instanceName}"
     }));
 }
 public async Task Publish(IReadOnlyCollection <FixQuoteModel> quotes)
 {
     try
     {
         await _publisher.ProduceAsync(quotes.ToArray());
     }
     catch (System.Exception exception)
     {
         await _log.WriteErrorAsync(nameof(FixQuotePublisher), nameof(Publish), "Publishing fix quotes", exception);
     }
     await _log.WriteInfoAsync(nameof(FixQuotePublisher), nameof(Publish), "Publishing fix quotes", $"{quotes.Count} fix quotes has been successfully published");
 }
 public async Task Publish(Domain.Price price)
 {
     try
     {
         await _publisher.ProduceAsync(Mapper.Map <Price>(price));
     }
     catch (Exception e)
     {
         _log.Warning("Could not publish price.", e);
         throw;
     }
 }
示例#13
0
        public static void Example(RabbitMqSubscriptionSettings settings)
        {
            var connection = new RabbitMqPublisher <string>(new NullLoggerFactory(), settings)
                             .SetSerializer(new TestMessageSerializer())
                             .SetPublishStrategy(new DefaultFanoutPublishStrategy(settings));

            connection.Start();

            for (var i = 0; i <= 10; i++)
            {
                connection.ProduceAsync("message#" + i);
            }
        }
        public void Publish(Contract.IndexTickPrice tickPrice)
        {
            _publisher.ProduceAsync(new Contract.IndexTickPrice
            {
                Source     = tickPrice.Source,
                AssetPair  = tickPrice.AssetPair,
                Ask        = tickPrice.Ask ?? 0,
                Bid        = tickPrice.Bid ?? 0,
                Timestamp  = tickPrice.Timestamp,
                AssetsInfo = tickPrice.AssetsInfo.Select(x => new Contract.AssetInfo(x.AssetId, x.Weight, x.Price, x.IsDisabled)).ToList()
            });

            _log.Info($"Published tick price: {tickPrice.ToJson()}.");
        }
示例#15
0
        public Task PublishAsync(Domain.OrderBook orderBook)
        {
            IEnumerable <OrderBookItem> sellOrderBookItems = orderBook.LimitOrders
                                                             .Where(o => o.Type == Domain.LimitOrderType.Sell)
                                                             .OrderBy(o => o.Price)
                                                             .Select(o => new OrderBookItem(o.Price, o.Volume));

            IEnumerable <OrderBookItem> buyOrderBookItems = orderBook.LimitOrders
                                                            .Where(o => o.Type == Domain.LimitOrderType.Buy)
                                                            .OrderByDescending(o => o.Price)
                                                            .Select(o => new OrderBookItem(o.Price, o.Volume));

            return(_publisher.ProduceAsync(new OrderBook($"LiquidityEngine{_instanceName}", orderBook.AssetPairId,
                                                         orderBook.Time, sellOrderBookItems, buyOrderBookItems)));
        }
        public static void Example(RabbitMqSubscriptionSettings settings)
        {
            var connection
                = new RabbitMqPublisher <string>(LegacyLykkeLogFactoryToConsole.Instance, settings)
                  .SetSerializer(new TestMessageSerializer())
                  .SetPublishStrategy(new DefaultFanoutPublishStrategy(settings))
                  .DisableInMemoryQueuePersistence()
                  .Start();


            for (var i = 0; i <= 10; i++)
            {
                connection.ProduceAsync("message#" + i);
                Thread.Sleep(3000);
            }
        }
        public async Task PublishAsync(string exchangeName, Domain.OrderBook orderBook)
        {
            var message = new OrderBook(
                exchangeName,
                orderBook.Pair,
                DateTime.UtcNow,
                orderBook.Asks.Select(x => new OrderBookItem(x.Price, x.RemainingVolume)),
                orderBook.Bids.Select(x => new OrderBookItem(x.Price, x.RemainingVolume)));

            if (message.AskLevels.IsEmpty && message.BidLevels.IsEmpty)
            {
                return;
            }

            await _publisher.ProduceAsync(message);
        }
示例#18
0
        public Task PublishAsync(Domain.TickPrice tickPrice)
        {
            if (tickPrice.Ask == 0 || tickPrice.Bid == 0)
            {
                return(Task.CompletedTask);
            }

            var message = new TickPrice
            {
                Source    = tickPrice.Source,
                Asset     = tickPrice.AssetPair,
                Timestamp = tickPrice.Timestamp,
                Ask       = tickPrice.Ask,
                Bid       = tickPrice.Bid
            };

            return(_publisher.ProduceAsync(message));
        }
        public async Task PublishAsync(IPaymentRequestTransaction transaction)
        {
            var message = new NewTransactionMessage
            {
                Id            = transaction.TransactionId,
                AssetId       = transaction.AssetId,
                Amount        = transaction.Amount,
                Confirmations = transaction.Confirmations,
                BlockId       = transaction.BlockId,
                Blockchain    = Enum.Parse <BlockchainType>(transaction.Blockchain.ToString()),
                //todo
                DueDate = transaction.DueDate ?? DateTime.UtcNow.AddDays(1)
            };

            _log.Info("Publishing new transaction message", message);

            await _publisher.ProduceAsync(message);
        }
示例#20
0
        public async Task PublishAsync(IPaymentRequestTransaction transaction)
        {
            var message = new NewTransactionMessage
            {
                Id            = transaction.TransactionId,
                AssetId       = transaction.AssetId,
                Amount        = transaction.Amount,
                Confirmations = transaction.Confirmations,
                BlockId       = transaction.BlockId,
                Blockchain    = Enum.Parse <BlockchainType>(transaction.Blockchain.ToString()),
                DueDate       = transaction.DueDate
            };

            await _log.WriteInfoAsync(nameof(TransactionPublisher), nameof(PublishAsync), message.ToJson(),
                                      "Publishing new transaction message");

            await _publisher.ProduceAsync(message);
        }
示例#21
0
        public void ShouldNotPublishNonSeriazableMessage()
        {
            var publisher = new RabbitMqPublisher <ComplexType>(EmptyLogFactory.Instance, _settings);

            publisher
            .SetPublishStrategy(new DefaultFanoutPublishStrategy(_settings))
            .DisableInMemoryQueuePersistence()
            .SetSerializer(new JsonMessageSerializer <ComplexType>())
            .Start();

            var invalidObj = new ComplexType
            {
                A = 10
            };

            invalidObj.B = invalidObj;

            Assert.ThrowsAsync <JsonSerializationException>(() => publisher.ProduceAsync(invalidObj));
        }
示例#22
0
        private IObservable <Unit> CreateWorker()
        {
            var feeds = GetFeeds().ToArray();

            _log.Info($"Producing {feeds.Length} feeds");

            _publisher = CreatePublisher(_settings.RabbitMq, _settings.OutputExchanger, _logFactory);

            return(feeds
                   .Merge()
                   .SelectMany(async x =>
            {
                await _publisher.ProduceAsync(x);
                return x;
            })
                   .Do(x => _log.Debug(JsonConvert.SerializeObject(x)),
                       err => _log.Error(err))
                   .RetryWithBackoff(TimeSpan.FromSeconds(1), TimeSpan.FromMinutes(10))
                   .Select(_ => Unit.Default));
        }
示例#23
0
        public Task StartAsync(CancellationToken cancellationToken)
        {
            var lykkeTickPrices = GetLykkeTickPrices().Share();

            var bitstampOrderbooks = GetBitstampOrderbooks().Share();

            _publisher = CreatePublisher(_settings.RabbitMq, _settings.OutputExchanger, _logFactory);

            _worker = GetFeeds(lykkeTickPrices, bitstampOrderbooks)
                      .Merge()
                      .SelectMany(async ob =>
            {
                await _publisher.ProduceAsync(ob);
                return(Unit.Default);
            })
                      .RetryWithBackoff(TimeSpan.FromSeconds(1), TimeSpan.FromMinutes(10))
                      .Subscribe(
                _ => { },
                err => _log.Error(err));

            return(Task.CompletedTask);
        }
示例#24
0
        public async Task PublishAsync(List <TradeLogItem> message)
        {
            await _lock.WaitAsync();

            try
            {
                var publishStart = DateTime.UtcNow;
                await _publisher.ProduceAsync(message);

                var publishTime = DateTime.UtcNow.Subtract(publishStart);
                if (publishTime > _timeThreshold)
                {
                    _log.WriteWarning(nameof(TradesPublisher), nameof(PublishAsync), $"Long publish ({publishTime}): {message.ToJson()}");
                    _publisher.Stop();
                    _publisher.Start();
                }
            }
            finally
            {
                _lock.Release();
            }
        }
示例#25
0
        public async Task PublishAsync(INotificationMessage notificationMessage)
        {
            Validate(notificationMessage);

            await Task.WhenAll(_publisher.ProduceAsync(notificationMessage));
        }
 public async Task PublishAsync(FxTickPrice message)
 {
     await _publisher.ProduceAsync(message);
 }
示例#27
0
 public async Task PublishAsync(NewWalletMessage message)
 {
     await _publisher.ProduceAsync(message);
 }
        public void Publish(Contract.MarketMakers marketMakers)
        {
            _publisher.ProduceAsync(marketMakers);

            _log.Info($"Published market makers: {marketMakers.ToJson()}.");
        }
示例#29
0
 public async Task PublishAsync(RestoreMessage message)
 {
     await _publisher.ProduceAsync(message);
 }
 public Task PublishAsync(OrderBookUpdateReport orderBookUpdateReport)
 {
     return(_publisher.ProduceAsync(orderBookUpdateReport));
 }