public void Setup()
        {
            // ITradeSharpServer
            var fakeServer = ProxyBuilder.Instance.MakeImplementer <ITradeSharpServer>(true);

            ((IMockableProxy)fakeServer).MockMethods.Add(
                StronglyName.GetMethodName <ITradeSharpServer>(s => s.GetAllManagers(null)),
                new Func <PaidServiceType?, List <PerformerStat> >(srvType => testPerformers));

            ((IMockableProxy)fakeServer).MockMethods.Add(
                StronglyName.GetMethodName <ITradeSharpServer>(s => s.GetCompanyTopPortfolioManagedAccounts()),
                new Func <List <PerformerStat> >(() => new List <PerformerStat>()));
            TradeSharpServer.Initialize(fakeServer);

            //// ITradeSharpAccount
            //private delegate RequestStatus GetMarketOrdersDel(int accountId, out List<MarketOrder> orders);
            //var fakeServerAccount = ProxyBuilder.Instance.MakeImplementer<ITradeSharpAccount>(true);
            //List<MarketOrder> orderList;
            //((IMockableProxy)fakeServerAccount).MockMethods.Add(
            //    StronglyName.GetMethodName<ITradeSharpAccount>(s => s.GetMarketOrders(0, out orderList)),
            //    new GetMarketOrdersDel((int id, out List<MarketOrder> orders) =>
            //        {

            //        }));
        }
        private void SetupFakeStatistics()
        {
            allPerformers = (from account in conn.ACCOUNT
                             join ua in conn.PLATFORM_USER_ACCOUNT on account.ID equals ua.Account
                             join srv in conn.SERVICE on ua.PlatformUser equals srv.User
                             where account.Balance > 0
                             select new PerformerStat
            {
                Account = account.ID,
                DepoCurrency = account.Currency,
                Service = srv.ID
            }).ToList();
            for (var i = 0; i < allPerformers.Count; i++)
            {
                allPerformers[i].Profit = (i - 10) * 5;
            }

            var accountStatistics = ProxyBuilder.Instance.MakeImplementer <IAccountStatistics>(true);

            ((IMockableProxy)accountStatistics).MockMethods.Add(StronglyName.GetMethodName <IAccountStatistics>(s =>
                                                                                                                s.GetAllPerformersWithCriteria(false, "", 0, true, null, 0)),
                                                                new Func <bool, string, int, bool, float?, int, List <PerformerStat> >(
                                                                    (managersOnly, criteria, count, asc, filterValue, serviceTypeMask) =>
            {
                return((asc
                            ? allPerformers.OrderBy(p => p.Profit)
                            : allPerformers.OrderByDescending(p => p.Profit)).Take(count).ToList());
            })
                                                                );

            TradeSharpAccountStatistics.Initialize(accountStatistics);
        }
예제 #3
0
        public void Setup()
        {
            // забить котировки
            QuoteMaker.FillQuoteStorageWithDefaultValues();
            // словари
            TradeSharpDictionary.Initialize(MoqTradeSharpDictionary.Mock);
            // ордера
            MakeTestOrders();
            // прокси
            var proxyAccount = ProxyBuilder.Instance.MakeImplementer <ITradeSharpAccount>(true);

            ((IMockableProxy)proxyAccount).MockMethods.Add(
                StronglyName.GetMethodName <ITradeSharpAccount>(a => a.GetClosedOrders(0, "", 0, 0)),
                new Func <int, string, int, int, List <MarketOrder> >((accountId, ticker, startId, maxCount) =>
                                                                      testOrders.Where(o => o.Symbol == ticker && o.ID > startId && o.State == PositionState.Closed).Take(maxCount).ToList())
                );
            List <MarketOrder> opOrders;

            ((IMockableProxy)proxyAccount).MockMethods.Add(
                StronglyName.GetMethodName <ITradeSharpAccount>(a => a.GetMarketOrders(0, out opOrders)),
                new GetMarketOrdersDel((int accountId, out List <MarketOrder> resOrders) =>
            {
                resOrders = testOrders.Where(o => o.State == PositionState.Opened).ToList();
                return(RequestStatus.OK);
            })
                );

            TradeSharpAccount.Initialize(proxyAccount);
            // тестовый счет
            AccountStatus.Instance.AccountData = new Account
            {
                Currency = "USD"
            };
        }
예제 #4
0
 private void MakeFakeTradeProxy()
 {
     Dealer.fakeProxyTrade = ProxyBuilder.Instance.MakeImplementer <ITradeSharpServerTrade>(true);
     ((IMockableProxy)Dealer.fakeProxyTrade).MockMethods.Add(
         StronglyName.GetMethodName <ITradeSharpServerTrade>(s => s.SubscribeOnPortfolio(null, "", null, null, null)),
         new Func <ProtectedOperationContext, string, TopPortfolio, decimal?, AutoTradeSettings, RequestStatus>((
                                                                                                                    secCtx, subscriberLogin, portfolio, maxFee, tradeSets) =>
     {
         if (secCtx == null)
         {
             throw new Exception("SubscribeOnPortfolio - sec ctx is null");
         }
         if (string.IsNullOrEmpty(subscriberLogin))
         {
             throw new Exception("SubscribeOnPortfolio - portfolio is null");
         }
         if (portfolio == null)
         {
             throw new Exception("SubscribeOnPortfolio - portfolio is null");
         }
         if (portfolio.Id == 0)
         {
             throw new Exception("SubscribeOnPortfolio - portfolio Id is 0");
         }
         //if (tradeSets == null) throw new Exception("SubscribeOnPortfolio - tradeSets is null");
         return(RequestStatus.OK);
     })
         );
 }
예제 #5
0
        private void MakeTradeSharpServerTradeProxy()
        {
            fakeServerTrade = ProxyBuilder.Instance.MakeImplementer <ITradeSharpServerTrade>(true);

            // ReSharper disable SuspiciousTypeConversion.Global
            ((IMockableProxy)fakeServerTrade).MockMethods.Add(
                // ReSharper restore SuspiciousTypeConversion.Global
                StronglyName.GetMethodName <ITradeSharpServerTrade>(
                    f => f.SendEditMarketRequest(null, null)),
                new Func <ProtectedOperationContext, MarketOrder, RequestStatus>((ctx, order) => RequestStatus.OK));
        }
예제 #6
0
        private void SetupFakeServer()
        {
            var fakeProxy = ProxyBuilder.Instance.MakeImplementer <ITradeSharpServerTrade>(true);

            Dealer.fakeProxyTrade = fakeProxy;

            // "замочить" нужные методы
            // ReSharper disable SuspiciousTypeConversion.Global
            ((IMockableProxy)fakeProxy).MockMethods.Add(
                // ReSharper restore SuspiciousTypeConversion.Global
                StronglyName.GetMethodName <ITradeSharpServerTrade>(
                    f => f.SendNewOrderRequest(null, 0, null, OrderType.Market, 0, 0)), // название метода - SendNewOrderRequest
                // тело мок-метода
                new Func <ProtectedOperationContext, int, MarketOrder, OrderType, decimal, decimal, RequestStatus>((
                                                                                                                       ctx, requestUniqueId, order, orderType, requestedPrice, slippagePoints) =>
            {
                marketRequests.Add(requestUniqueId, order);
                return(RequestStatus.OK);
            }));
        }
예제 #7
0
        private void MakeTradeSharpAccountProxy()
        {
            fakeAccountManager = ProxyBuilder.Instance.MakeImplementer <ITradeSharpAccount>(true);
            // "замочить" нужные методы
            // ReSharper disable SuspiciousTypeConversion.Global
            Account account;

            ((IMockableProxy)fakeAccountManager).MockMethods.Add(
                // ReSharper restore SuspiciousTypeConversion.Global
                StronglyName.GetMethodName <ITradeSharpAccount>(
                    f => f.GetAccountInfo(0, false, out account)),
                new GetAccountInfoDel((int accountId, bool needEquityInfo, out Account act) =>
            {
                act    = testAccount;
                act.ID = accountId;

                if (needEquityInfo)
                {
                    List <MarketOrder> ordList;
                    fakeAccountManager.GetMarketOrders(accountId, out ordList);
                    var profit = DalSpot.Instance.CalculateOpenedPositionsCurrentResult(ordList,
                                                                                        QuoteStorage.Instance.ReceiveAllData(), act.Currency);
                    act.Equity = act.Balance + (decimal)profit;
                }
                return(RequestStatus.OK);
            }));
            List <MarketOrder> orders;

            // ReSharper disable SuspiciousTypeConversion.Global
            ((IMockableProxy)fakeAccountManager).MockMethods.Add(
                // ReSharper restore SuspiciousTypeConversion.Global
                StronglyName.GetMethodName <ITradeSharpAccount>(
                    f => f.GetMarketOrders(0, out orders)),
                new GetMarketOrdersDel((int accountId, out List <MarketOrder> ordList) =>
            {
                ordList = new List <MarketOrder>
                {
                    new MarketOrder
                    {
                        AccountID  = accountId,
                        Symbol     = "EURUSD",
                        Side       = (int)DealType.Buy,
                        Volume     = 100000,
                        PriceEnter = 1.3140f,
                        State      = PositionState.Opened
                    },
                    new MarketOrder
                    {
                        AccountID  = accountId,
                        Symbol     = "EURUSD",
                        Side       = (int)DealType.Sell,
                        Volume     = 20000,
                        PriceEnter = 1.3180f,
                        State      = PositionState.Opened
                    },
                    new MarketOrder
                    {
                        AccountID  = accountId,
                        Symbol     = "USDCAD",
                        Side       = (int)DealType.Sell,
                        Volume     = 80000,
                        PriceEnter = 1.1130f,
                        State      = PositionState.Opened
                    }
                };
                return(RequestStatus.OK);
            }));
        }
        public void Setup()
        {
            // словари
            TradeSharpDictionary.Initialize(MoqTradeSharpDictionary.Mock);

            // заглушки для диалогов - выбора пользователей
            UserServiceRegistrator.DialogBoxProvider = new TestDialogBoxProvider();

            // серверный (торговый) прокси
            fakeTradeServer = ProxyBuilder.Instance.GetImplementer <ITradeSharpServerTrade>();
            List <Account> accounts;
            var            getUserOwnedAccountsWithActualBalanceMethodName =
                ProxyBuilder.GetMethodName <ITradeSharpServerTrade>(a => a.GetUserOwnedAccountsWithActualBalance("",
                                                                                                                 null, false, out accounts));

            ((IMockableProxy)fakeTradeServer).MockMethods.Add(getUserOwnedAccountsWithActualBalanceMethodName,
                                                              new GetUserOwnedAccountsWithActualBalanceDel((string login, ProtectedOperationContext secCtx, bool realOnly,
                                                                                                            out List <Account> acts) =>
            {
                acts = new List <Account>
                {
                    new Account
                    {
                        Balance  = 12000,
                        Currency = "USD",
                        ID       = 51,
                        Group    = "Real"
                    },
                    new Account
                    {
                        Balance  = 2000,
                        Currency = "USD",
                        ID       = 52,
                        Group    = "Real"
                    }
                };
                return(AuthenticationResponse.OK);
            }));
            MainForm.serverProxyTrade = new TradeSharpServerTrade(fakeTradeServer);

            // кошельковый прокси
            fakeWalletManager = ProxyBuilder.Instance.GetImplementer <IWalletManager>();
            ((IMockableProxy)fakeWalletManager).MockMethods.Add(StronglyName.GetMethodName <IWalletManager>(
                                                                    w => w.GetUserWallet(null, null)),
                                                                new Func <ProtectedOperationContext, string, Wallet>(
                                                                    (context, s) => new Wallet
            {
                Balance  = 1005,
                Currency = "USD",
                User     = 50
            }));
            WalletError walletError;
            var         registerOrUpdateServiceMethodName =
                ProxyBuilder.GetMethodName <IWalletManager>(w => w.RegisterOrUpdateService(
                                                                null, null, out walletError));

            ((IMockableProxy)fakeWalletManager).MockMethods.Add(registerOrUpdateServiceMethodName,
                                                                new RegisterOrUpdateServiceDel(
                                                                    (ProtectedOperationContext ctx, PaidService service,
                                                                     out WalletError error) =>
            {
                error = WalletError.OK;
                return(true);
            }));
            TradeSharpWalletManager.Initialize(fakeWalletManager);
        }