using Castle.Core.Logging; using KLHZ.Trader.Core.Common; using KLHZ.Trader.Core.Common.Messaging.Services; using KLHZ.Trader.Core.DataLayer; using KLHZ.Trader.Core.Exchange.Models.AssetsAccounting; using KLHZ.Trader.Core.Exchange.Models.Configs; using KLHZ.Trader.Core.Math.Common; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Logging; using Microsoft.Extensions.Options; using NSubstitute; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace KLHZ.Trader.Core.Tests { public class TraderTests { [Test] public void IsBuyAllowedTest1() { var account = new ManagedAccount("111"); account.Total = 10000; account.Balance = 9000; account.Assets["123"] = new Asset() { AccountId = account.AccountId, Figi = "123", Ticker = "123", Type = AssetType.Futures, }; Assert.IsTrue(KLHZ.Trader.Core.Exchange.Services.Trader.IsBuyAllowed(account, 3000, 1, 0.5m, 0.3m)); } [Test] public void IsBuyAllowedTest2() { var account = new ManagedAccount("111"); account.Total = 10000; account.Balance = 5000; account.Assets["123"] = new Asset() { AccountId = account.AccountId, Figi = "123", Ticker = "123", Type = AssetType.Futures, }; Assert.IsFalse(KLHZ.Trader.Core.Exchange.Services.Trader.IsBuyAllowed(account, 3000, 1, 0.5m, 0.3m)); } [Test] public void IsBuyAllowedTest3() { var account = new ManagedAccount("111"); account.Total = 10000; account.Balance = 5000; account.Assets["123"] = new Asset() { AccountId = account.AccountId, Figi = "123", Ticker = "123", Type = AssetType.Futures, }; Assert.IsFalse(KLHZ.Trader.Core.Exchange.Services.Trader.IsBuyAllowed(account, 1500, 2, 0.5m, 0.3m)); } [Test] public void IsBuyAllowedTest4() { var account = new ManagedAccount("111"); account.Total = 10000; account.Balance = 3000; account.Assets["123"] = new Asset() { AccountId = account.AccountId, Figi = "123", Ticker = "123", Type = AssetType.Futures, }; Assert.IsFalse(KLHZ.Trader.Core.Exchange.Services.Trader.IsBuyAllowed(account, 1500, 1, 0.5m, 0.3m)); } [Test] public void IsBuyAllowedTest5() { var account = new ManagedAccount("111"); account.Total = 10000; account.Balance = 5000; account.Assets["123"] = new Asset() { AccountId = account.AccountId, Figi = "123", Ticker = "123", Type = AssetType.Common, }; Assert.IsTrue(KLHZ.Trader.Core.Exchange.Services.Trader.IsBuyAllowed(account, 3000, 1, 0.5m, 0.1m)); } } }