public override PriceDto GenerateNextQuote(PriceDto previousPrice)
        {
            var pow = (decimal)Math.Pow(10, CurrencyPair.RatePrecision);
            var movement = 5 / pow;

            decimal newMid;
            if (_isIncreasing)
            {
                newMid = previousPrice.Mid + movement;
                if (newMid > _max)
                    _isIncreasing = false;
            }
            else
            {
                newMid = previousPrice.Mid - movement;
                if (newMid < _min)
                    _isIncreasing = true;
            }

            return new PriceDto
            {
                Symbol = previousPrice.Symbol,
                QuoteId = previousPrice.QuoteId + 1,
                ValueDate = DateTime.UtcNow.AddDays(2).Date,
                Mid = newMid,
                Ask = newMid + 5 / pow,
                Bid = newMid - 5 / pow,
                CreationTimestamp = Stopwatch.GetTimestamp()
            };
        }
Пример #2
0
        public IPrice Create(PriceDto priceDto, ICurrencyPair currencyPair)
        {
            var bid = new ExecutablePrice(Direction.SELL, priceDto.Bid, _executionRepository);
            var ask = new ExecutablePrice(Direction.BUY, priceDto.Ask, _executionRepository);
            var price = new Price(bid, ask, priceDto.SpotDate, currencyPair, priceDto.CreationTimestamp);

            _priceLatencyRecorder.OnReceived(price);

            return price;
        }
        public void OnPrice(PriceDto priceDto)
        {
            _eventLoopScheduler.Schedule(() => 
            {
                _priceCache[priceDto.Symbol] = priceDto;
                var currencyPairTracker = GetTrackerFor(priceDto.Symbol);
                currencyPairTracker.OnPrice(_priceCache, false);

            });
        }
Пример #4
0
        private void PopulateLastValueCache()
        {
            foreach (var currencyPairInfo in _currencyPairRepository.GetAllCurrencyPairs())
            {
                var mid = _currencyPairRepository.GetSampleRate(currencyPairInfo.CurrencyPair.Symbol);

                var initialQuote = new PriceDto
                {
                    Symbol = currencyPairInfo.CurrencyPair.Symbol,
                    Mid = mid
                };

                _priceLastValueCache.StoreLastValue(currencyPairInfo.GenerateNextQuote(initialQuote));
            }
        }
        public override PriceDto GenerateNextQuote(PriceDto previousPrice)
        {
            var pow = (decimal)Math.Pow(10, CurrencyPair.RatePrecision);
            var newMid = previousPrice.Mid + _random.Next(-5, 5) / pow;

            return new PriceDto
            {
                Symbol = previousPrice.Symbol,
                QuoteId = previousPrice.QuoteId + 1,
                ValueDate = DateTime.UtcNow.AddDays(2).Date,
                Mid = newMid,
                Ask = newMid + 5 / pow,
                Bid = newMid - 5 / pow,
                CreationTimestamp = Stopwatch.GetTimestamp()
            };
        }
Пример #6
0
        public async Task Publish(PriceDto price)
        {
            var context = _contextHolder.PricingHubClient;
            if (context == null) return;

            _totalUpdatesPublished++;
            var groupName = string.Format(PricingHub.PriceStreamGroupPattern, price.Symbol);
            try
            {
                await context.Group(groupName).OnNewPrice(price);
                if (Log.IsDebugEnabled)
                {
                    Log.DebugFormat("Published price to group {0}: {1}", groupName, price);
                }
            }
            catch (Exception e)
            {
                Log.Error(string.Format("An error occured while publishing price to group {0}: {1}", groupName, price), e);
            }
        }
        public override PriceDto GenerateNextQuote(PriceDto previousPrice)
        {
            var pow = (decimal)Math.Pow(10, CurrencyPair.RatePrecision);
            var newMid = previousPrice.Mid + Random.Next(-5, 5) / pow;

            // check that the new mid does not drift too far from sampleRate (3%)
            if (Math.Abs(newMid - SampleRate)/SampleRate > .03m)
            {
                newMid = SampleRate;
            }

            return new PriceDto
            {
                Symbol = previousPrice.Symbol,
                SpotDate = DateTime.UtcNow.AddDays(2).Date,
                Mid = newMid,
                Ask = newMid + _halfSpread / pow,
                Bid = newMid - _halfSpread / pow,
                CreationTimestamp = Stopwatch.GetTimestamp()
            };
        }
 public void StoreLastValue(PriceDto price)
 {
     _lastValueCache.AddOrUpdate(price.Symbol, _ => price, (s, p) => price);
 }
Пример #9
0
 public abstract PriceDto GenerateNextQuote(PriceDto lastPrice);