コード例 #1
0
        public SpotTilePricingViewModel(ICurrencyPair currencyPair, SpotTileSubscriptionMode spotTileSubscriptionMode, ISpotTileViewModel parent,
                                        Func <Direction, ISpotTilePricingViewModel, IOneWayPriceViewModel> oneWayPriceFactory,
                                        IReactiveTrader reactiveTrader,
                                        IConcurrencyService concurrencyService,
                                        IConstantRatePump constantRatePump,
                                        ILoggerFactory loggerFactory)
        {
            _currencyPair         = currencyPair;
            _subscriptionMode     = spotTileSubscriptionMode;
            _parent               = parent;
            _priceLatencyRecorder = reactiveTrader.PriceLatencyRecorder;
            _concurrencyService   = concurrencyService;
            _constantRatePump     = constantRatePump;
            _log = loggerFactory.Create(typeof(SpotTilePricingViewModel));

            _priceSubscription = new SerialDisposable();
            Bid           = oneWayPriceFactory(Direction.SELL, this);
            Ask           = oneWayPriceFactory(Direction.BUY, this);
            Notional      = "1000000";
            DealtCurrency = currencyPair.BaseCurrency;
            SpotDate      = "SP";
            IsSubscribing = true;

            SubscribeForPrices();
        }
コード例 #2
0
        static LimitedNotificationTrader GetTrader(ICurrencyPair currencyPair, IObservable <PriceDto> priceStream)
        {
            var trader = new LimitedNotificationTrader();

            trader.Initialize(priceStream, currencyPair);
            return(trader);
        }
コード例 #3
0
        public CurrencyPairFutureMasterCorrelations GetCurrencyFuturesCorrelations(ICurrencyPair currencyPair)
        {
            var result = new CurrencyPairFutureMasterCorrelations {
                CurrencyPair = currencyPair
            };

            /// If this currency pair is a major currency cross, eg AUD/USD, then we'll be able to find a single future master.
            var correlation = GetSingleContractCorrelation(currencyPair.BaseCurrency, currencyPair.QuoteCurrency);

            if (null != correlation)
            {
                result.FutureMastersCorrelations = new[] { correlation };
                return(result);
            }

            /// If this currency pair is NOT a major currency cross, eg AUD/NZD, we'll need to find a combination of future masters using a common major currency cross.
            /// TODO: At the moment, there is no preference given to the order in which major currencies are searched.
            var majors = _futuresMap.Select(m => m.FutureMasterQuote).Distinct().Select(s => CurrencyTypeExtensions.FromForexCode(s));

            foreach (var major in majors)
            {
                /// Note that it's important to get the input parameters in the correct order for each of these two lines below.
                var correlation1 = GetSingleContractCorrelation(currencyPair.BaseCurrency, major);
                var correlation2 = GetSingleContractCorrelation(major, currencyPair.QuoteCurrency);

                if (null != correlation1 && null != correlation2)
                {
                    result.FutureMastersCorrelations = new[] { correlation1, correlation2 };
                    return(result);
                }
            }

            throw new Exception($"Unable to find future master correlation for currency pair '{currencyPair.BaseCurrency}/{currencyPair.QuoteCurrency}'.");
        }
コード例 #4
0
        public SpotTilePricingViewModel(ICurrencyPair currencyPair, SpotTileSubscriptionMode spotTileSubscriptionMode, ISpotTileViewModel parent,
            Func<Direction, ISpotTilePricingViewModel, IOneWayPriceViewModel> oneWayPriceFactory,
            IReactiveTrader reactiveTrader,
            IConcurrencyService concurrencyService,
            IConstantRatePump constantRatePump,
            ILoggerFactory loggerFactory)
        {
            _currencyPair = currencyPair;
            _subscriptionMode = spotTileSubscriptionMode;
            _parent = parent;
            _priceLatencyRecorder = reactiveTrader.PriceLatencyRecorder;
            _concurrencyService = concurrencyService;
            _constantRatePump = constantRatePump;
            _log = loggerFactory.Create(typeof(SpotTilePricingViewModel));

            _priceSubscription = new SerialDisposable();
            Bid = oneWayPriceFactory(Direction.SELL, this);
            Ask = oneWayPriceFactory(Direction.BUY, this);
            Notional = "1000000";
            DealtCurrency = currencyPair.BaseCurrency;
            SpotDate = "SP";
            IsSubscribing = true;

            SubscribeForPrices();
        }
コード例 #5
0
 public void Initialize(IObservable<PriceDto> priceStream, ICurrencyPair currencyPair) 
 {
     _loggerFactory = new DebugLoggerFactory();
     var pricingServiceClient = new WatchPricingServiceClient(priceStream);
     var priceFactory = new PriceFactory(new WatchExecutionRepository(), new PriceLatencyRecorder());
     var priceRepository = new PriceRepository(pricingServiceClient, priceFactory, _loggerFactory);
     PriceStream = priceRepository.GetPriceStream(currencyPair);
 }
コード例 #6
0
        public void Initialize(IObservable <PriceDto> priceStream, ICurrencyPair currencyPair)
        {
            _loggerFactory = new DebugLoggerFactory();
            var pricingServiceClient = new WatchPricingServiceClient(priceStream);
            var priceFactory         = new PriceFactory(new WatchExecutionRepository(), new PriceLatencyRecorder());
            var priceRepository      = new PriceRepository(pricingServiceClient, priceFactory, _loggerFactory);

            PriceStream = priceRepository.GetPriceStream(currencyPair);
        }
コード例 #7
0
        public bool Matches(ICurrencyPair pair)
        {
            if (pair == null)
            {
                return false;
            }

            return (pair.BaseCurrency == _baseCurrency && pair.CounterCurrency == _counterCurrency);
        }
コード例 #8
0
        public bool Matches(ICurrencyPair pair)
        {
            if (pair == null)
            {
                return(false);
            }

            return(pair.BaseCurrency == _baseCurrency && pair.CounterCurrency == _counterCurrency);
        }
コード例 #9
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);
        }
コード例 #10
0
 public void UpdateSpecifiedPair(ICurrencyPair chosenPair)
 {
     using (HttpClient hc = new HttpClient())
     {
         HttpResponseMessage response = hc.GetAsync(string.Format("{0}{1}", GetSpecifiedPairURL, chosenPair.ShortName)).Result;
         string responseString        = response.Content.ReadAsStringAsync().Result;
         var    rawItem = JsonConvert.DeserializeObject <CurrencyPairResponseSpecific>(responseString.Substring(11, responseString.Length - 12));
         chosenPair.UpdateValues(new decimal(rawItem.Avg), new decimal(rawItem.Last), new decimal(rawItem.Buy), new decimal(rawItem.Sell), new decimal(rawItem.High), new decimal(rawItem.Low));
     }
 }
コード例 #11
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;
        }
コード例 #12
0
 public IObservable<IPrice> GetPriceStream(ICurrencyPair currencyPair)
 {
     return Observable.Defer(() => _pricingServiceClient.GetSpotStream(currencyPair.Symbol))
         .Select(p => _priceFactory.Create(p, currencyPair))
         .Catch(Observable.Return(new StalePrice(currencyPair))) // if the stream errors (server disconnected), we push a stale price
         .Repeat()                                               // and resubscribe
         .DetectStale(TimeSpan.FromSeconds(4),  Scheduler.Default)
         .Select(s => s.IsStale ? new StalePrice(currencyPair) : s.Update)
         .Publish()
         .RefCount();
 }
コード例 #13
0
        public Price(ExecutablePrice bid, ExecutablePrice ask, DateTime valueDate, ICurrencyPair currencyPair, long serverTimestamp)
        {
            _serverTimestamp = serverTimestamp;
            Bid          = bid;
            Ask          = ask;
            ValueDate    = valueDate;
            CurrencyPair = currencyPair;

            bid.Parent = this;
            ask.Parent = this;

            Spread = (ask.Rate - bid.Rate) * (long)Math.Pow(10, currencyPair.PipsPosition);
        }
コード例 #14
0
ファイル: Price.cs プロジェクト: 925coder/ReactiveTrader
        public Price(ExecutablePrice bid, ExecutablePrice ask, DateTime valueDate, ICurrencyPair currencyPair, long serverTimestamp)
        {
            _serverTimestamp = serverTimestamp;
            Bid = bid;
            Ask = ask;
            ValueDate = valueDate;
            CurrencyPair = currencyPair;

            bid.Parent = this;
            ask.Parent = this;

            Spread = (ask.Rate - bid.Rate)* (long)Math.Pow(10, currencyPair.PipsPosition);
        }
コード例 #15
0
        private void CurrencyChooseComboBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            ICurrencyPair temp = (ICurrencyPair)CurrencyChooseComboBox.SelectedItem;

            Graph.Titles.Clear();
            if (temp != null)
            {
                Title t = new Title(RadioButtonSN.IsChecked.Value ? temp.ShortName : temp.FullName);
                t.Font = new Font("Segoe UI", 15);
                Graph.Titles.Add(t);
            }
            axisXData.Clear();
            axisBuyData.Clear();
            axisSellData.Clear();
        }
コード例 #16
0
        public SpotTileViewModel(ICurrencyPair currencyPair,
            SpotTileSubscriptionMode spotTileSubscriptionMode,
            Func<ICurrencyPair, SpotTileSubscriptionMode, ISpotTileViewModel, ISpotTilePricingViewModel> pricingFactory,
            Func<ITrade, ISpotTileViewModel, ISpotTileAffirmationViewModel> affirmationFactory,
            Func<string, ISpotTileViewModel, ISpotTileErrorViewModel> errorFactory,
            Func<ISpotTileConfigViewModel> configFactory)
        {
            _affirmationFactory = affirmationFactory;
            _errorFactory = errorFactory;
            _configFactory = configFactory;

            if (currencyPair != null)
            {
                Pricing = pricingFactory(currencyPair, spotTileSubscriptionMode, this);
                CurrencyPair = currencyPair.Symbol;
            }
        }
コード例 #17
0
        public SpotTileViewModel(ICurrencyPair currencyPair,
                                 SpotTileSubscriptionMode spotTileSubscriptionMode,
                                 Func <ICurrencyPair, SpotTileSubscriptionMode, ISpotTileViewModel, ISpotTilePricingViewModel> pricingFactory,
                                 Func <ITrade, ISpotTileViewModel, ISpotTileAffirmationViewModel> affirmationFactory,
                                 Func <string, ISpotTileViewModel, ISpotTileErrorViewModel> errorFactory,
                                 Func <ISpotTileConfigViewModel> configFactory)
        {
            _affirmationFactory = affirmationFactory;
            _errorFactory       = errorFactory;
            _configFactory      = configFactory;

            if (currencyPair != null)
            {
                Pricing      = pricingFactory(currencyPair, spotTileSubscriptionMode, this);
                CurrencyPair = currencyPair.Symbol;
            }
        }
コード例 #18
0
        public override void Awake(NSObject context)
        {
            base.Awake(context);

            _pair = PairFromContext(context);

            if (_pair == null)
            {
                return;
            }

            if (Pairs.NotificationCurrencyPair != null && Pairs.NotificationCurrencyPair.Matches(_pair))
            {
                BecomeCurrentPage();
                Pairs.NotificationCurrencyPair = null;
            }

            SetTitle($"{_pair.BaseCurrency} / {_pair.CounterCurrency}");
        }
コード例 #19
0
        public override void Awake(NSObject context)
        {
            base.Awake(context);

            _pair = PairFromContext(context);

            if (_pair == null)
            {
                return;
            }

            if (Pairs.NotificationCurrencyPair != null && Pairs.NotificationCurrencyPair.Matches(_pair))
            {
                BecomeCurrentPage();
                Pairs.NotificationCurrencyPair = null;
            }

            SetTitle($"{_pair.BaseCurrency} / {_pair.CounterCurrency}");
        }
コード例 #20
0
ファイル: PriceRepository.cs プロジェクト: KqSMea8/gueslang
 public IObservable <IPrice> GetPriceStream(ICurrencyPair currencyPair)
 {
     return(Observable.Defer(() => _pricingServiceClient.GetSpotStream(currencyPair.Symbol))
            .Select(p => _priceFactory.Create(p, currencyPair))
            .Catch <IPrice, Exception>(ex =>
     {
         _log.Error("Error thrown in stream " + currencyPair.Symbol, ex);
         // if the stream errors (server disconnected), we push a stale price
         return Observable
         .Return <IPrice>(new StalePrice(currencyPair))
         // terminate the observable in 3sec so the repeat does not kick-off immediatly
         .Concat(Observable.Timer(TimeSpan.FromSeconds(3)).IgnoreElements().Select(_ => new StalePrice(currencyPair)));
     })
            .Repeat()                                            // and resubscribe
            .DetectStale(TimeSpan.FromSeconds(4), Scheduler.Default)
            .Select(s => s.IsStale ? new StalePrice(currencyPair) : s.Update)
            .Publish()
            .RefCount());
 }
コード例 #21
0
 public IObservable<IPrice> GetPriceStream(ICurrencyPair currencyPair)
 {
     return Observable.Defer(() => _pricingServiceClient.GetSpotStream(currencyPair.Symbol))
         .Select(p => _priceFactory.Create(p, currencyPair))
         .Catch<IPrice, Exception>(ex =>
         {
             _log.Error("Error thrown in stream " + currencyPair.Symbol, ex);
             // if the stream errors (server disconnected), we push a stale price 
             return Observable
                     .Return<IPrice>(new StalePrice(currencyPair))
                     // terminate the observable in 3sec so the repeat does not kick-off immediatly
                     .Concat(Observable.Timer(TimeSpan.FromSeconds(3)).IgnoreElements().Select(_ => new StalePrice(currencyPair)));
         }) 
         .Repeat()                                               // and resubscribe
         .DetectStale(TimeSpan.FromSeconds(4),  Scheduler.Default)
         .Select(s => s.IsStale ? new StalePrice(currencyPair) : s.Update)
         .Publish()
         .RefCount();
 }
コード例 #22
0
        public PriceTileModel(ICurrencyPair currencyPair, IPriceLatencyRecorder priceLatencyRecorder, IConcurrencyService concurrencyService)
        {
            this.priceLatencyRecorder = priceLatencyRecorder;
            this._currencyPair        = currencyPair;
            this._concurrencyService  = concurrencyService;

            // Default ui content.

            this.Symbol             = _currencyPair.BaseCurrency + " / " + _currencyPair.CounterCurrency;
            this.Status             = PriceTileStatus.Streaming;
            this.RightSideBigNumber = this.LeftSideBigNumber = "--";
            this.NotionalCcy        = this.Base;

            // Make default National something a bit random / more interesting. Improved usability.

            var random = new System.Random();

            this.Notional = 100000 + 50000 * random.Next(19);


            _currencyPair.PriceStream
            .ObserveOn(_concurrencyService.Dispatcher)
            .Subscribe(price => OnPrice(price));
        }
コード例 #23
0
 public static bool IsUSDBase(this ICurrencyPair pair) => pair.BaseCurrency == CurrencyType.UsDollar;
コード例 #24
0
        public IFutureContract[] GetContinuousFutureContracts(ICurrencyPair currencyPair)
        {
            var futureMasters = GetCurrencyFuturesCorrelations(currencyPair).FutureMastersCorrelations.Select(c => c.FutureMaster);

            return(futureMasters.Select(fm => InstrumentProvider.GetContinuousFutureContract(fm)).ToArray());
        }
コード例 #25
0
 public CurrencyPairUpdate(UpdateType updateType, ICurrencyPair currencyPair)
 {
     UpdateType   = updateType;
     CurrencyPair = currencyPair;
 }
コード例 #26
0
 public CurrencyPairUpdate(UpdateType updateType, ICurrencyPair currencyPair)
 {
     UpdateType = updateType;
     CurrencyPair = currencyPair;
 }
コード例 #27
0
        public static NSString ToNSString(this ICurrencyPair currencyPair)
        {
            var json = JsonConvert.SerializeObject(currencyPair);

            return(new NSString(json));
        }
コード例 #28
0
ファイル: StalePrice.cs プロジェクト: 925coder/ReactiveTrader
 public StalePrice(ICurrencyPair currencyPair)
 {
     CurrencyPair = currencyPair;
 }
コード例 #29
0
 public static bool IsUSDQuote(this ICurrencyPair pair) => pair.QuoteCurrency == CurrencyType.UsDollar;
コード例 #30
0
 public static bool IsUSDCrossFor(this ICurrencyPair pair, CurrencyType currency) => (pair.IsUSDBase() && pair.QuoteCurrency == currency) || (pair.IsUSDQuote() && pair.BaseCurrency == currency);
コード例 #31
0
 public StalePrice(ICurrencyPair currencyPair)
 {
     CurrencyPair = currencyPair;
 }
コード例 #32
0
 static LimitedNotificationTrader GetTrader(ICurrencyPair currencyPair, IObservable<PriceDto> priceStream)
 {
     var trader = new LimitedNotificationTrader();
     trader.Initialize(priceStream, currencyPair);
     return trader;
 }