Esempio n. 1
0
 private CryptocurrencyWithdrawalAddress(int userId, string address, CryptocurrencyType cryptocurrenyType)
 {
     this.CryptocurrencyCode = cryptocurrenyType.ToString();
     this.UserId             = userId;
     this.Address            = address;
     this.DateAdded          = AppSettings.ServerTime;
     this.IsNew = true;
 }
Esempio n. 2
0
        private void ValidateWithdrawal(Member user, string userAddress, decimal amount, WithdrawalSourceBalance withdrawalSource)
        {
            if (!WithdrawalEnabled)
            {
                throw new MsgException("Withdrawal is currently disabled by the administrator");
            }

            if (CryptocurrencyApi.IsAdministratorAddress(userAddress, WithdrawalApiProcessor))
            {
                throw new MsgException("You can't withdraw to administrator-generated address.");
            }

            Money  amountInCorrectType = Money.Zero;
            string errorMessage        = String.Empty;

            //General validation
            PayoutManager.ValidatePayoutNotConnectedToAmount(user);

            //Amounts & Balances
            if (withdrawalSource == WithdrawalSourceBalance.MainBalance)
            {
                amountInCorrectType = new Money(amount);

                //Check the balance
                if (amountInCorrectType > user.MainBalance)
                {
                    throw new MsgException(L1.NOTENOUGHFUNDS);
                }

                PayoutManager.ValidatePayout(user, amountInCorrectType);
                PayoutManager.CheckMaxPayout(CryptocurrencyTypeHelper.ConvertToPaymentProcessor(CryptocurrencyType), user, amountInCorrectType);
            }
            else //Wallets
            {
                amountInCorrectType = new CryptocurrencyMoney(this.Type, amount);

                //Check the balance
                if (amountInCorrectType > user.GetCryptocurrencyBalance(CryptocurrencyType))
                {
                    throw new MsgException(string.Format(U6012.NOFUNDSINWALLET, CryptocurrencyType.ToString()));
                }
            }

            //Check MIN withdrawal
            if (amountInCorrectType < GetMinimumWithdrawalAmount(user, withdrawalSource))
            {
                throw new MsgException(U5003.WITHDRAWALMUSTBEHIGHER);
            }

            //Check MAX withdrawals
            if (amountInCorrectType > GetMaximumWithdrawalAmount(user, withdrawalSource, out errorMessage))
            {
                throw new MsgException(errorMessage);
            }
        }
 public CryptocurrencyWithdrawRequest(int userId, string address, Money amount, Money amountWithFee, CryptocurrencyType cryptocurrency, WithdrawalSourceBalance sourceBalance)
 {
     this.CryptocurrencyCode      = cryptocurrency.ToString();
     this.UserId                  = userId;
     this.Address                 = address;
     this.RequestDate             = AppSettings.ServerTime;
     this.Status                  = WithdrawRequestStatus.Pending;
     this.Amount                  = amount;
     this.AmountWithFee           = amountWithFee;
     this.WithdrawalSourceBalance = sourceBalance;
     this.CryptocurrencyObject    = CryptocurrencyFactory.Get(Cryptocurrency);
 }
    public override void TryWithDrawCryptocurrencyFromWallet(decimal amountInCryptocurrency, string userAddress, CryptocurrencyType cryptocurrencyType)
    {
        string cmd = "create_withdrawal";

        using (WebClient client = new WebClient())
        {
            var values = new NameValueCollection();
            values["version"]      = "1";
            values["key"]          = AppSettings.Cryptocurrencies.CoinPaymentsApiKey;
            values["format"]       = "json";
            values["cmd"]          = cmd;
            values["amount"]       = amountInCryptocurrency.ToString();
            values["currency"]     = cryptocurrencyType.ToString();
            values["address"]      = userAddress;
            values["auto_confirm"] = "1";

            string SpecialParams = String.Format("{0}&amount={1}&currency={3}&address={2}&auto_confirm=1", cmd, amountInCryptocurrency.ToString(), userAddress,
                                                 cryptocurrencyType.ToString());

            client.Headers.Add("HMAC", GetSHA512HMAC(SpecialParams));

            try
            {
                var     response       = client.UploadValues(baseUrl, values);
                string  responseString = Encoding.Default.GetString(response);
                JObject o = JObject.Parse(responseString);

                if (o["error"].ToString() != "ok")
                {
                    throw new MsgException(o["error"].ToString());
                }
            }
            catch (Exception ex)
            {
                throw new MsgException(ex.Message);
            }
        }
    }
Esempio n. 5
0
        public async Task <Pro.Model.Cryptocurrency.ListingsData> CryptocurrencyListingsHistoricalAsync(
            DateTime timestamp,
            int?start              = 1,
            int?limit              = 100,
            FiatCurrency convert   = FiatCurrency.USD,
            SortBy sort            = SortBy.market_cap,
            SortDirection sort_dir = SortDirection.desc,
            CryptocurrencyType cryptocurrency_type = CryptocurrencyType.all
            )
        {
            HttpClient _httpClient = new HttpClient {
                BaseAddress = new Uri(Pro.Config.Cryptocurrency.CoinMarketCapProApiUrl)
            };

            _httpClient.DefaultRequestHeaders.Add("X-CMC_PRO_API_KEY", this.ProApiKey);

            var url = QueryStringService.AppendQueryString(Pro.Config.Cryptocurrency.CryptocurrencyListingsHistorical, new Dictionary <string, string>
            {
                { "timestamp", timestamp.ToUnixTimeSeconds().ToString() },
                { "start", start.HasValue && start.Value >= 1 ? start.Value.ToString() : null },
                { "limit", limit.HasValue && limit.Value >= 1 ? limit.Value.ToString() : null },
                { "convert", convert.ToString() },
                { "sort", sort.ToString() },
                { "sort_dir", sort_dir.ToString() },
                { "cryptocurrency_type", cryptocurrency_type.ToString() },
            });
            var response = await _httpClient.GetAsync(url);

            Pro.Model.Cryptocurrency.ListingsData data = await JsonParserService.ParseResponse <Pro.Model.Cryptocurrency.ListingsData>(response);

            if (data == null)
            {
                data = new Pro.Model.Cryptocurrency.ListingsData
                {
                    Data   = null,
                    Status = new Status {
                        ErrorCode = int.MinValue
                    },
                    Success = false
                };
            }
            data.Success = data.Status.ErrorCode == 0;

            // Add to Status List
            this.statusList.Add(data.Status);

            return(data);
        }
Esempio n. 6
0
        private static UserCryptocurrencyBalance GetObject(int userId, CryptocurrencyType code)
        {
            var result = TableHelper.GetListFromRawQuery<UserCryptocurrencyBalance>
                (String.Format("SELECT * FROM UserCryptocurrencyBalances WHERE UserId = {0} AND CurrencyCode = '{1}'", userId, code));

            if (result.Count > 0)
            {
                result[0].Balance.cryptocurrencyType = code; //CryptocurrenyMoney class fix
                return result[0];
            }

            UserCryptocurrencyBalance userCryptocurrencyBalance = new UserCryptocurrencyBalance();
            userCryptocurrencyBalance.Balance = new CryptocurrencyMoney(code, 0);
            userCryptocurrencyBalance.CurrencyCode = code.ToString();
            userCryptocurrencyBalance.UserId = userId;
            userCryptocurrencyBalance.Save();

            return userCryptocurrencyBalance;
        }
Esempio n. 7
0
 public static string ToValue(this CryptocurrencyType value)
 {
     return(value.ToString().ToLower());
 }
    public override void TryWithDrawCryptocurrencyFromWallet(decimal amountInCryptocurrency, string userAddress, CryptocurrencyType cryptocurrencyType)
    {
        CoinbaseApi api     = new CoinbaseApi(AppSettings.Cryptocurrencies.CoinbaseAPIKey, AppSettings.Cryptocurrencies.CoinbaseAPISecret, false);
        var         options = new { type = "send", to = userAddress, amount = amountInCryptocurrency, currency = cryptocurrencyType.ToString() };

        var response = api.SendRequest(String.Format("/accounts/{0}/transactions", GetAccountId(api)),
                                       options, RestSharp.Method.POST);

        if (response.Errors != null)
        {
            throw new MsgException(response.Errors[0].Message);
        }
    }