public MerchantSupportReceiptWalletDTO GetSupportReceiptByFiatCurrency(Guid accountId, string fiatCurrency, int coinId)
        {
            var account = new MerchantAccountDAC().GetById(accountId);
            var crypto  = new CryptocurrencyDAC().GetById(coinId);

            var marketPriceComponent = new MarketPriceComponent();
            var marketPrice          = marketPriceComponent.GetMarketPrice(fiatCurrency, crypto.Code);

            var supportReceiptWallets = new MerchantWalletDAC().SupportReceiptList(accountId);
            var singleSupportWallet   = supportReceiptWallets.FirstOrDefault(e => e.CryptoId == crypto.Id);

            if (singleSupportWallet == null)
            {
                return(new MerchantSupportReceiptWalletDTO());
            }

            return(new MerchantSupportReceiptWalletDTO
            {
                WalletId = singleSupportWallet.Id,
                CryptoId = crypto.Id,
                CryptoStatus = crypto.Status,
                CryptoCode = crypto.Code,
                CryptoName = crypto.Name,
                IconURL = crypto.IconURL,
                DecimalPlace = crypto.DecimalPlace,
                Markup = account.Markup,
                MarketPrice = marketPrice?.Price.ToString("F"),
                CryptoEnable = crypto.Enable
            });
        }
        private decimal GetExchangeRate(int countryId, string fiatCurrency, string coinCode)
        {
            var agent = new MarketPriceComponent();
            var price = agent.GetMarketPrice(fiatCurrency, coinCode);

            return(price?.Price ?? 0);
        }
        private decimal GetExchangeRate(int countryId, string fiatCurrency, Cryptocurrency crypto)
        {
            var price = new MarketPriceComponent().GetMarketPrice(fiatCurrency, crypto.Code);

            if (price == null)
            {
                return(0M);
            }
            return(price.Price);
        }
        private MerchantWithdrawalMasterSettingDTO GetMerchantWithdrawalMasterSettingWithCrypto(Cryptocurrency crypto, int level)
        {
            var withdrawMasterSetting = GetMerchantWithdrawalMasterSetting();
            var marketPriceComponent  = new MarketPriceComponent();
            var mpInfo = marketPriceComponent.GetMarketPrice("USD", crypto.Code);

            if (mpInfo == null)
            {
                throw new CommonException(ReasonCode.NOT_SUPORT_WITHDRAWAL, Resources.支持的币种);
            }

            var exchangeRate = mpInfo.Price;

            switch (level)
            {
            case 1:
                withdrawMasterSetting.PerTxLimit    = (withdrawMasterSetting.PerTxLimit1 / exchangeRate).ToSpecificDecimal(crypto.DecimalPlace);
                withdrawMasterSetting.PerDayLimit   = (withdrawMasterSetting.PerDayLimit1 / exchangeRate).ToSpecificDecimal(crypto.DecimalPlace);
                withdrawMasterSetting.PerMonthLimit = (withdrawMasterSetting.PerMonthLimit1 / exchangeRate).ToSpecificDecimal(crypto.DecimalPlace);
                break;

            case 2:
                withdrawMasterSetting.PerTxLimit    = (withdrawMasterSetting.PerTxLimit2 / exchangeRate).ToSpecificDecimal(crypto.DecimalPlace);
                withdrawMasterSetting.PerDayLimit   = (withdrawMasterSetting.PerDayLimit2 / exchangeRate).ToSpecificDecimal(crypto.DecimalPlace);
                withdrawMasterSetting.PerMonthLimit = (withdrawMasterSetting.PerMonthLimit2 / exchangeRate).ToSpecificDecimal(crypto.DecimalPlace);
                break;

            default:
                withdrawMasterSetting.PerTxLimit    = (withdrawMasterSetting.PerTxLimit / exchangeRate).ToSpecificDecimal(crypto.DecimalPlace);
                withdrawMasterSetting.PerDayLimit   = (withdrawMasterSetting.PerDayLimit / exchangeRate).ToSpecificDecimal(crypto.DecimalPlace);
                withdrawMasterSetting.PerMonthLimit = (withdrawMasterSetting.PerMonthLimit / exchangeRate).ToSpecificDecimal(crypto.DecimalPlace);
                break;
            }
            //未设置 默认最小值
            if (withdrawMasterSetting.ToOutsideMinAmount <= 0)
            {
                withdrawMasterSetting.ToOutsideMinAmount = 1 / (decimal)Math.Pow(10, crypto.DecimalPlace);
            }
            else
            {
                withdrawMasterSetting.ToOutsideMinAmount = (withdrawMasterSetting.ToOutsideMinAmount / exchangeRate).ToSpecificDecimal(crypto.DecimalPlace);
            }

            //未设置 默认最小值
            if (withdrawMasterSetting.ToUserMinAmount <= 0)
            {
                withdrawMasterSetting.ToUserMinAmount = 1 / (decimal)Math.Pow(10, crypto.DecimalPlace);
            }
            else
            {
                withdrawMasterSetting.ToUserMinAmount = (withdrawMasterSetting.ToUserMinAmount / exchangeRate).ToSpecificDecimal(crypto.DecimalPlace);
            }

            return(withdrawMasterSetting);
        }
        public List <MarketPriceInfo> GetAllMarketPrice(int countryId, string fiatCurrency)
        {
            string cryptoPriceKey = "Setting:CryptoCurrency:MarketPrice" + fiatCurrency;

            if (RedisHelper.KeyExists(cryptoPriceKey))
            {
                List <MarketPriceInfo> infoList = JsonConvert.DeserializeObject <List <MarketPriceInfo> >(RedisHelper.StringGet(cryptoPriceKey));
                return(infoList);
            }

            var agent  = new MarketPriceComponent();
            var result = agent.GetMarketPrice(fiatCurrency);

            if (result == null)
            {
                throw new FiiiFinanceException(10000, "");
            }

            RedisHelper.StringSet(cryptoPriceKey, JsonConvert.SerializeObject(result), new TimeSpan(0, Constant.CACHE_CRYPTO_PRICE_TIME, 0));

            return(result);
        }
        public MarketPriceInfo GetMarketPrice(int countryId, string fiatCurrency, string cryptoCode)
        {
            string cryptoPriceKey = "Setting:CryptoCurrency:MarketPrice" + fiatCurrency;

            if (RedisHelper.KeyExists(cryptoPriceKey))
            {
                List <MarketPriceInfo> infoList = JsonConvert.DeserializeObject <List <MarketPriceInfo> >(RedisHelper.StringGet(cryptoPriceKey));
                var priceInfo = infoList.FirstOrDefault(t => t.CryptoName == cryptoCode);

                if (priceInfo == null)
                {
                    var agent = new MarketPriceComponent();
                    return(agent.GetMarketPrice(fiatCurrency, cryptoCode));
                }

                return(priceInfo);
            }

            var allPriceInfo = GetAllMarketPrice(countryId, fiatCurrency);

            return(allPriceInfo.First(t => t.CryptoName == cryptoCode));
        }
        public MerchantTotalAssetsDTO GetMerchantTotalAssets(Guid accountId)
        {
            var account    = new MerchantAccountDAC().GetById(accountId);
            var walletList = new MerchantWalletDAC().GetByAccountId(accountId);

            decimal totalPrice = 0m;

            if (walletList.Count > 0)
            {
                var cryptoList = new CryptocurrencyDAC().GetAllActived();
                if (account.POSId.HasValue)
                {
                    var pos = new POSDAC().GetById(account.POSId.Value);
                    if (!pos.IsWhiteLabel)
                    {
                        cryptoList.RemoveAll(t => t.IsWhiteLabel == 1);
                    }
                }

                var marketPriceList = new MarketPriceComponent().GetMarketPrice(account.FiatCurrency);

                totalPrice = walletList.Sum(e =>
                {
                    var coin        = cryptoList.FirstOrDefault(c => c.Id == e.CryptoId);
                    var marketPrice = marketPriceList.FirstOrDefault(m => m.CryptoName == coin?.Code);

                    return((e.Balance + e.FrozenBalance) * (marketPrice?.Price ?? 0));
                });
            }

            return(new MerchantTotalAssetsDTO
            {
                FiatCurrency = account.FiatCurrency,
                Amount = totalPrice.ToString("N", CultureInfo.InvariantCulture),
                IsAllowWithDrawal = account.IsAllowWithdrawal
            });
        }
        public List <MarketPriceInfo> GetMarketPrice(int countryId, string fiatCurrency)
        {
            var marketPriceComponent = new MarketPriceComponent();

            return(marketPriceComponent.GetMarketPrice(fiatCurrency));
        }
Exemple #9
0
        private decimal GetExchangeRate(string fiatCurrency, Cryptocurrency crypto)
        {
            var price = new MarketPriceComponent().GetMarketPrice(fiatCurrency, crypto.Code);

            return(price?.Price ?? 0);
        }