Esempio n. 1
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);
        }
Esempio n. 2
0
        public void Is_Fpl_Buy_Cross_Correct()
        {
            const string instrument = "BTCCHF";

            _bestPriceConsumer.SendEvent(this, new BestPriceChangeEventArgs(new InstrumentBidAskPair {
                Instrument = "USDCHF", Ask = 1.072030M, Bid = 1.071940M
            }));
            _bestPriceConsumer.SendEvent(this, new BestPriceChangeEventArgs(new InstrumentBidAskPair {
                Instrument = "BTCUSD", Ask = 1001M, Bid = 1000M
            }));
            _bestPriceConsumer.SendEvent(this, new BestPriceChangeEventArgs(new InstrumentBidAskPair {
                Instrument = "BTCCHF", Ask = 901M, Bid = 900M
            }));
            _fxRateCacheService.SetQuote(new InstrumentBidAskPair {
                Instrument = "USDCHF", Ask = 1.072030M, Bid = 1.071940M
            });
            _fxRateCacheService.SetQuote(new InstrumentBidAskPair {
                Instrument = "BTCUSD", Ask = 1001M, Bid = 1000M
            });
            _fxRateCacheService.SetQuote(new InstrumentBidAskPair {
                Instrument = "BTCCHF", Ask = 901M, Bid = 900M
            });

            var position = TestObjectsFactory.CreateOpenedPosition(instrument, Accounts[0],
                                                                   MarginTradingTestsUtils.TradingConditionId, 1000, 935.461M, 0.932888034778M);

            position.UpdateClosePrice(935.61M);

            Assert.AreEqual(139m, Math.Round(position.GetFpl(), 3));
        }