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.NextBoolean() ? currentPrice + adjustment : currentPrice - adjustment; observer.OnNext(currentPrice); }); }); }
public CreateNewTradeRequest(BuyOrSell buyOrSell,CurrencyPair currencyPair,int amount, decimal rate) { if (currencyPair == null) throw new ArgumentNullException("currencyPair"); BuyOrSell = buyOrSell; CurrencyPair = currencyPair; Amount = amount; Rate = rate; }
public MarketDataTicker(CurrencyPair currencyPair, IObservable<MarketData> marketDataObservable) { if (currencyPair == null) throw new ArgumentNullException("currencyPair"); if (marketDataObservable == null) throw new ArgumentNullException("marketDataObservable"); CurrencyPair = currencyPair; _cleanUp = marketDataObservable. Subscribe(md => { Trend = Bid > md.Bid ? Trend.Up : Trend.Down; Bid = md.Bid; Offer = md.Offer; }); }
protected bool Equals(CurrencyPair other) { return(string.Equals(Code, other.Code)); }
protected bool Equals(CurrencyPair other) { return string.Equals(Code, other.Code); }