Example #1
0
        private decimal?GetLocalLastPriorPositionPrice(Instrument inst, out decimal fxRate, out DateTime date)
        {
            var pos = Context.PriorPositions.Where(x => x.InstrumentID == inst.ID).OrderByDescending(x => x.Date).FirstOrDefault();

            if (pos == null)
            {
                _logger.Log(LogLevel.Error, "Could not find any local data on instrument " + inst.ToString());
                fxRate = 1;
                date   = DateTime.Now;
                return(null);
            }

            fxRate = pos.FXRateToBase;
            date   = pos.Date;

            return(pos.Price);
        }
Example #2
0
        private decimal? GetLocalLastPriorPositionPrice(Instrument inst, out decimal fxRate, out DateTime date)
        {
            var pos = Context.PriorPositions.Where(x => x.InstrumentID == inst.ID).OrderByDescending(x => x.Date).FirstOrDefault();
            if (pos == null)
            {
                _logger.Log(LogLevel.Error, "Could not find any local data on instrument " + inst.ToString());
                fxRate = 1;
                date = DateTime.Now;
                return null;
            }

            fxRate = pos.FXRateToBase;
            date = pos.Date;

            return pos.Price;
        }
Example #3
0
        private decimal?GetLocalLastFxRatePrice(Instrument instrument, out decimal fxRate, out DateTime date)
        {
            if (instrument.AssetCategory != AssetClass.Cash)
            {
                throw new Exception("Wrong asset class.");
            }
            fxRate = 1;

            string[] splitSymbol    = instrument.Symbol.Split(".".ToCharArray());
            string   fxCurrencyName = splitSymbol[0] == "USD" ? splitSymbol[1] : splitSymbol[0];

            var currency = Context.Currencies.FirstOrDefault(x => x.Name == fxCurrencyName);

            if (currency == null)
            {
                throw new Exception(string.Format("Currency {0} not found.", fxCurrencyName));
            }

            //Some currencies are in the format X.USD, others in format USD.X
            //The latter need to be inverted because all fx rates are given in X.USD
            bool invert = splitSymbol[0] == "USD";

            var price =
                Context
                .FXRates
                .Where(x => x.FromCurrencyID == currency.ID)
                .OrderByDescending(x => x.Date)
                .FirstOrDefault();

            if (price == null)
            {
                _logger.Log(LogLevel.Error, "Could not find any local data on instrument " + instrument.ToString());
                date = DateTime.Now;
                return(null);
            }

            date = price.Date;
            return(invert ? 1m / price.Rate : price.Rate);
        }
Example #4
0
        private decimal? GetLocalLastFxRatePrice(Instrument instrument, out decimal fxRate, out DateTime date)
        {
            if (instrument.AssetCategory != AssetClass.Cash) throw new Exception("Wrong asset class.");
            fxRate = 1;

            string[] splitSymbol = instrument.Symbol.Split(".".ToCharArray());
            string fxCurrencyName = splitSymbol[0] == "USD" ? splitSymbol[1] : splitSymbol[0];

            var currency = Context.Currencies.FirstOrDefault(x => x.Name == fxCurrencyName);
            if (currency == null) throw new Exception(string.Format("Currency {0} not found.", fxCurrencyName));

            //Some currencies are in the format X.USD, others in format USD.X
            //The latter need to be inverted because all fx rates are given in X.USD
            bool invert = splitSymbol[0] == "USD";

            var price =
                Context
                .FXRates
                .Where(x => x.FromCurrencyID == currency.ID)
                .OrderByDescending(x => x.Date)
                .FirstOrDefault();

            if (price == null)
            {
                _logger.Log(LogLevel.Error, "Could not find any local data on instrument " + instrument.ToString());
                date = DateTime.Now;
                return null;
            }

            date = price.Date;
            return invert ? 1m / price.Rate : price.Rate;
        }