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(); }
static LimitedNotificationTrader GetTrader(ICurrencyPair currencyPair, IObservable <PriceDto> priceStream) { var trader = new LimitedNotificationTrader(); trader.Initialize(priceStream, currencyPair); return(trader); }
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}'."); }
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(); }
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); }
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); }
public bool Matches(ICurrencyPair pair) { if (pair == null) { return false; } return (pair.BaseCurrency == _baseCurrency && pair.CounterCurrency == _counterCurrency); }
public bool Matches(ICurrencyPair pair) { if (pair == null) { return(false); } return(pair.BaseCurrency == _baseCurrency && pair.CounterCurrency == _counterCurrency); }
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 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)); } }
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 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(); }
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); }
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); }
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(); }
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; } }
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; } }
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}"); }
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()); }
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(); }
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)); }
public static bool IsUSDBase(this ICurrencyPair pair) => pair.BaseCurrency == CurrencyType.UsDollar;
public IFutureContract[] GetContinuousFutureContracts(ICurrencyPair currencyPair) { var futureMasters = GetCurrencyFuturesCorrelations(currencyPair).FutureMastersCorrelations.Select(c => c.FutureMaster); return(futureMasters.Select(fm => InstrumentProvider.GetContinuousFutureContract(fm)).ToArray()); }
public CurrencyPairUpdate(UpdateType updateType, ICurrencyPair currencyPair) { UpdateType = updateType; CurrencyPair = currencyPair; }
public static NSString ToNSString(this ICurrencyPair currencyPair) { var json = JsonConvert.SerializeObject(currencyPair); return(new NSString(json)); }
public StalePrice(ICurrencyPair currencyPair) { CurrencyPair = currencyPair; }
public static bool IsUSDQuote(this ICurrencyPair pair) => pair.QuoteCurrency == CurrencyType.UsDollar;
public static bool IsUSDCrossFor(this ICurrencyPair pair, CurrencyType currency) => (pair.IsUSDBase() && pair.QuoteCurrency == currency) || (pair.IsUSDQuote() && pair.BaseCurrency == currency);
static LimitedNotificationTrader GetTrader(ICurrencyPair currencyPair, IObservable<PriceDto> priceStream) { var trader = new LimitedNotificationTrader(); trader.Initialize(priceStream, currencyPair); return trader; }