コード例 #1
0
        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);

                            });
            });
        }
コード例 #2
0
 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;
 }
コード例 #3
0
        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;
                });
        }
コード例 #4
0
ファイル: CurrencyPair.cs プロジェクト: harshints/Financials
 protected bool Equals(CurrencyPair other)
 {
     return(string.Equals(Code, other.Code));
 }
コード例 #5
0
 protected bool Equals(CurrencyPair other)
 {
     return string.Equals(Code, other.Code);
 }