private IObservable<MarketData> GenerateStream(CurrencyPair currencyPair)
        {

            return Observable.Create<MarketData>(observer =>
            {
                var spread = currencyPair.DefaultSpread;
                var midRate = currencyPair.InitialPrice;
                var bid = midRate - (spread * currencyPair.PipSize);
                var offer = midRate + (spread * currencyPair.PipSize);
                var initial = new MarketData(currencyPair.Code, bid, offer);

                var currentPrice = initial;
                observer.OnNext(initial);

                var random = new Random();


                //for a given period, move prices by up to 5 pips
                return Observable.Interval(TimeSpan.FromSeconds(1 / (double)currencyPair.TickFrequency))
                    .Select(_ => random.Next(1, 5))
                    .Subscribe(pips =>
                    {
                        //move up or down between 1 and 5 pips
                        var adjustment = Math.Round(pips * currencyPair.PipSize, currencyPair.DecimalPlaces);
                        currentPrice = random.NextDouble() > 0.5
                                        ? currentPrice + adjustment
                                        : currentPrice - adjustment;
                        observer.OnNext(currentPrice);

                    });
            });
        }
        private decimal GererateRandomPrice(CurrencyPair currencyPair, BuyOrSell buyOrSell)
        {

            var price = _latestPrices.Lookup(currencyPair.Code)
                                .ConvertOr(md => md.Bid, () => currencyPair.InitialPrice);

            //generate percent price 1-100 pips away from the inital market
            var pipsFromMarket = _random.Next(1, 100);
            var adjustment = Math.Round(pipsFromMarket * currencyPair.PipSize, currencyPair.DecimalPlaces);
            return buyOrSell == BuyOrSell.Sell ? price + adjustment : price - adjustment;
        }
Example #3
0
 protected bool Equals(CurrencyPair other)
 {
     return(string.Equals(Code, other.Code));
 }
 protected bool Equals(CurrencyPair other)
 {
     return string.Equals(_code, other._code);
 }