Example #1
0
        public async Task SubscribePriceStream(PriceSubscriptionRequestDto request)
        {
            _contextHolder.PricingHubClient = Clients;

            Log.InfoFormat("Received subscription request {0} from connection {1}", request, Context.ConnectionId);

            if (!_currencyPairRepository.Exists(request.CurrencyPair))
            {
                Log.WarnFormat("Received a subscription request for an invalid currency pair '{0}', it was ignored.", request.CurrencyPair);
                return;
            }

            // simulate slow response for EURCHF
            if (request.CurrencyPair == "EURCHF")
            {
                await Task.Delay(TimeSpan.FromSeconds(2));
            }

            // add client to this group
            var groupName = string.Format(PriceStreamGroupPattern, request.CurrencyPair);
            await Groups.Add(Context.ConnectionId, groupName);

            Log.InfoFormat("Connection {0} added to group '{1}'", Context.ConnectionId, groupName);

            // send current price to client
            var lastValue = _priceLastValueCache.GetLastValue(request.CurrencyPair);
            await Clients.Caller.OnNewPrice(lastValue);

            Log.InfoFormat("Snapshot published to {0}: {1}", Context.ConnectionId, lastValue);
        }
Example #2
0
        private void Reset(long _)
        {
            _analyticsService.Reset();
            _tradeRepository.Reset();

            // make 3 trades

            // eurusd
            // gbpusd
            // nzdusd
            foreach (var ccyPair in new [] { "EURUSD", "GBPUSD", "NZDUSD" })
            {
                try
                {
                    var price = _priceLastValueCache.GetLastValue(ccyPair);

                    var trade = new TradeRequestDto()
                    {
                        DealtCurrency = "EUR",
                        Direction     = DirectionDto.Buy,
                        Notional      = 500000,
                        SpotRate      = price.Bid,
                        Symbol        = ccyPair,
                        ValueDate     = DateTime.Now.ToNextWeekday(2)
                    };

                    _executionService.Execute(trade, "CPU-007").Wait(TimeSpan.FromSeconds(10));
                }
                catch
                {
                    // swallow exception
                }
            }
        }
        private void OnTimerTick(object state)
        {
            var activePairs = _currencyPairRepository.GetAllCurrencyPairInfos().Where(cp => cp.Enabled && !cp.Stale).ToList();

            if (activePairs.Count == 0)
            {
                return;
            }

            for (int i = 0; i < _updatesPerTick; i++)
            {
                var randomCurrencyPairInfo = activePairs[_random.Next(0, activePairs.Count)];
                var lastPrice = _priceLastValueCache.GetLastValue(randomCurrencyPairInfo.CurrencyPair.Symbol);

                var newPrice = randomCurrencyPairInfo.GenerateNextQuote(lastPrice);
                _priceLastValueCache.StoreLastValue(newPrice);
                _pricePublisher.Publish(newPrice);
            }
        }