public async Task Is_Swaps_Correct() { _bestPriceConsumer.SendEvent(this, new BestPriceChangeEventArgs(new InstrumentBidAskPair { Instrument = "EURUSD", Bid = 1.02M, Ask = 1.04M })); _accountAssetsRepository.AddOrReplaceAsync(new AccountAssetPair { TradingConditionId = MarginTradingTestsUtils.TradingConditionId, BaseAssetId = "USD", Instrument = "EURUSD", LeverageInit = 100, LeverageMaintenance = 150, SwapLong = 100, SwapShort = 100 }).Wait(); await _accountAssetsManager.UpdateAccountAssetsCache(); var dayOrder = new Order { AccountAssetId = "USD", Instrument = "EURUSD", Volume = 20, OpenDate = new DateTime(2017, 01, 01, 20, 50, 0), CloseDate = new DateTime(2017, 01, 02, 20, 50, 0), MatchedOrders = new MatchedOrderCollection(new List <MatchedOrder> { new MatchedOrder() { Volume = 20 } }), SwapCommission = 100 }; var swapsForDay = _swapService.GetSwaps(dayOrder); var twoDayOrder = new Order { AccountAssetId = "USD", Instrument = "EURUSD", Volume = 20, OpenDate = new DateTime(2017, 01, 01, 20, 50, 0), CloseDate = new DateTime(2017, 01, 03, 20, 50, 0), MatchedOrders = new MatchedOrderCollection(new List <MatchedOrder>() { new MatchedOrder() { Volume = 20 } }), SwapCommission = 100 }; var swapsFor2Days = _swapService.GetSwaps(twoDayOrder); Assert.AreEqual(5.69863014m, swapsForDay); Assert.AreEqual(11.39726027m, swapsFor2Days); }
public async Task Is_Swaps_Correct() { _bestPriceConsumer.SendEvent(this, new BestPriceChangeEventArgs(new InstrumentBidAskPair { Instrument = "EURUSD", Bid = 1.02M, Ask = 1.04M })); var instrumentContract = new TradingInstrumentContract { TradingConditionId = MarginTradingTestsUtils.TradingConditionId, Instrument = "EURUSD", LeverageInit = 100, LeverageMaintenance = 150, SwapLong = 100, SwapShort = 100 }; Mock.Get(_tradingInstruments).Setup(s => s.List(It.IsAny <string>())) .ReturnsAsync(new List <TradingInstrumentContract> { instrumentContract }); await _accountAssetsManager.UpdateTradingInstrumentsCacheAsync(); var dayPosition = new Position(Guid.NewGuid().ToString("N"), 0, "EURUSD", 20, Accounts[0].Id, MarginTradingTestsUtils.TradingConditionId, Accounts[0].BaseAssetId, null, MatchingEngineConstants.DefaultMm, new DateTime(2017, 01, 01, 20, 50, 0), "OpenTrade", OrderType.Market, 20, 1, 1, "USD", 1, new List <RelatedOrderInfo>(), "LYKKETEST", OriginatorType.Investor, "", "EURUSD", FxToAssetPairDirection.Straight, ""); dayPosition.SetCommissionRates(100, 0, 0, 1); dayPosition.StartClosing(new DateTime(2017, 01, 02, 20, 50, 0), PositionCloseReason.Close, OriginatorType.Investor, ""); dayPosition.Close(new DateTime(2017, 01, 02, 20, 50, 0), MatchingEngineConstants.DefaultMm, 2, 1, 1, OriginatorType.Investor, PositionCloseReason.Close, "", "CloseTrade"); var swapsForDay = _swapService.GetSwaps(dayPosition); var twoDayPosition = new Position(Guid.NewGuid().ToString("N"), 0, "EURUSD", 20, Accounts[0].Id, MarginTradingTestsUtils.TradingConditionId, Accounts[0].BaseAssetId, null, MatchingEngineConstants.DefaultMm, new DateTime(2017, 01, 01, 20, 50, 0), "OpenTrade", OrderType.Market, 20, 1, 1, "USD", 1, new List <RelatedOrderInfo>(), "LYKKETEST", OriginatorType.Investor, "", "EURUSD", FxToAssetPairDirection.Straight, ""); twoDayPosition.SetCommissionRates(100, 0, 0, 1); twoDayPosition.StartClosing(new DateTime(2017, 01, 03, 20, 50, 0), PositionCloseReason.Close, OriginatorType.Investor, ""); twoDayPosition.Close(new DateTime(2017, 01, 03, 20, 50, 0), MatchingEngineConstants.DefaultMm, 2, 1, 1, OriginatorType.Investor, PositionCloseReason.Close, "", "CloseTrade"); var swapsFor2Days = _swapService.GetSwaps(twoDayPosition); Assert.AreEqual(5.69863014m, swapsForDay); Assert.AreEqual(11.39726027m, swapsFor2Days); }