Example #1
0
        public static AccountUserModel DecoratePlatformUser(PLATFORM_USER platformUser)
        {
            var result = new AccountUserModel
            {
                UserId = platformUser.ID,
                UserName = platformUser.Name,
                UserSurname = platformUser.Surname,
                UserPatronym = platformUser.Patronym,
                UserDescription = platformUser.Description,
                UserEmail = platformUser.Email,
                UserLogin = platformUser.Login,
                UserPassword = platformUser.Password,
                UserPhone1 = platformUser.Phone1,
                UserPhone2 = platformUser.Phone2,
                UserRoleMask = (UserRole)platformUser.RoleMask,
                UserRightsMask = new Dictionary<int, UserAccountRights>(),
                UserRegistrationDate = platformUser.RegistrationDate
            };

            return result;
        }
Example #2
0
        public static PLATFORM_USER UndecoratePlatformUser(PlatformUser user)
        {
            var us = new PLATFORM_USER
            {
                ID               = user.ID,
                Title            = user.Title,
                Login            = user.Login,
                Name             = user.Name,
                Password         = user.Password,
                Patronym         = user.Patronym,
                Phone1           = user.Phone1,
                Phone2           = user.Phone2,
                RoleMask         = (int)user.RoleMask,
                Surname          = user.Surname,
                Description      = user.Description,
                Email            = user.Email,
                RegistrationDate = user.RegistrationDate
            };

            return(us);
        }
Example #3
0
        private string CreateAccount(out int accountId)
        {
            accountId = -1;
            if (string.IsNullOrEmpty(tbLogin.Text) ||
                string.IsNullOrEmpty(tbEmail.Text) ||
                string.IsNullOrEmpty(tbPassword.Text) ||
                cbAccountGroup.SelectedIndex < 0) return "Поля не заполнены";

            var login = tbLogin.Text;
            var password = tbPassword.Text;
            var email = tbEmail.Text;
            var group = cbAccountGroup.SelectedItem.ToString();
            var depo = tbStartDepo.Text.ToDecimalUniformSafe() ?? 0;
            var createTime = dpCreateTime.Value;

            using (var conn = DatabaseContext.Instance.Make())
            {
                if (conn.PLATFORM_USER.Any(u => u.Login == login))
                    return "Логин занят";
                if (conn.PLATFORM_USER.Any(u => u.Email == email))
                    return "Email занят";

                try
                {
                    var usr = new PLATFORM_USER
                    {
                        Login = login,
                        Password = password,
                        Email = email,
                        Name = tbName.Text,
                        Surname = tbSurname.Text,
                        RegistrationDate = createTime,
                        RoleMask = 0,
                        Patronym = "Н",
                        Title = "-"
                    };
                    conn.PLATFORM_USER.Add(usr);
                    var account = new ACCOUNT
                    {
                        Currency = "USD",
                        Balance = depo,
                        MaxLeverage = tbMaxLeverage.Text.ToDecimalUniformSafe() ?? 100,
                        AccountGroup = group,
                        TimeCreated = createTime,
                        Status = (int) Account.AccountStatus.Created
                    };
                    conn.ACCOUNT.Add(account);
                    conn.SaveChanges();
                    var pa = new PLATFORM_USER_ACCOUNT
                    {
                        PlatformUser = usr.ID,
                        Account = account.ID,
                        RightsMask = 0
                    };
                    conn.PLATFORM_USER_ACCOUNT.Add(pa);

                    var bc = new BALANCE_CHANGE
                    {
                        AccountID = account.ID,
                        Amount = depo,
                        ChangeType = (int) BalanceChangeType.Deposit,
                        Description = "Initial deposit",
                        ValueDate = createTime
                    };
                    conn.BALANCE_CHANGE.Add(bc);
                    conn.SaveChanges();
                    accountId = account.ID;
                    return string.Empty;
                }
                catch (Exception ex)
                {
                    return ex.GetType().Name + ": " + ex.Message;
                }
            }
        }
 private static bool CheckPhoneCriteria(ColumnFilterCriteria crit, PLATFORM_USER user, string specimen)
 {
     if (crit == ColumnFilterCriteria.Равно && user.Phone1 != specimen && user.Phone2 != specimen) return false;
     if (crit == ColumnFilterCriteria.НеРавно && (user.Phone1 == specimen || user.Phone2 == specimen)) return false;
     if (crit == ColumnFilterCriteria.Включает && (user.Phone1.Contains(specimen) ||
         user.Phone2.Contains(specimen)) == false) return false;
     if (crit == ColumnFilterCriteria.НачинаетсяС && (user.Phone1.StartsWith(specimen) ||
         user.Phone2.StartsWith(specimen)) == false) return false;
     if (crit == ColumnFilterCriteria.КончаетсяНа && (user.Phone1.EndsWith(specimen) ||
         user.Phone2.EndsWith(specimen)) == false) return false;
     return true;
 }
Example #5
0
        private void MakeTestData()
        {
            paidService = conn.SERVICE.First(s => s.Currency == "USD");
            srvOwner = paidService.PLATFORM_USER;
            srvSubscriber = conn.PLATFORM_USER.First(u => u.WALLET.Currency == "USD" && u.ID != srvOwner.ID);
            // аккаунт с дольками и открытыми позами
            accountShared = conn.ACCOUNT.First(a => a.POSITION.Count > 1 && a.POSITION.Count < 200);
            accountSharedOwner = (from pa in conn.PLATFORM_USER_ACCOUNT
                                  join u in conn.PLATFORM_USER on pa.PlatformUser equals u.ID
                                  where pa.Account == accountShared.ID
                                  select u).First();
            // добавить ПАММ-сервис
            conn.SERVICE.Add(new SERVICE
                {
                    Currency = "USD",
                    ServiceType = (int) PaidServiceType.PAMM,
                    AccountId = accountShared.ID,
                    User = accountSharedOwner.ID,
                    Comment = "PAMMMmm"
                });

            // добавить дольки
            var oneMoreUser = conn.PLATFORM_USER.First(u => u.ID != accountSharedOwner.ID);
            conn.ACCOUNT_SHARE.Add(new ACCOUNT_SHARE
                {
                    Account = accountShared.ID,
                    Share = 55,
                    ShareOwner = accountSharedOwner.ID
                });
            conn.ACCOUNT_SHARE.Add(new ACCOUNT_SHARE
            {
                Account = accountShared.ID,
                Share = 45,
                ShareOwner = oneMoreUser.ID
            });
            conn.SaveChanges();
        }
Example #6
0
        public void TestInvestInPAMM()
        {
            // PAMM-инвестор
            var pammInvestor = new PLATFORM_USER
                {
                    Email = "*****@*****.**",
                    Login = "******",
                    Password = "******",
                    RegistrationDate = DateTime.Now,
                    RoleMask = (int) UserRole.Trader,
                    Title = "trader"
                };
            conn.PLATFORM_USER.Add(pammInvestor);
            conn.SaveChanges();
            var wallet = new WALLET
                {
                    User = pammInvestor.ID,
                    Balance = 160000,
                    Currency = "USD",
                    Password = "******"
                };
            conn.WALLET.Add(wallet);
            conn.SaveChanges();

            // посчитать, что было ДО инвестирования в ПАММ
            List<AccountShare> shares;
            bool noQuoteError;
            WalletManager.CalculateAccountEquityWithShares(conn, accountShared, accountSharedOwner.ID,
                                                 Contract.Util.BL.QuoteStorage.Instance.ReceiveAllData(),
                                                 out shares, out noQuoteError);

            // инвестировать в ПАММ
            const decimal amountToInvest = 10000;
            var oldBalance = accountShared.Balance;
            var status = walletManager.InvestInPAMM(ProtectedOperationContext.MakeServerSideContext(),
                                                pammInvestor.Login, accountShared.ID, amountToInvest);
            Assert.AreEqual(RequestStatus.OK, status, "InvestInPAMM - должно быть ОК");
            accountShared = conn.ACCOUNT.First(a => a.ID == accountShared.ID);

            var shouldBeBalance = oldBalance + amountToInvest;
            Assert.IsTrue(shouldBeBalance.RoughCompares(accountShared.Balance, 0.1M),
                "InvestInPAMM - баланс счета должен увеличиться на сумму вложения");

            var newShares = conn.ACCOUNT_SHARE.Where(s => s.Account == accountShared.ID).ToList();
            Assert.AreEqual(shares.Count + 1, newShares.Count, "InvestInPAMM - добавился один пай");
            var sumSharesPercent = newShares.Sum(s => s.Share);
            Assert.IsTrue(100M.RoughCompares(sumSharesPercent, 0.000001M),
                "InvestInPAMM - сумма паев осталась 100%");
            Assert.IsTrue(newShares.Any(s => s.ShareOwner == pammInvestor.ID),
                "InvestInPAMM - новый владелец должен быть в списке пайщиков");
            Assert.IsTrue(conn.SUBSCRIPTION.Any(s => s.User == pammInvestor.ID),
                "InvestInPAMM - должна появиться подписка");

            // инвестировать еще денег
            const decimal moreMoney = 145201.55M;
            status = walletManager.InvestInPAMM(ProtectedOperationContext.MakeServerSideContext(),
                                                pammInvestor.Login, accountShared.ID, moreMoney);
            Assert.AreEqual(RequestStatus.OK, status, "InvestInPAMM (повторно) - должно быть ОК");
            var updatedNewShares = conn.ACCOUNT_SHARE.Where(s => s.Account == accountShared.ID).ToList();
            Assert.AreEqual(newShares.Count, updatedNewShares.Count, "InvestInPAMM (повторно) - количество паев не должно меняться");
            sumSharesPercent = updatedNewShares.Sum(s => s.Share);
            Assert.IsTrue(100M.RoughCompares(sumSharesPercent, 0.000001M),
                "InvestInPAMM (повторно) - сумма паев осталась 100%");

            status = walletManager.InvestInPAMM(ProtectedOperationContext.MakeServerSideContext(),
                pammInvestor.Login, accountShared.ID, moreMoney);
            Assert.AreEqual(RequestStatus.MarginOrLeverageExceeded, status,
                "InvestInPAMM (превышение баланса) - должно быть MarginOrLeverageExceeded");

            // вывести из ПАММа кусочек
            const decimal withdrawnMoney = 50.25M;
            var balanceBeforeWth = conn.WALLET.First(w => w.User == pammInvestor.ID).Balance;
            status = walletManager.WithdrawFromPAMM(ProtectedOperationContext.MakeServerSideContext(),
                                                pammInvestor.Login, accountShared.ID, withdrawnMoney, false);
            Assert.AreEqual(RequestStatus.OK, status, "InvestInPAMM (вывод средств) - должно быть OK");
            var sharesAfterWithdraw = conn.ACCOUNT_SHARE.Where(s => s.Account == accountShared.ID).ToList();
            var balanceAfterWth = conn.WALLET.First(w => w.User == pammInvestor.ID).Balance;
            Assert.IsTrue(balanceBeforeWth.RoughCompares(balanceAfterWth - withdrawnMoney, 0.005M),
                "баланс должен увеличиться на сумму вывода");
            Assert.AreEqual(updatedNewShares.Count, sharesAfterWithdraw.Count,
                "InvestInPAMM (вывод средств) - количество паёв не должно измениться");
            Assert.IsTrue(conn.SUBSCRIPTION.Any(s => s.User == pammInvestor.ID),
                "InvestInPAMM (вывод средств) - должна остаться подписка");

            // попробовать вывести слишком много
            status = walletManager.WithdrawFromPAMM(ProtectedOperationContext.MakeServerSideContext(),
                                                pammInvestor.Login, accountShared.ID, 1000000, false);
            Assert.AreEqual(RequestStatus.BadRequest, status,
                "InvestInPAMM (вывод средств) - должно быть BadRequest");

            // вывести остаток
            status = walletManager.WithdrawFromPAMM(ProtectedOperationContext.MakeServerSideContext(),
                                                pammInvestor.Login, accountShared.ID, 0, true);
            Assert.AreEqual(RequestStatus.OK, status, "InvestInPAMM (вывод всех средств) - должно быть OK");
            Assert.IsFalse(conn.SUBSCRIPTION.Any(s => s.User == pammInvestor.ID),
                "InvestInPAMM (вывод всех средств) - должна удалиться подписка");
            Assert.IsFalse(conn.ACCOUNT_SHARE.Any(s => s.ShareOwner == pammInvestor.ID),
                "InvestInPAMM (вывод всех средств) - должна удалиться долька нашего пайщика");
        }
        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)
                    }
                );
        }
Example #8
0
        private Wallet GetMoneyFromUserOwnedAccount(int accountId, decimal amountInSrcCurrency, out WalletError error,
                                                    ACCOUNT account, WALLET wallet, TradeSharpConnection ctx, PLATFORM_USER user)
        {
            var amountWallet = amountInSrcCurrency;
            if (account.Currency != wallet.Currency)
            {
                // найти котировку и перевести
                string errorString;
                var amountTarget = DalSpot.Instance.ConvertSourceCurrencyToTargetCurrency(wallet.Currency,
                                                                                          account.Currency,
                                                                                          (double) amountWallet,
                                                                                          QuoteStorage.Instance.ReceiveAllData(),
                                                                                          out errorString);
                if (!amountTarget.HasValue)
                {
                    Logger.ErrorFormat("DepositOrWithdraw({0} {1}): {2} (withdraw)",
                                       amountInSrcCurrency, account.Currency + "/" + wallet.Currency,
                                       errorString);
                    error = WalletError.CurrencyExchangeFailed;
                    return null;
                }
                amountWallet = amountTarget.Value;
            }

            // достаточно ли средств на счете?
            // проверить средства / зарезервированное марж. обеспечение
            decimal equity, usedMargin;
            if (!GetAccountEquityAndUsedMargin(account, out equity, out usedMargin))
            {
                error = WalletError.ServerError;
                return null;
            }
            if (equity - usedMargin < amountInSrcCurrency)
            {
                error = WalletError.ServerError;
                return null;
            }

            // списать со счета в пользу кошелька
            wallet.Balance += amountInSrcCurrency;
            account.Balance -= amountInSrcCurrency;
            var date = DateTime.Now;
            var bc = ctx.BALANCE_CHANGE.Add(new BALANCE_CHANGE
                {
                    AccountID = accountId,
                    Amount = amountInSrcCurrency,
                    ChangeType = (int) BalanceChangeType.Withdrawal,
                    ValueDate = date,
                    Description = "Списание на кошелек №" + wallet.User
                });
            ctx.SaveChanges();
            ctx.TRANSFER.Add(new TRANSFER
                {
                    Amount = amountWallet,
                    TargetAmount = amountWallet,
                    User = user.ID,
                    Comment = "Вывод средств со счета №" + account.ID,
                    ValueDate = date,
                    BalanceChange = bc.ID,
                });

            ctx.SaveChanges();
            error = WalletError.OK;
            return LinqToEntity.DecorateWallet(wallet);
        }
 private void FindSubscriber()
 {
     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 > 1000
                   select usr).First();
     // отписать будущего подписчика от всех служб
     var ownedSubs = conn.SUBSCRIPTION.Where(s => s.User == subscriber.ID).ToList();
     foreach (var sub in ownedSubs)
     {
         conn.SUBSCRIPTION.Remove(sub);
     }
     conn.SaveChanges();
 }
Example #10
0
        private static Wallet PutMoneyOnUserOwnedAccount(int accountId, decimal amountInSrcCurrency, out WalletError error,
                                                         WALLET wallet, ACCOUNT account, TradeSharpConnection ctx,
                                                         PLATFORM_USER user)
        {
            // достаточно ли денег в кошельке?
            if (amountInSrcCurrency > wallet.Balance)
            {
                error = WalletError.InsufficientFunds;
                return null;
            }

            // перевести объем в валюту счета
            var amount = amountInSrcCurrency;
            if (account.Currency != wallet.Currency)
            {
                // найти котировку и перевести
                string errorString;
                var amountTarget = DalSpot.Instance.ConvertSourceCurrencyToTargetCurrency(account.Currency,
                                                                                          wallet.Currency, (double) amount,
                                                                                          QuoteStorage.Instance.ReceiveAllData(),
                                                                                          out errorString);
                if (!amountTarget.HasValue)
                {
                    Logger.ErrorFormat("DepositOrWithdraw({0} {1}): {2}",
                                       amountInSrcCurrency, account.Currency + "/" + wallet.Currency,
                                       errorString);
                    error = WalletError.CurrencyExchangeFailed;
                    return null;
                }
                amount = amountTarget.Value;
            }

            // списать с кошелька и пополнить счет
            wallet.Balance -= amountInSrcCurrency;
            account.Balance += amount;
            var dateOper = DateTime.Now;
            var balanceChange = ctx.BALANCE_CHANGE.Add(new BALANCE_CHANGE
                {
                    AccountID = accountId,
                    Amount = amount,
                    ChangeType = (int) BalanceChangeType.Deposit,
                    ValueDate = dateOper,
                    Description = "Пополнение с кошелька №" + wallet.User
                });
            try
            {
                ctx.SaveChanges();
            }
            catch (Exception ex)
            {
                Logger.Error("DepositOrWithdraw() - error saving balance change", ex);
                error = WalletError.ServerError;
                return null;
            }

            var balanceChangeId = balanceChange.ID;
            ctx.TRANSFER.Add(new TRANSFER
                {
                    Amount = -amountInSrcCurrency,
                    TargetAmount = -amountInSrcCurrency,
                    User = user.ID,
                    Comment = "Т. счет №" + account.ID,
                    ValueDate = dateOper,
                    BalanceChange = balanceChangeId,
                });

            try
            {
                ctx.SaveChanges();
            }
            //catch (System.Data.Entity.Infrastructure.DbUpdateConcurrencyException)
            //{
            //}
            catch (Exception ex)
            {
                Logger.Error("DepositOrWithdraw() - error saving transfer for user " + user.ID +
                             ", balance change Id: " + balanceChangeId + ", user: " + user.ID, ex);
                error = WalletError.ServerError;
                return null;
            }
            error = WalletError.OK;
            return LinqToEntity.DecorateWallet(wallet);
        }
        private RequestStatus FindPAMMServiceWithOwner()
        {
            owner = (from pa in ctx.PLATFORM_USER_ACCOUNT
                         join u in ctx.PLATFORM_USER on pa.PlatformUser equals u.ID
                         where pa.Account == accountId && pa.RightsMask == (int)AccountRights.Управление
                         select u).FirstOrDefault();
            if (owner == null)
            {
                Logger.ErrorFormat("InvestOrWithdrawFromPamm(acc={0}) - владелец счета не найден", accountId);
                return RequestStatus.IncorrectData;
            }

            // найти ПАММ-сервис для целевого акаунта
            service = (from srv in ctx.SERVICE
                           where srv.AccountId == accountId &&
                                 srv.User == owner.ID && srv.ServiceType == (int)PaidServiceType.PAMM
                           select srv).FirstOrDefault();
            if (service == null)
            {
                Logger.ErrorFormat("InvestOrWithdrawFromPamm(acc={0}) - счет не указан как ПАММ", accountId);
                return RequestStatus.BadRequest;
            }

            return RequestStatus.OK;
        }
        private RequestStatus CheckShareAndUpdateSubscriberWallet(List<AccountShare> shares, PLATFORM_USER subscriber,
            ACCOUNT account, Dictionary<string, QuoteData> quotes, out decimal amountInAccountCurx)
        {
            amountInAccountCurx = 0;
            var subscribersShare = shares.FirstOrDefault(s => s.UserId == subscriber.ID);
            if (subscribersShare == null && withdrawNotInvest)
            {
                Logger.ErrorFormat("CheckShareAndUpdateSubscriberWallet(acc={0}, user={1}) - у пользователя нет вклада",
                                   accountId, subscriber.Login);
                return RequestStatus.BadRequest;
            }

            // посчитать сумму вложения в валюте целевого счета
            var ownerWallet = ctx.WALLET.First(w => w.User == subscriber.ID);

            string errorStr;
            var calculatedAmountInAccountCurx = DalSpot.Instance.ConvertSourceCurrencyToTargetCurrency(account.Currency,
                ownerWallet.Currency, (double) sumInWalletCurrency, quotes, out errorStr);
            if (!calculatedAmountInAccountCurx.HasValue)
            {
                Logger.Error("CheckShareAndUpdateSubscriberWallet - невозможно перевести " + account.Currency + " в " +
                             ownerWallet.Currency +
                             ": " + errorStr);
                return RequestStatus.ServerError;
            }
            amountInAccountCurx = calculatedAmountInAccountCurx.Value;

            // завести денег в ПАММ - списать с кошелька подписчика
            if (!withdrawNotInvest)
            {
                // списать деньги с кошелька подписчика
                if (ownerWallet.Balance < sumInWalletCurrency)
                {
                    Logger.ErrorFormat(
                        "CheckShareAndUpdateSubscriberWallet({0} на счет {1}) - сумма инвестирования {2} больше баланса кошелька ({3})",
                        login, accountId, sumInWalletCurrency, ownerWallet.Balance);
                    return RequestStatus.MarginOrLeverageExceeded;
                }
                ownerWallet.Balance -= sumInWalletCurrency;
            }
            else
            {
                // вывести все?
                if (withdrawAll)
                {
                    amountInAccountCurx = subscribersShare.ShareMoney;

                    string errorDepoAmountStr;
                    var calculatedAmountInWalletCurx = DalSpot.Instance.ConvertSourceCurrencyToTargetCurrency(
                        ownerWallet.Currency, account.Currency, (double) amountInAccountCurx, quotes, out errorDepoAmountStr);
                    if (!calculatedAmountInWalletCurx.HasValue)
                    {
                        Logger.Error("CheckShareAndUpdateSubscriberWallet - (расчет суммы вывода) невозможно перевести " + account.Currency + " в " +
                                     ownerWallet.Currency + ": " + errorDepoAmountStr);
                        return RequestStatus.ServerError;
                    }
                    sumInWalletCurrency = calculatedAmountInWalletCurx.Value;
                }
                else
                {
                    // не превышает ли выводимая сумма долю вкладчика?
                    if (calculatedAmountInAccountCurx > subscribersShare.ShareMoney)
                    {
                        Logger.ErrorFormat("CheckShareAndUpdateSubscriberWallet({0} на счет {1}) - сумма вывода {2} больше доли пайщика ({3})",
                                           login, accountId, calculatedAmountInAccountCurx, subscribersShare.ShareMoney);
                        return RequestStatus.BadRequest;
                    }

                    subscribersShare.ShareMoney -= calculatedAmountInAccountCurx.Value;
                    // выводится, фактически, вся сумма?
                    if (subscribersShare.ShareMoney < MinInvestAmountOnPamm)
                    {
                        Logger.InfoFormat("CheckShareAndUpdateSubscriberWallet({0} на счет {1}) - сумма вывода {2} примерно равна доле пайщика ({3}), выводится все",
                            login, accountId, calculatedAmountInAccountCurx, subscribersShare.ShareMoney);
                        withdrawAll = true;
                        subscribersShare.ShareMoney = 0;
                    }
                }

                ownerWallet.Balance += sumInWalletCurrency;
            }
            return RequestStatus.OK;
        }
Example #13
0
 public static PLATFORM_USER UndecoratePlatformUser(PlatformUser user)
 {
     var us = new PLATFORM_USER
     {
         ID = user.ID,
         Title = user.Title,
         Login = user.Login,
         Name = user.Name,
         Password = user.Password,
         Patronym = user.Patronym,
         Phone1 = user.Phone1,
         Phone2 = user.Phone2,
         RoleMask = (int)user.RoleMask,
         Surname = user.Surname,
         Description = user.Description,
         Email = user.Email,
         RegistrationDate = user.RegistrationDate
     };
     return us;
 }
Example #14
0
 public void MakeNewlyRegisteredAccountSignaller(TradeSharpConnection ctx,
     PLATFORM_USER user, ACCOUNT account)
 {
     try
     {
         ctx.SERVICE.Add(new SERVICE
             {
                 AccountId = account.ID,
                 ServiceType = (int) PaidServiceType.PAMM,
                 Currency = account.Currency,
                 FixedPrice = 1,
                 Comment = "Сигналы " + LinqToEntity.DecoratePlatformUser(user).NameWithInitials,
                 User = user.ID
             });
     }
     catch (Exception ex)
     {
         Logger.ErrorFormat("Ошибка в MakeNewlyRegisteredAccountSignaller(login={0}, account={1}): {2}",
             user.Login, account.ID, ex);
     }
 }