예제 #1
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();
        }
예제 #2
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)
                    }
                );
        }