示例#1
0
        /// <summary>
        /// Gets the address to deposit to and applicable details.
        /// </summary>
        /// <param name="symbol">Symbol to get address for</param>
        /// <param name="forceRegenerate">(ignored) Binance does not provide the ability to generate new addresses</param>
        /// <returns>
        /// Deposit address details (including memo if applicable, such as XRP)
        /// </returns>
        public override ExchangeDepositDetails GetDepositAddress(string symbol, bool forceRegenerate = false)
        {
            /*
             * TODO: Binance does not offer a "regenerate" option in the API, but a second IOTA deposit to the same address will not be credited
             * How does Binance handle GetDepositAddress for IOTA after it's been used once?
             * Need to test calling this API after depositing IOTA.
             */

            Dictionary <string, object> payload = GetNoncePayload();

            payload["asset"] = NormalizeSymbol(symbol);

            JToken response = MakeJsonRequest <JToken>("/depositAddress.html", WithdrawalUrlPrivate, payload);

            CheckError(response);

            ExchangeDepositDetails depositDetails = new ExchangeDepositDetails
            {
                Symbol  = response["asset"].ToStringInvariant(),
                Address = response["address"].ToStringInvariant(),
                Memo    = response["addressTag"].ToStringInvariant()
            };

            if (response["success"] == null || !response["success"].ConvertInvariant <bool>())
            {
                throw new APIException(response["msg"].ToStringInvariant());
            }

            return(depositDetails);
        }
示例#2
0
        protected override async Task <ExchangeDepositDetails> OnGetDepositAddressAsync(string symbol, bool forceRegenerate = false)
        {
            symbol = NormalizeSymbol(symbol);
            JToken token = await MakeJsonRequestAsync <JToken>("/payment/get/address?" + "currency=" + symbol, BaseUrl, GetNoncePayload(), "GET");

            token = CheckError(token);
            if (token != null && token.HasValues && token["currency"].Value <string>() == symbol && token["wallet"].Value <string>() != null)
            {
                ExchangeDepositDetails address = new ExchangeDepositDetails()
                {
                    Symbol = symbol
                };
                if (token["wallet"].Value <string>().Contains("::"))
                {
                    // address tags are separated with a '::'
                    var split = token["wallet"].Value <string>().Replace("::", ":").Split(':');
                    address.Address    = split[0];
                    address.AddressTag = split[1];
                }
                else
                {
                    address.Address = token["wallet"].ToStringInvariant();
                }
                return(address);
            }
            return(null);
        }
示例#3
0
        protected override async Task <ExchangeDepositDetails> OnGetDepositAddressAsync(string currency, bool forceRegenerate = false)
        {
            var payload = await GetNoncePayloadAsync();

            JArray array = await MakeJsonRequestAsync <JArray>("/payment-methods", null, await GetNoncePayloadAsync());

            if (array != null)
            {
                var rc = array.Where(t => t["currency"].ToStringInvariant() == currency).FirstOrDefault();
                payload = await GetNoncePayloadAsync();

                payload["currency"] = currency;
                payload["method"]   = rc["id"].ToStringInvariant();

                JToken token = await MakeJsonRequestAsync <JToken>("/deposits/make", null, payload, "POST");

                ExchangeDepositDetails deposit = new ExchangeDepositDetails()
                {
                    Currency   = currency,
                    Address    = token["address"].ToStringInvariant(),
                    AddressTag = token["tag"].ToStringInvariant()
                };
                return(deposit);
            }
            return(null);
        }
        protected override async Task <ExchangeDepositDetails> OnGetDepositAddressAsync(string symbol, bool forceRegenerate = false)
        {
            symbol = NormalizeSymbol(symbol);
            var    payload = GetNoncePayload();
            JArray array   = MakeJsonRequest <JArray>("/payment-methods", null, GetNoncePayload(), "GET");

            if (array != null)
            {
                var rc = array.Where(t => t.Value <string>("currency") == symbol).FirstOrDefault();
                payload             = GetNoncePayload();
                payload["currency"] = NormalizeSymbol(symbol);
                payload["method"]   = rc.Value <string>("id");

                JToken token = await MakeJsonRequestAsync <JToken>("/deposits/make", null, payload, "POST");

                ExchangeDepositDetails deposit = new ExchangeDepositDetails()
                {
                    Symbol     = symbol,
                    Address    = token["address"].ToStringInvariant(),
                    AddressTag = token["tag"].ToStringInvariant()
                };
                return(deposit);
            }
            return(null);
        }
        protected override async Task <ExchangeDepositDetails> OnGetDepositAddressAsync(string currency, bool forceRegenerate = false)
        {
            JToken token = await MakeJsonRequestAsync <JToken>("/payment/get/address?" + "currency=" + currency.UrlEncode(), BaseUrl, await GetNoncePayloadAsync());

            if (token != null && token.HasValues && token["currency"].ToStringInvariant() == currency && token["wallet"].ToStringInvariant().Length != 0)
            {
                ExchangeDepositDetails address = new ExchangeDepositDetails()
                {
                    Currency = currency
                };
                if (token["wallet"].ToStringInvariant().Contains("::"))
                {
                    // address tags are separated with a '::'
                    var split = token["wallet"].ToStringInvariant().Replace("::", ":").Split(':');
                    address.Address    = split[0];
                    address.AddressTag = split[1];
                }
                else
                {
                    address.Address = token["wallet"].ToStringInvariant();
                }
                return(address);
            }
            return(null);
        }
示例#6
0
        /// <summary>
        /// Gets the address to deposit to and applicable details.
        /// </summary>
        /// <param name="symbol">Symbol to get address for</param>
        /// <param name="forceRegenerate">(ignored) Binance does not provide the ability to generate new addresses</param>
        /// <returns>
        /// Deposit address details (including tag if applicable, such as XRP)
        /// </returns>
        protected override async Task <ExchangeDepositDetails> OnGetDepositAddressAsync(string symbol, bool forceRegenerate = false)
        {
            /*
             * TODO: Binance does not offer a "regenerate" option in the API, but a second IOTA deposit to the same address will not be credited
             * How does Binance handle GetDepositAddress for IOTA after it's been used once?
             * Need to test calling this API after depositing IOTA.
             */

            Dictionary <string, object> payload = GetNoncePayload();

            payload["asset"] = NormalizeSymbol(symbol);

            JToken response = await MakeJsonRequestAsync <JToken>("/depositAddress.html", WithdrawalUrlPrivate, payload);

            CheckError(response);

            ExchangeDepositDetails depositDetails = new ExchangeDepositDetails
            {
                Symbol     = response["asset"].ToStringInvariant(),
                Address    = response["address"].ToStringInvariant(),
                AddressTag = response["addressTag"].ToStringInvariant()
            };

            return(depositDetails);
        }
 protected override async Task<ExchangeDepositDetails> OnGetDepositAddressAsync(string currency, bool forceRegenerate = false)
 {
     ExchangeDepositDetails deposit = new ExchangeDepositDetails() { Currency = currency };
     JToken token = await MakeJsonRequestAsync<JToken>("/payment/address/" + currency, null, await GetNoncePayloadAsync());
     if (token != null)
     {
         deposit.Address = token["address"].ToStringInvariant();
         if (deposit.Address.StartsWith("bitcoincash:"))
         {
             deposit.Address = deposit.Address.Replace("bitcoincash:", string.Empty);  // don't know why they do this for bitcoincash
         }
         deposit.AddressTag = token["wallet"].ToStringInvariant();
     }
     return deposit;
 }
        /// <summary>
        /// Create a deposit address
        /// </summary>
        /// <param name="currency">Currency to create an address for</param>
        /// <param name="currencies">Lookup of existing currencies</param>
        /// <returns>ExchangeDepositDetails with an address or a BaseAddress/AddressTag pair.</returns>
        private async Task <ExchangeDepositDetails> CreateDepositAddress(string currency, IReadOnlyDictionary <string, ExchangeCurrency> currencies)
        {
            JToken result = await MakePrivateAPIRequestAsync("generateNewAddress", new object[] { "currency", currency });

            var details = new ExchangeDepositDetails
            {
                Currency = currency,
            };

            if (!TryPopulateAddressAndTag(currency, currencies, details, result["response"].ToStringInvariant()))
            {
                return(null);
            }

            return(details);
        }
        private async Task <bool> TryFetchExistingAddresses(string currency, IReadOnlyDictionary <string, ExchangeCurrency> currencies, Dictionary <string, ExchangeDepositDetails> depositAddresses)
        {
            JToken result = await MakePrivateAPIRequestAsync("returnDepositAddresses");

            foreach (JToken jToken in result)
            {
                var token   = (JProperty)jToken;
                var details = new ExchangeDepositDetails {
                    Currency = token.Name
                };

                if (!TryPopulateAddressAndTag(currency, currencies, details, token.Value.ToStringInvariant()))
                {
                    return(false);
                }

                depositAddresses[details.Currency] = details;
            }

            return(true);
        }
示例#10
0
        /// <summary>
        /// Gets the address to deposit to and applicable details.
        /// If one does not exist, the call will fail and return ADDRESS_GENERATING until one is available.
        /// </summary>
        /// <param name="symbol">Symbol to get address for.</param>
        /// <param name="forceRegenerate">(ignored) Bittrex does not support regenerating deposit addresses.</param>
        /// <returns>
        /// Deposit address details (including memo if applicable, such as with XRP)
        /// </returns>
        public override ExchangeDepositDetails GetDepositAddress(string symbol, bool forceRegenerate = false)
        {
            IReadOnlyDictionary <string, ExchangeCurrency> updatedCurrencies = this.GetCurrencies();

            string url      = "/account/getdepositaddress?currency=" + NormalizeSymbol(symbol);
            JToken response = MakeJsonRequest <JToken>(url, null, GetNoncePayload());
            JToken result   = CheckError(response);

            // NOTE API 1.1 does not include the the static wallet address for currencies with memos such as XRP & NXT (API 2.0 does!)
            // We are getting the static addresses via the GetCurrencies() api.
            ExchangeDepositDetails depositDetails = new ExchangeDepositDetails
            {
                Symbol = result["Currency"].ToStringInvariant(),
            };

            if (!updatedCurrencies.TryGetValue(depositDetails.Symbol, out ExchangeCurrency coin))
            {
                Console.WriteLine($"Unable to find {depositDetails.Symbol} in existing list of coins.");
                return(null);
            }

            if (this.TwoFieldDepositCoinTypes.Contains(coin.CoinType))
            {
                depositDetails.Address = coin.BaseAddress;
                depositDetails.Memo    = result["Address"].ToStringInvariant();
            }
            else if (this.OneFieldDepositCoinTypes.Contains(coin.CoinType))
            {
                depositDetails.Address = result["Address"].ToStringInvariant();
            }
            else
            {
                Console.WriteLine($"ExchangeBittrexAPI: Unknown coin type {coin.CoinType} must be registered as requiring one or two fields. Add coin type to One/TwoFieldDepositCoinTypes and make this call again.");
                return(null);
            }

            return(depositDetails);
        }
        private static bool TryPopulateAddressAndTag(string currency, IReadOnlyDictionary <string, ExchangeCurrency> currencies, ExchangeDepositDetails details, string address)
        {
            if (currencies.TryGetValue(currency, out ExchangeCurrency coin))
            {
                if (!string.IsNullOrWhiteSpace(coin.BaseAddress))
                {
                    details.Address    = coin.BaseAddress;
                    details.AddressTag = address;
                }
                else
                {
                    details.Address = address;
                }

                return(true);
            }

            // Cannot find currency in master list.
            // Stay safe and don't return a possibly half-baked deposit address missing a tag
            return(false);
        }