예제 #1
0
        public void Setup()
        {
            // подготовить свежие котировки
            QuoteMaker.FillQuoteStorageWithDefaultValues();

            // соединение и тестовые данные
            TradeSharpConnectionPersistent.RestoreCsvFilesInMoqDbFolder();
            conn = TradeSharpConnectionPersistent.InitializeTradeSharpConnection();
            MakeTestData();

            // словари
            TradeSharpDictionary.Initialize(MoqTradeSharpDictionary.Mock);

            // тестируемый менеджер
            ManagerTrade.MakeTestInstance(
                new Dictionary <string, IDealer>
            {
                { testAccount.AccountGroup,
                  new DemoDealer.DemoDealer(new DealerDescription(), conn.ACCOUNT_GROUP.Select(g => g.Code).ToList()) }
            });
            managerTrade = ManagerTrade.Instance;
            var mockAccountRepository = new Mock <IAccountRepository>();

            mockAccountRepository.Setup(s => s.GetAccount(It.IsAny <int>())).Returns(
                (int id) => LinqToEntity.DecorateAccount(testAccount));
            managerTrade.accountRepository = mockAccountRepository.Object;

            managerTrade.orderRepository = OrderRepository.Instance;
        }
 public void Setup()
 {
     conn = TradeSharpConnectionPersistent.InitializeTradeSharpConnection();
     ManagerTrade.MakeTestInstance();
     SetupFakeStatistics();
     FindSubscriber();
 }
예제 #3
0
 public void InitTest()
 {
     // временно удалить файл начального наполнения (открытые ордера)
     TradeSharpConnectionPersistent.RenameCsvFilesInMoqDbFolder(typeof(POSITION));
     conn = TradeSharpConnectionPersistent.InitializeTradeSharpConnection();
     MakeTestOrders();
 }
예제 #4
0
        public void InitTest()
        {
            // забить котировки
            QuoteMaker.FillQuoteStorageWithDefaultValues();

            // словари
            TradeSharpDictionary.Initialize(MoqTradeSharpDictionary.Mock);

            tradeManager = new TradeManager(
                null,
                null,
                QuoteStorage.Instance, accountId =>
            {
                // ReSharper disable ConvertToLambdaExpression
                return(LinqToEntity.DecorateAccountGroup(conn.ACCOUNT.First(a => a.ID == accountId).ACCOUNT_GROUP));
                // ReSharper restore ConvertToLambdaExpression
            });

            // временно удалить файл начального наполнения (открытые ордера)
            TradeSharpConnectionPersistent.RestoreCsvFilesInMoqDbFolder();
            TradeSharpConnectionPersistent.RenameCsvFilesContainingAccountDataInMoqDbFolder();
            conn = TradeSharpConnectionPersistent.InitializeTradeSharpConnection();

            MakeTestData();
        }
예제 #5
0
 public void Setup()
 {
     TradeSharpDictionary.Initialize(MoqTradeSharpDictionary.Mock);
     conn = TradeSharpConnectionPersistent.InitializeTradeSharpConnection();
     QuoteMaker.FillQuoteStorageWithDefaultValues();
     platformManager = new PlatformManager();
 }
예제 #6
0
        public void TestSetup()
        {
            connectionPersistent = TradeSharpConnectionPersistent.InitializeTradeSharpConnection();
            TradeSharpDictionary.Initialize(MoqTradeSharpDictionary.Mock);
            walletManager = new WalletManager();

            DatabaseContext.InitializeFake(connectionPersistent);
        }
예제 #7
0
        public void SetupTest()
        {
            // подготовить свежие котировки
            QuoteMaker.FillQuoteStorageWithDefaultValues();
            conn = TradeSharpConnectionPersistent.InitializeTradeSharpConnection();
            ACCOUNT eurAccount;

            AccountShareTestDataMaker.MakePammData(conn, out testAccount, out shareOwner, out eurAccount);
        }
예제 #8
0
        public void SetupMethods()
        {
            EntityConnection connection;

            connectionPersistent          = TradeSharpConnectionPersistent.InitializeTradeSharpConnection(out connection);
            exceptionConnectionPersistent = new TradeSharpConnectionPersistent(connection)
            {
                TestException = new Exception("DB context has failed")
            };
            DatabaseContext.InitializeFake(connectionPersistent);
        }
예제 #9
0
        public void InitTest()
        {
            // забить котировки
            QuoteMaker.FillQuoteStorageWithDefaultValues();

            // словари
            TradeSharpDictionary.Initialize(MoqTradeSharpDictionary.Mock);

            // временно удалить файл начального наполнения (открытые ордера)
            TradeSharpConnectionPersistent.RestoreCsvFilesInMoqDbFolder();
            //TradeSharpConnectionPersistent.RenameCsvFilesContainingAccountDataInMoqDbFolder();
            conn = TradeSharpConnectionPersistent.InitializeTradeSharpConnection();
            MakeTestData();
        }
예제 #10
0
        public void Setup()
        {
            conn = TradeSharpConnectionPersistent.InitializeTradeSharpConnection();
            // подготовить свежие котировки
            QuoteMaker.FillQuoteStorageWithDefaultValues();

            // словари
            TradeSharpDictionary.Initialize(MoqTradeSharpDictionary.Mock);

            ManagerTrade.MakeTestInstance();
            testManager = ManagerAccount.Instance;

            // тестовые данные
            MakeTestData();
        }
예제 #11
0
        public void Setup()
        {
            conn = TradeSharpConnectionPersistent.InitializeTradeSharpConnection();
            ManagerTrade.MakeTestInstance();
            subscriber = (from usr in conn.PLATFORM_USER
                          join w in conn.WALLET on usr.ID equals w.User
                          join pa in conn.PLATFORM_USER_ACCOUNT on usr.ID equals pa.PlatformUser
                          where pa.RightsMask == (int)AccountRights.Управление && w.Currency == SubscriberCurx && w.Balance > 40
                          select usr).First();

            CreateServiceWithOwner("USD", 5, out serviceOwnerUsd, out serviceUsd);
            CreateServiceWithOwner("RUB", 25, out serviceOwnerRub, out serviceRub);
            QuoteStorage.Instance.UpdateValues("USDRUB", new QuoteData(35.20f, 35.20f, DateTime.Now));

            // словари
            TradeSharpDictionary.Initialize(MoqTradeSharpDictionary.Mock);
        }
예제 #12
0
 private void SetupDatabase()
 {
     connectionPersistent = TradeSharpConnectionPersistent.InitializeTradeSharpConnection();
 }
예제 #13
0
 public void Setup()
 {
     connectionPersistent = TradeSharpConnectionPersistent.InitializeTradeSharpConnection();
     DatabaseContext.InitializeFake(connectionPersistent);
 }
예제 #14
0
 public void InitTest()
 {
     connectionPersistent = TradeSharpConnectionPersistent.InitializeTradeSharpConnection();
 }
예제 #15
0
        public void SetupTest()
        {
            MakeFakeTradeProxy();

            conn = TradeSharpConnectionPersistent.InitializeTradeSharpConnection();

            // очистить подписки на портфели
            foreach (var sub in conn.USER_TOP_PORTFOLIO.ToList())
            {
                conn.USER_TOP_PORTFOLIO.Remove(sub);
            }
            foreach (var portf in conn.TOP_PORTFOLIO.ToList())
            {
                conn.TOP_PORTFOLIO.Remove(portf);
            }
            conn.SaveChanges();

            // определить владельцев портфелей и подписантов
            portOwners =
                conn.PLATFORM_USER_ACCOUNT.Where(a => a.RightsMask == (int)AccountRights.Управление).Take(2).ToArray();
            var lastOwnerId = portOwners[portOwners.Length - 1].PlatformUser;

            portSubs =
                conn.PLATFORM_USER_ACCOUNT.Where(a => a.RightsMask == (int)AccountRights.Управление).Where(a => a.PlatformUser > lastOwnerId).Take(2).ToArray();

            // создать портфели
            portfolios = new []
            {
                new TOP_PORTFOLIO
                {
                    Criteria         = "AYP",
                    ParticipantCount = 3,
                    OwnerUser        = portOwners[0].PlatformUser,
                    Name             = "P1"
                },
                new TOP_PORTFOLIO
                {
                    Criteria         = "DD",
                    ParticipantCount = 2,
                    OwnerUser        = portOwners[1].PlatformUser,
                    Name             = "P1"
                }
            };
            foreach (var pf in portfolios)
            {
                conn.TOP_PORTFOLIO.Add(pf);
            }
            conn.SaveChanges();

            // подписать пользователей на портфели
            var curPortfolioIndex = 0;

            foreach (var usr in portSubs)
            {
                var port = portfolios[curPortfolioIndex++];
                if (curPortfolioIndex == portfolios.Length)
                {
                    curPortfolioIndex = 0;
                }
                conn.USER_TOP_PORTFOLIO.Add(new USER_TOP_PORTFOLIO
                {
                    User      = usr.PlatformUser,
                    Portfolio = port.Id
                });
            }
            conn.SaveChanges();
        }
예제 #16
0
        public void Setup()
        {
            // подыграть за торговый контракт
            SetupFakeServer();

            // инициализировать словари (прежде всего - словарь тикеров)
            TradeSharpDictionary.Initialize(MoqTradeSharpDictionary.Mock);

            connection = TradeSharpConnectionPersistent.InitializeTradeSharpConnection();

            // пользователь - владелец тестового сервиса
            var ownerUser = new PLATFORM_USER
            {
                Email            = "*****@*****.**",
                Login            = "******",
                Title            = "Vafel",
                RoleMask         = 0,
                Password         = "******",
                RegistrationDate = DateTime.Now
            };

            connection.PLATFORM_USER.Add(ownerUser);
            connection.SaveChanges();

            // добавить категорию сигналов
            var srv = new SERVICE
            {
                FixedPrice = 0,
                Currency   = "USD",
                User       = ownerUser.ID
            };

            connection.SERVICE.Add(srv);
            connection.SaveChanges();
            serviceId = srv.ID;

            // добавить пользователя
            var user = new PLATFORM_USER
            {
                Email            = "*****@*****.**",
                Login            = "******",
                Password         = "******",
                Title            = "test",
                RegistrationDate = DateTime.Now
            };

            connection.PLATFORM_USER.Add(user);
            connection.SaveChanges();
            testUserId = user.ID;

            // добавить счет и сделок
            var group   = connection.ACCOUNT_GROUP.First(g => !g.IsReal);
            var account = new ACCOUNT
            {
                AccountGroup = group.Code,
                Currency     = AccountCurrency,
                Balance      = 30000
            };

            connection.ACCOUNT.Add(account);
            connection.SaveChanges();
            testAccountId = account.ID;

            // назначить пользователя владельцем счета
            connection.PLATFORM_USER_ACCOUNT.Add(new PLATFORM_USER_ACCOUNT
            {
                Account      = testAccountId,
                PlatformUser = testUserId,
                RightsMask   = (int)AccountRights.Управление
            });

            // подписать счет на сигнал
            connection.SUBSCRIPTION.Add(new SUBSCRIPTION
            {
                User      = testUserId,
                Service   = serviceId,
                RenewAuto = true,
                TimeEnd   = DateTime.Now.Date.AddDays(1)
            });
            connection.SUBSCRIPTION_SIGNAL.Add(new SUBSCRIPTION_SIGNAL
            {
                User            = testUserId,
                Service         = serviceId,
                AutoTrade       = true,
                PercentLeverage = 120,
                MinVolume       = 10000,
                TargetAccount   = testAccountId
            });
            connection.SaveChanges();

            // позиции
            MakeOrdersForTest();
            foreach (var order in ordersForTest)
            {
                var pos = LinqToEntity.UndecorateOpenedPosition(order);
                connection.POSITION.Add(pos);
            }
            connection.SaveChanges();

            // прописать срез котировок
            var nowTime = DateTime.Now;

            Contract.Util.BL.QuoteStorage.Instance.UpdateValues(new []
            {
                "EURUSD", "GBPUSD", "USDJPY", "EURGBP"
            },
                                                                new []
            {
                new QuoteData(1.3820f, 1.3822f, nowTime),
                new QuoteData(1.5350f, 1.5354f, nowTime),
                new QuoteData(90.81f, 90.83f, nowTime),
                new QuoteData(1.1107f, 1.1112f, nowTime)
            }
                                                                );
        }