Пример #1
0
        void ValidateExchangeParams(BrokerExchangeParams model)
        {
            if (!string.IsNullOrWhiteSpace(model.FiatCurrency))
            {
                if (model.BuyFiatAmount <= 0 && model.SellFiatAmount <= 0)
                {
                    throw new ApiException(ErrorCode.FiatAmountEmpty);
                }

                if (model.SellFiatAmount > 0 && model.BuyFiatAmount > 0)
                {
                    throw new ApiException(ErrorCode.OnlyOneAmountAllowed);
                }

                if (model.SellAmount > 0 || model.BuyAmount > 0)
                {
                    throw new ApiException(ErrorCode.OnlyOneAmountAllowed);
                }
            }
            else
            {
                if (model.SellAmount > 0 && model.BuyAmount > 0)
                {
                    throw new ApiException(ErrorCode.OnlyOneAmountAllowed);
                }

                if (model.SellAmount <= 0 && model.BuyAmount <= 0)
                {
                    throw new ApiException(ErrorCode.InvalidAmount);
                }
            }

            if (string.IsNullOrWhiteSpace(model.SellCurrency))
            {
                throw new ApiException(ErrorCode.SellCurrencyEmpty);
            }

            if (!_rateCache.IsSupported(model.SellCurrency))
            {
                throw new ApiException(ErrorCode.SellCurrencyNotSupported, model.SellCurrency);
            }

            if (string.IsNullOrWhiteSpace(model.BuyCurrency))
            {
                throw new ApiException(ErrorCode.BuyCurrencyEmpty);
            }

            if (!((model.BuyCurrency == "GRFT" && model.SellCurrency == "BTC") ||
                  (model.BuyCurrency == "GRFT" && model.SellCurrency == "ETH") ||
                  (model.BuyCurrency == "USDT" && model.SellCurrency == "GRFT")))
            {
                throw new ApiException(ErrorCode.CurrencyPairNotSupported, $"{model.SellCurrency}->{model.BuyCurrency}");
            }

            if (string.IsNullOrWhiteSpace(model.WalletAddress))
            {
                throw new ApiException(ErrorCode.WalletEmpty);
            }
        }
Пример #2
0
        void ValidateSaleParams(BrokerSaleParams model)
        {
            if (model.SaleAmount <= 0)
            {
                throw new ApiException(ErrorCode.InvalidAmount);
            }

            if (string.IsNullOrWhiteSpace(model.SaleCurrency))
            {
                throw new ApiException(ErrorCode.SaleCurrencyEmpty);
            }

            if (model.SaleCurrency != "USD")
            {
                throw new ApiException(ErrorCode.SaleCurrencyNotSupported, model.SaleCurrency);
            }

            if (string.IsNullOrWhiteSpace(model.PayCurrency))
            {
                throw new ApiException(ErrorCode.PayCurrencyEmpty);
            }

            if (!_rateCache.IsSupported(model.PayCurrency))
            {
                throw new ApiException(ErrorCode.PayCurrencyNotSupported, model.PayCurrency);
            }

            if (model.ServiceProviderFee < 0 || model.ServiceProviderFee > _settings.MaxServiceProviderFee)
            {
                throw new ApiException(ErrorCode.InvalidServiceProviderFee);
            }

            if (model.ServiceProviderFee > 0 && string.IsNullOrWhiteSpace(model.ServiceProviderWallet))
            {
                throw new ApiException(ErrorCode.ServiceProviderWalletEmpty);
            }

            if (string.IsNullOrWhiteSpace(model.MerchantWallet))
            {
                throw new ApiException(ErrorCode.MerchantWalletEmpty);
            }
        }