public void StoreTrade(TradeDto trade)
 {
     lock (_trades)
     {
         _trades.Enqueue(trade);
     }
 }
 public void StoreTrade(TradeDto trade)
 {
     lock (_allTrades)
     {
         _allTrades.Add(trade);
     }
 }
        public Task Publish(TradeDto trade)
        {
            if (_contextHolder.BlotterHubClients == null) return Task.FromResult(false);

            Log.InfoFormat("Broadcast new trade to blotters: {0}", trade);
            return _contextHolder.BlotterHubClients.Group(BlotterHub.BlotterGroupName).OnNewTrade(new []{trade});
        }
        public void StoreTrade(TradeDto trade)
        {
            lock (_trades)
            {
                _trades.Enqueue(trade);

                if (_trades.Count > MaxTrades)
                {
                    _trades.Dequeue();
                }
            }
        }
 public ITrade Create(TradeDto trade)
 {
     return new Trade(
         trade.CurrencyPair,
         trade.Direction == DirectionDto.Buy ? Direction.BUY : Direction.SELL,
         trade.Notional,
         trade.DealtCurrency,
         trade.SpotRate,
         trade.Status == TradeStatusDto.Done ? TradeStatus.Done : TradeStatus.Rejected,
         trade.TradeDate,
         trade.TradeId,
         trade.TraderName,
         trade.ValueDate);
 }
        public void OnTrade(TradeDto trade)
        {
            _eventLoopScheduler.Schedule(() =>
            {
                CurrencyPairTracker currencyPairTracker;

                var currencyPair = trade.CurrencyPair;
                
                currencyPairTracker = GetTrackerFor(currencyPair);

                currencyPairTracker.OnTrade(trade, _priceCache);
                PublishPositionReport();
            });
        }
        public async Task<TradeDto> Execute(TradeRequestDto tradeRequest, string user)
        {
            var status = TradeStatusDto.Done;

            switch (tradeRequest.Symbol)
            {
                case "EURJPY":
                    await Task.Delay(TimeSpan.FromSeconds(5));
                    break;
                case "GBPUSD":
                    await Task.Delay(TimeSpan.FromSeconds(1.5));
                    break;
                default:
                    await Task.Delay(TimeSpan.FromSeconds(.5));
                    break;
            }
           
            if (tradeRequest.Symbol == "GBPJPY")
            {
                status = TradeStatusDto.Rejected;
            }

            var trade =  new TradeDto
            {
                CurrencyPair = tradeRequest.Symbol,
                Direction = tradeRequest.Direction,
                Notional = tradeRequest.Notional,
                SpotRate = tradeRequest.SpotRate,
                Status = status,
                TradeDate = DateTime.UtcNow,
                ValueDate = tradeRequest.ValueDate,
                TradeId = Interlocked.Increment(ref _tradeId),
                TraderName = user,
                DealtCurrency = tradeRequest.DealtCurrency
            };

            _tradeRepository.StoreTrade(trade);
            _analyticsService.OnTrade(trade);

            // publish trade asynchronously
            await _blotterPublisher.Publish(trade);

            
            return trade;
        }
        public void OnTrade(TradeDto trade, IDictionary<string, PriceDto> priceCache)
        {
            if (trade.Status != TradeStatusDto.Done)
                return;
            
            if (trade.Direction == DirectionDto.Buy)
            {
                _baseTradedAmount += trade.Notional;
                _counterTradedAmount += (trade.Notional*trade.SpotRate);
            }
            else
            {
                _baseTradedAmount -= trade.Notional;
                _counterTradedAmount -= (trade.Notional * trade.SpotRate);
            }
            _tradeCount++;

            OnPrice(priceCache, true);
        }