Esempio n. 1
0
        public decimal GetQuoteRateForBaseAsset(string accountAssetId, string assetPairId, string legalEntity,
                                                bool useAsk)
        {
            var assetPair = _assetPairsCache.GetAssetPairById(assetPairId);

            // two step transform: base -> quote from QuoteCache, quote -> account from FxCache
            // if accountAssetId == assetPair.BaseAssetId, rate != 1, because trading and fx rates can be different

            var assetPairQuote = _quoteCacheService.GetQuote(assetPairId);
            var tradingRate    = useAsk ? assetPairQuote.Ask : assetPairQuote.Bid;

            if (assetPair.QuoteAssetId == accountAssetId)
            {
                return(tradingRate);
            }

            var fxPair =
                _assetPairsCache.FindAssetPair(assetPair.QuoteAssetId, accountAssetId, legalEntity);
            var fxQuote = _fxRateCacheService.GetQuote(fxPair.Id);

            var rate = fxPair.BaseAssetId == assetPair.QuoteAssetId
                ? fxQuote.Ask * tradingRate
                : 1 / fxQuote.Bid * tradingRate;

            return(rate);
        }
Esempio n. 2
0
        public void Is_GetQuoteRateForQuoteAsset_Correct()
        {
            const string instrument = "USDCHF";

            _fxRateCacheService.SetQuote(new InstrumentBidAskPair {
                Instrument = "USDCHF", Ask = 0.9982M, Bid = 0.9980M
            });

            var quote = _fxRateCacheService.GetQuote(instrument);

            Assert.IsNotNull(quote);
            Assert.AreEqual(0.9980, quote.Bid);
            Assert.AreEqual(0.9982, quote.Ask);

            var quoteRate = _cfdCalculatorService.GetQuoteRateForQuoteAsset(Accounts[0].BaseAssetId, instrument, "LYKKETEST");

            Assert.AreEqual(1.002004008016032064128256513, quoteRate);

            quoteRate = _cfdCalculatorService.GetQuoteRateForQuoteAsset(Accounts[0].BaseAssetId, instrument, "LYKKETEST", false);

            Assert.AreEqual(1.0018032458425165297535564015, quoteRate);
        }