Skip to content

Commit dbae0c1

Browse files
committed
Solve review comments
1 parent f00e22a commit dbae0c1

1 file changed

Lines changed: 16 additions & 4 deletions

File tree

Tests/Common/Securities/CashBuyingPowerModelTests.cs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,7 @@ public void LimitBuyOrderChecksOpenOrders()
228228
[Test]
229229
public void LimitSellOrderChecksOpenOrders()
230230
{
231+
_algorithm.SetBrokerageModel(BrokerageName.Kraken, AccountType.Cash);
231232
_portfolio.SetCash(5000);
232233
_portfolio.CashBook["BTC"].SetAmount(1m);
233234
_portfolio.CashBook["ETH"].SetAmount(3m);
@@ -252,12 +253,15 @@ public void LimitSellOrderChecksOpenOrders()
252253
// ETHBTC buy limit order decreases available BTC (0.9 - 0.1 = 0.8 BTC)
253254
SubmitLimitOrder(_ethbtc.Symbol, 1m, 0.1m);
254255

255-
// 0.8 BTC available, can sell 0.8 BTC at any price
256-
var order = new LimitOrder(_btcusd.Symbol, -0.8m, 10000m, DateTime.UtcNow);
256+
// BTCUSD sell stop order decreases available BTC (0.8 - 0.1 = 0.7 BTC)
257+
SubmitStopMarketOrder(_btcusd.Symbol, -0.1m, 5000m);
258+
259+
// 0.7 BTC available, can sell 0.7 BTC at any price
260+
var order = new LimitOrder(_btcusd.Symbol, -0.7m, 10000m, DateTime.UtcNow);
257261
Assert.IsTrue(_buyingPowerModel.HasSufficientBuyingPowerForOrder(_portfolio, _btcusd, order).IsSufficient);
258262

259-
// 0.8 BTC available, cannot sell 0.9 BTC at any price
260-
order = new LimitOrder(_btcusd.Symbol, -0.9m, 10000m, DateTime.UtcNow);
263+
// 0.7 BTC available, cannot sell 0.8 BTC at any price
264+
order = new LimitOrder(_btcusd.Symbol, -0.8m, 10000m, DateTime.UtcNow);
261265
Assert.IsFalse(_buyingPowerModel.HasSufficientBuyingPowerForOrder(_portfolio, _btcusd, order).IsSufficient);
262266

263267
// 2 ETH available, can sell 2 ETH at any price
@@ -267,6 +271,14 @@ public void LimitSellOrderChecksOpenOrders()
267271
// 2 ETH available, cannot sell 2.1 ETH at any price
268272
order = new LimitOrder(_ethusd.Symbol, -2.1m, 2000m, DateTime.UtcNow);
269273
Assert.IsFalse(_buyingPowerModel.HasSufficientBuyingPowerForOrder(_portfolio, _ethusd, order).IsSufficient);
274+
275+
// 0.7 BTC available, can sell stop 0.7 BTC at any price
276+
var stopOrder = new StopMarketOrder(_btcusd.Symbol, -0.7m, 5000m, DateTime.UtcNow);
277+
Assert.IsTrue(_buyingPowerModel.HasSufficientBuyingPowerForOrder(_portfolio, _btcusd, stopOrder).IsSufficient);
278+
279+
// 0.7 BTC available, cannot sell stop 0.8 BTC at any price
280+
stopOrder = new StopMarketOrder(_btcusd.Symbol, -0.8m, 5000m, DateTime.UtcNow);
281+
Assert.IsFalse(_buyingPowerModel.HasSufficientBuyingPowerForOrder(_portfolio, _btcusd, stopOrder).IsSufficient);
270282
}
271283

272284
[Test]

0 commit comments

Comments
 (0)