Esempio n. 1
0
    // Use this for initialization
    void Start()
    {
        if (textDisplayUI == null)
        {
            textDisplayUI = gameObject.GetComponent <Text>();
            if (textDisplayUI == null)
            {
                Debug.LogWarning("DisplayPrice requires a Text script be on the same gameobject, or that you provice a link to a Text object. Disabling.");
            }
        }

        if (priceObject != null)
        {
            _po = priceObject.GetComponent <IPrice>();
        }
        else
        {
            _po = gameObject.GetComponentInChildren <IPrice>();

            if (_po == null)
            {
                _po = gameObject.GetComponentInParent <IPrice>();
            }
        }//else
        if (_po == null)
        {
            Debug.LogWarning("DisplayPrice requires a script that implements IPrice be on the same gameobject, or that you provide a link to an IPrice-implmenting object. Disabling.");
        }

        enabled = (textDisplayUI != null && _po != null);
    }
Esempio n. 2
0
 public static FormattedPrice ToAskPrice(this IPrice price)
 {
     return(PriceFormatter.GetFormattedPrice(
                price.Ask.Rate,
                price.CurrencyPair.RatePrecision,
                price.CurrencyPair.PipsPosition));
 }
        void SetupStreams(LimitedNotificationTrader trader)
        {
            trader.PriceStream
            .Where(price => !price.IsStale)
            .Subscribe(price =>
            {
                _price = price;
                _sellPriceLabel.SetText(price.ToBidPrice().ToAttributedNotificationString());
                _buyPriceLabel.SetText(price.ToAskPrice().ToAttributedNotificationString());
            })
            .Add(_compositeDisposable);

            trader.PriceStream
            .Where(price => price.IsStale)
            .Subscribe(price =>
            {
                _sellPriceLabel.SetText("-");
                _buyPriceLabel.SetText("-");
                _priceLabel.SetText("");
            })
            .Add(_compositeDisposable);

            trader.PriceStream
            .Where(price => !price.IsStale)
            .ToPriceMovementStream()
            .Subscribe(priceMovement =>
            {
                _arrowLabel.SetText(priceMovement.ToAttributedArrow(_price));
                _priceLabel.SetText(_price.Spread.ToString("0.0"));
                SetPricesHidden(false);
            })
            .Add(_compositeDisposable);
        }
Esempio n. 4
0
        /// <summary>Constructor</summary>
        /// <param name="baseVal">Value exclusive or inclusive VAT</param>
        /// <param name="vatRate">VAT rate (in %)</param>
        /// <param name="currencyUnit">Price currency</param>
        /// <param name="base">Specification of 1st parameter: exclusive/inclusive VAT</param>
        /// <exception cref = "PriceException">Thrown when VAT rate is negative</exception>
        public Price(IPrice price)
        {
            Create(price.ExclVAT, price.VATrate, price.CurrencyUnit, PriceBase.Excl);

            Accounting  = price.Accounting?.Clone();
            Description = price.Description;
            Stamp       = price.Stamp;
        }
Esempio n. 5
0
 public App(IPrice <ForeignCurrencyPrice> priceProvider,
            IRepository <ForeignCurrencyPrice> repository,
            IEventBus eventBus, ILogger <App> logger)
 {
     _pgpPriceProvider = priceProvider;
     _repository       = repository;
     _eventBus         = eventBus;
     _logger           = logger;
 }
Esempio n. 6
0
        public void SetRetailPrice(double price)
        {
            if (price <= 0)
            {
                throw new ArgumentException("Parameter cannot be less than or equal to zero", nameof(price));
            }

            this.retailPricing = new RetailPrice(price);
        }
Esempio n. 7
0
        private void AddHistoricalPrice(IPrice price)
        {
            if (_historicalMid.Count > HistoricalPriceCount)
            {
                _historicalMid.RemoveAt(0);
            }

            _historicalMid.Add(price.Mid);
        }
    //TODO: may be "GetDefaultPrice" is a better name for the method
    public static IEnumerable <Price> GetPrice(this IPrice price)
    {
        if (null == price)
        {
            throw new ArgumentNullException("price");
        }

        return(price.GetPrice((DateTime?)null));
    }
Esempio n. 9
0
        public Movie(string title, IPrice price)
        {
            Price = price;
            if (string.IsNullOrEmpty(title))
            {
                throw new ArgumentNullException("title");
            }

            this.title = title;
        }
Esempio n. 10
0
File: Movie.cs Progetto: Sivsu/Abcam
        public Movie(string title, IPrice pricingStrategy)
        {
            if (string.IsNullOrEmpty(title))
            {
                throw new ArgumentNullException("title");
            }

            this.title = title;
            this.pricingStrategy = pricingStrategy;
        }
 public void OnRendered(IPrice price)
 {
     var priceLatency = price as IPriceLatency;
     if (priceLatency != null)
     {
         priceLatency.DisplayedOnUi();
         _uiLatency.AddObservation((long)priceLatency.UiProcessingTimeMs);
         _combinedLatency.AddObservation((long)priceLatency.TotalLatencyMs);
     }
 }
Esempio n. 12
0
        public Movie(string title, IPrice price)
        {
            Price = price;
            if (string.IsNullOrEmpty(title))
            {
                throw new ArgumentNullException("title");
            }

            this.title = title;
        }
Esempio n. 13
0
        //Това е абстрактния начин да запишем закоментираните методи дилу (с един метод вършим работата на 3-те метода долу!
        public void BuyProduct(IPrice product, User user)//така подаден обекта, е скопен само до пропъртито Price, защото другите не ни интересуват!
        {
            decimal price = product.Price;

            if (user.Money < price)
            {
                throw new ArgumentException("Nqma kesh");
            }
            user.Money -= price;
            Console.WriteLine($"Bought: " + product + $"for only : {price}");
        }
Esempio n. 14
0
        public void OnRendered(IPrice price)
        {
            var priceLatency = price as IPriceLatency;

            if (priceLatency != null)
            {
                priceLatency.DisplayedOnUi();
                _uiLatency.AddObservation((long)priceLatency.UiProcessingTimeMs);
                _combinedLatency.AddObservation((long)priceLatency.TotalLatencyMs);
            }
        }
Esempio n. 15
0
 public HomeController(IUserStore iuserstore, IBady ibady, ILog ilog, ISetting isetting, IMoney imoney, IUser iuser, IPrice ipirce, IHelp ihelp)
 {
     this.iuserstore = iuserstore;
     this.ibady      = ibady;
     this.ilog       = ilog;
     this.isetting   = isetting;
     this.imoney     = imoney;
     this.iuser      = iuser;
     this.iprice     = ipirce;
     this.ihelp      = ihelp;
 }
Esempio n. 16
0
        public static PriceModel MapPrice(IPrice price)
        {
            if (price == null)
            {
                return(null);
            }

            return(new PriceModel
            {
                Amount = price.Amount
            });
        }
Esempio n. 17
0
 public AdminController(IUser iuser, ISetting isetting, ILog ilog, IPrice iprice, INotice inotice, IRequestMoney irequestmoney, IMoney imoney, IHelp ihelp, IUserAccount iuseraccount)
 {
     this.iuser         = iuser;
     this.isetting      = isetting;
     this.ilog          = ilog;
     this.iprice        = iprice;
     this.inotice       = inotice;
     this.irequestmoney = irequestmoney;
     this.imoney        = imoney;
     this.ihelp         = ihelp;
     this.iuseraccount  = iuseraccount;
 }
 public void OnReceived(IPrice price)
 {
     var priceLatency = price as IPriceLatency;
     if (priceLatency != null)
     {
         priceLatency.ReceivedInGuiProcess();
         lock (_histogramLock)
         {
             _serverLatency.AddObservation((long) priceLatency.ServerToClientMs);
         }
     }
 }
        //public FormulaLogic Logic { get;set; }

        //[Query]
        //public int Stamina => State.Values["stamina"];

        //[Query]
        //public IReadOnlyDictionary<int, IScorer> Scorers => Static.Scorers;

        public void Spend(IPrice price, FormulaLogic logic)
        {
            var value    = (int)logic.Calculate(price.Value);
            var scorerId = Static.MoneyTypes[price.MoneyType].ScorerId;

            State.Values.TryGetValue(scorerId, out var count);
            if (count < value)
            {
                throw new Exception($"Недостаточно ресурсов type = {price.MoneyType} для покупки ({count} < {value})");
            }
            State.Values[scorerId] = count - value;
        }
Esempio n. 20
0
        public void OnReceived(IPrice price)
        {
            var priceLatency = price as IPriceLatency;

            if (priceLatency != null)
            {
                priceLatency.ReceivedInGuiProcess();
                lock (_histogramLock)
                {
                    _serverLatency.AddObservation((long)priceLatency.ServerToClientMs);
                }
            }
        }
Esempio n. 21
0
        public static decimal GetUnitPrice(this IStoreOrderDetail item, bool applyMultiplier = true)
        {
            IPrice  p       = ServiceProvider.Current.Store.GetPrice(item.PriceID);
            decimal baseQty = p.BaseQMultiplier;
            decimal result  = p.PackagePrice / baseQty;

            if (applyMultiplier)
            {
                int accountId = item.AccountID;
                result = Prices.ApplyStoreMultiplier(result, accountId);
            }
            return(result);
        }
Esempio n. 22
0
        /// <summary>
        /// Gets the current gold price.
        /// </summary>
        /// <param name="getPrice">if set to <c>true</c> [get price].</param>
        /// <returns>return the price of gold</returns>
        public int GetCurrentGoldPrice(bool getPrice)
        {
            if (getPrice)
            {
                this.price = new GoldPrice();

                ////getting the actual resources
                return(this.price.GetPrice());
            }
            else
            {
                return(0);
            }
        }
Esempio n. 23
0
 public PriceViewModel(IPrice price, IEdition edition)
 {
     AddDate = price.AddDate;
     if (Enum.TryParse(price.Source, out PriceValueSource source))
     {
         Source = source;
     }
     else
     {
         Source = PriceValueSource.Unknown;
     }
     Foil        = price.Foil;
     Value       = price.Value;
     EditionName = edition.Name;
 }
        public static NSAttributedString ToAttributedArrow(this PriceMovement priceMovement, IPrice price)
        {
            if (price == null)
            {
                return new NSAttributedString(string.Empty);
            }

            var movementText = new Dictionary<PriceMovement, NSAttributedString>
            {
                {PriceMovement.Up,   new NSAttributedString("▲", _arrowFont, UIColor.Green) },
                {PriceMovement.Down, new NSAttributedString("▼", _arrowFont, UIColor.Red) },
                {PriceMovement.None, new NSAttributedString("▼", _arrowFont, UIColor.Clear) }
            };

            return movementText[priceMovement];
        }
        public override void WillActivate()
        {
            base.WillActivate();

            if (_pair == null)
            {
                return;
            }

            _disposables = new CompositeDisposable();
            var stream = _pair.PriceStream;

            stream.Subscribe(price => _price = price).Add(_disposables);

            stream
            .Where(price => !price.IsStale && !_executing)
            .Select(price => price.ToBidPrice().ToAttributedString())
            .Subscribe(SellPriceLabel.SetText)
            .Add(_disposables);

            stream
            .Where(price => !price.IsStale && !_executing)
            .Select(price => price.ToAskPrice().ToAttributedString())
            .Subscribe(BuyPriceLabel.SetText)
            .Add(_disposables);

            stream
            .Where(price => !price.IsStale)
            .ToPriceMovementStream()
            .DistinctUntilChanged()
            .Select(movement => movement.ToAttributedString(_price))
            .Where(_ => !_executing)
            .Subscribe(PriceLabel.SetText)
            .Add(_disposables);

            stream
            .Select(price => price.IsStale)
            .DistinctUntilChanged()
            .Subscribe(isStale =>
            {
                SetStatus(isStale, BuyButton);
                SetStatus(isStale, SellButton);
            })
            .Add(_disposables);
        }
Esempio n. 26
0
        public override void WillActivate()
        {
            base.WillActivate();

            if (_pair == null)
            {
                return;
            }

            _disposables = new CompositeDisposable();
            var stream = _pair.PriceStream;

            stream.Subscribe(price => _price = price).Add(_disposables);

            stream
                .Where(price => !price.IsStale && !_executing)
                .Select(price => price.ToBidPrice().ToAttributedString())
                .Subscribe(SellPriceLabel.SetText)
                .Add(_disposables);

            stream
                .Where(price => !price.IsStale && !_executing)
                .Select(price => price.ToAskPrice().ToAttributedString())
                .Subscribe(BuyPriceLabel.SetText)
                .Add(_disposables);

            stream
                .Where(price => !price.IsStale)
                .ToPriceMovementStream()
                .DistinctUntilChanged()                    
                .Select(movement => movement.ToAttributedString(_price))
                .Where(_ => !_executing)
                .Subscribe(PriceLabel.SetText)
                .Add(_disposables);

            stream
                .Select(price => price.IsStale)
                .DistinctUntilChanged()
                .Subscribe(isStale => 
                {
                    SetStatus(isStale, BuyButton);
                    SetStatus(isStale, SellButton);
                })
                .Add(_disposables);
        }
Esempio n. 27
0
        private IPrice GetHistoricalPrice(IEnumerable <IPrice> prices, DateTime date)
        {
            var included = prices.Where(x => x.DateActive <= date.Date).ToList();

            IPrice result = null;

            if (included.Count > 0)
            {
                result = prices.Where(x => x.DateActive == included.Max(b => b.DateActive)).FirstOrDefault();
            }

            if (result == null)
            {
                result = prices.First();
            }

            return(result);
        }
Esempio n. 28
0
        public void update(IPrice update)
        {
            if (this.bid > update.bid)
            {
                state = EPriceState.Decreasing;
            }
            else if (this.bid < update.bid)
            {
                state = EPriceState.Increasing;
            }
            else
            {
                state = EPriceState.Default;
            }

            this.bid  = update.bid;
            this.ask  = update.ask;
            this.time = update.time;
        }
Esempio n. 29
0
        private void OnPrice(IPrice price)
        {
            IsSubscribing = false;
            IsStale       = price.IsStale;

            if (price.IsStale)
            {
                Bid.OnStalePrice();
                Ask.OnStalePrice();
                Spread        = string.Empty;
                _previousRate = null;
                Movement      = PriceMovement.None;
                SpotDate      = "SP";
            }
            else
            {
                if (_previousRate.HasValue)
                {
                    if (price.Mid > _previousRate.Value)
                    {
                        Movement = PriceMovement.Up;
                    }
                    else if (price.Mid < _previousRate.Value)
                    {
                        Movement = PriceMovement.Down;
                    }
                    else
                    {
                        Movement = PriceMovement.None;
                    }
                }
                Mid           = price.Mid;
                _previousRate = price.Mid;
                Bid.OnPrice(price.Bid);
                Ask.OnPrice(price.Ask);
                Spread   = PriceFormatter.GetFormattedSpread(price.Spread, _currencyPair.RatePrecision, _currencyPair.PipsPosition);
                SpotDate = "SP. " + price.ValueDate.ToString("dd MMM");
                _priceLatencyRecorder.OnRendered(price);

                AddHistoricalPrice(price);
            }
            _currentPrice = price;
        }
        private void SubscribeForPricesConstantRate()
        {
            var ps = _currencyPair.PriceStream
                     .SubscribeOn(_concurrencyService.TaskPool)
                     .Subscribe(price =>
            {
                _latestPrice = price;
            }, OnError);

            var el = _concurrencyService.DispatcherPeriodic.Schedule(() =>
            {
                if (_currentPrice != _latestPrice && _latestPrice != null)
                {
                    OnPrice(_latestPrice);
                }
            });

            _priceSubscription.Disposable = new CompositeDisposable(ps, el);
        }
        public static NSAttributedString ToAttributedString(this PriceMovement priceMovement, IPrice price)
        {
            if (price == null)
            {
                return new NSAttributedString(string.Empty);
            }

            var movementText = new Dictionary<PriceMovement, NSAttributedString>
            {
                {PriceMovement.Up,   new NSAttributedString("▲", _arrowFont, UIColor.Green) },
                {PriceMovement.Down, new NSAttributedString("▼", _arrowFont, UIColor.Red) },
                {PriceMovement.None, new NSAttributedString("▼", _arrowFont, UIColor.Clear) }
            };


            var spread = new NSAttributedString(price.Spread.ToString("0.0") + "   ");
            var text = new NSMutableAttributedString(spread);
            text.Append(movementText[priceMovement]);
            return text;
        }
Esempio n. 32
0
        public void SetWholesalePrice(int quantity, double price)
        {
            if (price <= 0)
            {
                throw new ArgumentException("Parameter cannot be less than or equal to zero", nameof(price));
            }

            if (quantity <= 0)
            {
                throw new ArgumentException("Parameter cannot be less than or equal to zero", nameof(quantity));
            }

            if (quantity == 1)
            {
                SetRetailPrice(price);
                return;
            }

            this.wholesalePrice = new WholesalePrice(quantity, price);
        }
Esempio n. 33
0
        public void SetPriceCode(int priceCode)
        {
            switch (priceCode)
            {
            case REGULAR:
                _price = new RegularPrice();
                break;

            case CHILDRENS:
                _price = new ChildrenPrice();
                break;

            case NEW_RELEASE:
                _price = new NewReleasePrice();
                break;

            default:
                throw new Exception();
            }
        }
        public static void ConvertD(IPrice price, ICurrency sourceCurrency, Currency targetCurrency)
        {
            try
            {
                switch (sourceCurrency.Currency)
                {
                case Currency.UAH:
                    switch (targetCurrency)
                    {
                    case Currency.UAH:
                        price.Price = price.Price;
                        break;

                    case Currency.USD:
                    case Currency.EUR:
                        var a        = _courceCurrency[targetCurrency];
                        var newPrice = Math.Round(price.Price / a, 2, MidpointRounding.AwayFromZero);
                        price.Price             = newPrice;
                        sourceCurrency.Currency = targetCurrency;
                        break;

                    default:
                        throw new ArgumentOutOfRangeException(nameof(targetCurrency), targetCurrency, null);
                    }
                    break;

                case Currency.USD:
                    break;

                case Currency.EUR:
                    break;

                default:
                    throw new ArgumentOutOfRangeException(nameof(sourceCurrency), sourceCurrency, null);
                }
            }
            catch (Exception)
            {
                throw;
            }
        }
        public static IPrice[] Decomposite(IPrice price, List <IPrice> prices = null)
        {
            if (prices == null)
            {
                prices = new List <IPrice>();
            }

            var cp = price as CompositePrice;

            if (cp != null)
            {
                foreach (var pr in cp.prices)
                {
                    Decomposite(pr.Value, prices);
                }
            }
            else
            {
                prices.Add(price);
            }

            return(prices.ToArray());
        }
        void ExecuteTrade(IPrice price, IExecutablePrice executablePrice, WKInterfaceLabel label)
        {
            if (price == null)
            {
                throw new ArgumentNullException("price");
            }

            if (price == null || price.IsStale || _executing)
            {
                return;
            }

            _executing = true;
            label.SetText("Executing...");

            executablePrice.ExecuteRequest(100930, _pair.BaseCurrency)
            .Subscribe(result =>
            {
                _executing = false;
                ShowConfirmation(result.Update);
                label.SetText("");
            })
            .Add(_disposables);
        }
Esempio n. 37
0
 public CurrencyPriceDecorator(IPrice price, decimal exchangeRate)
 {
     _basePrice    = price;
     _exchangeRate = exchangeRate;
 }
 public TradeDiscountPriceDecorator(IPrice basePrice)
 {
     _basePrice = basePrice;
 }
Esempio n. 39
0
 public Movie(IPrice price)
 {
     PriceCode = price;
 }
 public CurrencyPriceDecorator(IPrice basePrice, decimal exchangeRate)
 {
     _basePrice = basePrice;
     _exchangeRate = exchangeRate;
 }
        private void AddHistoricalPrice(IPrice price)
        {
            if (_historicalMid.Count > HistoricalPriceCount)
            {
                _historicalMid.RemoveAt(0);
            }

            _historicalMid.Add(price.Mid);
        }
        void SetupStreams(LimitedNotificationTrader trader)
        {
            trader.PriceStream
                .Where(price => !price.IsStale)
                .Subscribe(price =>
                    {
                        _price = price;
                        _sellPriceLabel.SetText(price.ToBidPrice().ToAttributedNotificationString());
                        _buyPriceLabel.SetText(price.ToAskPrice().ToAttributedNotificationString());
                    })
                .Add(_compositeDisposable);

            trader.PriceStream
                .Where(price => price.IsStale)
                .Subscribe(price =>
                    {
                        _sellPriceLabel.SetText("-");
                        _buyPriceLabel.SetText("-");
                        _priceLabel.SetText("");
                    })
                .Add(_compositeDisposable);

            trader.PriceStream
                .Where(price => !price.IsStale)
                .ToPriceMovementStream()
                .Subscribe(priceMovement => 
                    {
                        _arrowLabel.SetText(priceMovement.ToAttributedArrow(_price));
                        _priceLabel.SetText(_price.Spread.ToString("0.0"));
                        SetPricesHidden(false);
                    })
                .Add(_compositeDisposable);
        }
        private void SubscribeForPricesConstantRate()
        {
            var ps = _currencyPair.PriceStream
                                  .SubscribeOn(_concurrencyService.TaskPool)
                                  .Subscribe(price =>
                                      {
                                          _latestPrice = price;
                                      }, OnError);

            var el = _constantRatePump.Tick.Subscribe(_ =>
                {
                    if (_currentPrice != _latestPrice && _latestPrice != null)
                    {
                        OnPrice(_latestPrice);
                    }
                });

            _priceSubscription.Disposable = new CompositeDisposable(ps, el);
        }
Esempio n. 44
0
        void ExecuteTrade(IPrice price, IExecutablePrice executablePrice, WKInterfaceLabel label)
        {
            if (price == null)
            {
                throw new ArgumentNullException("price");
            }

            if (price == null || price.IsStale || _executing)
            {
                return;
            }

            _executing = true;
            label.SetText("Executing...");

            executablePrice.ExecuteRequest(100930, _pair.BaseCurrency)
                .Subscribe(result => 
                    {
                        _executing = false;
                        ShowConfirmation(result.Update);
                        label.SetText("");
                    })
                .Add(_disposables);
        }
Esempio n. 45
0
 public void UpdatePrice(IPrice spread)
 {
     var price=  ((BondPrice)spread).Price;
     _cleanPrice.CleanPrice = price;
 }
        private void SubscribeForPricesConstantRate()
        {
            var ps = _currencyPair.PriceStream
                                  .SubscribeOn(_concurrencyService.ThreadPool)
                                  .Subscribe(price =>
                                      {
                                          _latestPrice = price;
                                      }, OnError);

            var el = _concurrencyService.DispatcherPeriodic.Schedule(() =>
                {
                    if (_currentPrice != _latestPrice && _latestPrice != null)
                    {
                        OnPrice(_latestPrice);
                    }
                });

            _priceSubscription.Disposable = new CompositeDisposable(ps, el);
        }
        private void OnPrice(IPrice price)
        {
            IsSubscribing = false;
            IsStale = price.IsStale;

            if (price.IsStale)
            {
                Bid.OnStalePrice();
                Ask.OnStalePrice();
                Spread = string.Empty;
                _previousRate = null;
                Movement = PriceMovement.None;
                SpotDate = "SP";
            }
            else
            {
                if (_previousRate.HasValue)
                {
                    if (price.Mid > _previousRate.Value)
                        Movement = PriceMovement.Up;
                    else if (price.Mid < _previousRate.Value)
                        Movement = PriceMovement.Down;
                    else
                        Movement = PriceMovement.None;
                }
                _previousRate = price.Mid;

                Bid.OnPrice(price.Bid);
                Ask.OnPrice(price.Ask);
                Spread = PriceFormatter.GetFormattedSpread(price.Spread, _currencyPair.RatePrecision, _currencyPair.PipsPosition);
                SpotDate = "SP. " + price.ValueDate.ToString("dd MMM");

                _priceLatencyRecorder.OnRendered(price);

            }
            _currentPrice = price;
        }
Esempio n. 48
0
		public FlatPrice(IPrice price)
		{
			Value = price.Value;
			ValueInCents = price.ValueInCents;
			ToCurrencyString = price.ToCurrencyString();
		}