Beispiel #1
0
        public PriceCalculatorResponse CalculatePrice(PriceRequest request)
        {
            PriceCalculatorResponse response = null;

            if (request != null)
            {
                AbstractPriceCreateArg arg = new AbstractPriceCreateArg {
                    UserType = (UserTypeEnum)request.UserType, PriceCalculatorService = this
                };
                var priceProduct = _priceFactory.Create(arg);
                response = priceProduct.Product.CalculatePrice(request);
            }
            return(response);
        }
Beispiel #2
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());
 }