Esempio n. 1
0
        public async Task <CreateWithdrawResponseModel> CreateWithdraw(string userId, CreateWithdrawModel model, bool isApi)
        {
            try
            {
                var estimatedPrice = await BalanceEstimationService.GetNZDPerCoin(model.CurrencyId).ConfigureAwait(false);

                var estimatedTotal     = model.Amount * estimatedPrice;
                var verificationResult = await UserVerificationReader.GetVerificationStatus(userId);

                if (verificationResult.Level != VerificationLevel.Legacy && (verificationResult.Current + estimatedTotal) > verificationResult.Limit)
                {
                    return new CreateWithdrawResponseModel {
                               Error = $"Withdraw exceeds daily limit of ${verificationResult.Limit:F2} NZD."
                    }
                }
                ;

                using (var tradeService = CreateService())
                {
                    var response = await tradeService.SubmitWithdrawAsync(new SubmitWithdrawRequest
                    {
                        Address        = model.Address,
                        Amount         = model.Amount,
                        CurrencyId     = model.CurrencyId,
                        TwoFactorToken = model.TwoFactorToken,
                        Type           = model.Type,
                        UserId         = new Guid(userId),
                        EstimatedPrice = estimatedTotal,
                        IsApi          = isApi
                    }).ConfigureAwait(false);

                    return(new CreateWithdrawResponseModel
                    {
                        Error = response.Error,
                        WithdrawId = response.WithdrawId
                                     //	Notifications = await ProcessNotifications(response),
                    });
                }
            }
            catch (Exception)
            {
                return(new CreateWithdrawResponseModel {
                    Error = "An Error occurred creating withdraw request, if problem persist please contact Cryptopia Support"
                });
            }
        }
Esempio n. 2
0
        public async Task <CreateTransferResponseModel> CreateTransfer(string userId, CreateTransferModel model, bool isApi)
        {
            try
            {
                var estimatedPrice = await BalanceEstimationService.GetNZDPerCoin(model.CurrencyId).ConfigureAwait(false);

                var estimatedTotal     = model.Amount * estimatedPrice;
                var verificationResult = await UserVerificationReader.GetVerificationStatus(userId);

                if (verificationResult.Level != VerificationLevel.Legacy && model.TransferType != TransferType.Paytopia && (verificationResult.Current + estimatedTotal) > verificationResult.Limit)
                {
                    return new CreateTransferResponseModel {
                               Error = $"Transfer exceeds daily limit of ${verificationResult.Limit:F2} NZD."
                    }
                }
                ;

                using (var tradeService = CreateService())
                {
                    var response = await tradeService.SubmitTransferAsync(new SubmitTransferRequest
                    {
                        Amount         = model.Amount,
                        CurrencyId     = model.CurrencyId,
                        UserId         = new Guid(userId),
                        UserTo         = new Guid(model.Receiver),
                        TransferType   = model.TransferType,
                        EstimatedPrice = estimatedTotal,
                        IsApi          = isApi
                    }).ConfigureAwait(false);

                    return(new CreateTransferResponseModel
                    {
                        Error = response.Error,
                        TransferId = response.TransferId,
                        Notifications = await ProcessTransferNotifications(response),
                    });
                }
            }
            catch (Exception)
            {
                return(new CreateTransferResponseModel {
                    Error = "An Error occurred placing transfer, if problem persist please contact Cryptopia Support"
                });
            }
        }
Esempio n. 3
0
        public async Task <UserBalanceModel> GetBalances(string userId, bool calculateEstimate)
        {
            try
            {
                var model       = new UserBalanceModel();
                var currentUser = new Guid(userId);
                using (var context = ExchangeDataContextFactory.CreateReadOnlyContext())
                {
                    var query = from currency in context.Currency
                                from balance in context.Balance.Where(b => b.UserId == currentUser && b.CurrencyId == currency.Id).DefaultIfEmpty()
                                //	from address in context.Address.Where(a => a.UserId == currentUser && a.CurrencyId == currency.Id).DefaultIfEmpty()
                                where currency.IsEnabled
                                orderby currency.Name
                                select new UserBalanceItemModel
                    {
                        //Address = address.AddressHash,
                        CurrencyId      = currency.Id,
                        HeldForTrades   = (decimal?)balance.HeldForTrades ?? 0,
                        PendingWithdraw = (decimal?)balance.PendingWithdraw ?? 0,
                        Name            = currency.Name,
                        Symbol          = currency.Symbol,
                        Status          = currency.Status,
                        ListingStatus   = currency.ListingStatus,
                        StatusMessage   = currency.StatusMessage,
                        Total           = (decimal?)balance.Total ?? 0,
                        Unconfirmed     = (decimal?)balance.Unconfirmed ?? 0,
                        IsFavorite      = (bool?)balance.IsFavorite ?? false,
                        CurrencyType    = currency.Type,
                        BaseAddress     = currency.BaseAddress
                    };

                    var balances = await query.ToListNoLockAsync().ConfigureAwait(false);

                    model.Balances = balances.DistinctBy(x => x.CurrencyId).ToList();
                }

                if (calculateEstimate)
                {
                    await model.Balances.ForEachAsync(async b => b.EstimatedBTC = await BalanceEstimationService.GetEstimatedBTC(b.Total, b.CurrencyId));

                    model.BTCEstimate    = model.Balances.Sum(x => x.EstimatedBTC);
                    model.BTCEstimateAlt = model.Balances.Where(x => x.CurrencyId != Constant.BITCOIN_ID).Sum(x => x.EstimatedBTC);

                    var verificationData = await UserVerificationReader.GetVerificationStatus(userId).ConfigureAwait(false);

                    model.HasWithdrawLimit = verificationData.Limit > 0;
                    model.WithdrawLimit    = verificationData.Limit;
                    model.WithdrawTotal    = verificationData.Current;
                }
                return(model);
            }
            catch (Exception)
            {
                return(new UserBalanceModel());
            }
        }