public void MakePreTradeValidation(Order order, bool shouldOpenNewPosition, IMatchingEngineBase matchingEngine) { GetAssetPairIfAvailableForTrading(order.AssetPairId, order.OrderType, shouldOpenNewPosition, true); ValidateTradeLimits(order.AssetPairId, order.TradingConditionId, order.AccountId, order.Volume, shouldOpenNewPosition); if (shouldOpenNewPosition) { _accountUpdateService.CheckIsEnoughBalance(order, matchingEngine); } }
public void Check_IsEnoughBalance() { //account have 1000 var me = new FakeMatchingEngine(10); var order1 = TestObjectsFactory.CreateNewOrder(OrderType.Market, "EURUSD", Accounts[0], MarginTradingTestsUtils.TradingConditionId, 96000); Assert.DoesNotThrow(() => _accountUpdateService.CheckIsEnoughBalance(order1, me, 0)); var order2 = TestObjectsFactory.CreateNewOrder(OrderType.Market, "EURUSD", Accounts[0], MarginTradingTestsUtils.TradingConditionId, 97000); Assert.Throws <ValidateOrderException>(() => _accountUpdateService.CheckIsEnoughBalance(order2, me, 0)); var meWithSpread = new FakeMatchingEngine(10, closePrice: 1); var order3 = TestObjectsFactory.CreateNewOrder(OrderType.Market, "EURUSD", Accounts[0], MarginTradingTestsUtils.TradingConditionId, 96000); Assert.Throws <ValidateOrderException>( () => _accountUpdateService.CheckIsEnoughBalance(order3, meWithSpread, 0)); var meForLimitOk = new FakeMatchingEngine(999); var limitOrderOk = TestObjectsFactory.CreateNewOrder(OrderType.Limit, "EURUSD", Accounts[0], MarginTradingTestsUtils.TradingConditionId, 960, price: 1000); Assert.DoesNotThrow(() => _accountUpdateService.CheckIsEnoughBalance(limitOrderOk, meForLimitOk, 0)); var limitOrderErr = TestObjectsFactory.CreateNewOrder(OrderType.Limit, "EURUSD", Accounts[0], MarginTradingTestsUtils.TradingConditionId, 960, price: 1000); var meWithHighPrice = new FakeMatchingEngine(1000, 10); var ex = Assert.Throws <ValidateOrderException>(() => _accountUpdateService.CheckIsEnoughBalance(limitOrderErr, meWithHighPrice, 0)); Console.WriteLine(ex.Comment); }