예제 #1
0
        public void GetBalance_ShouldUnauthorizedThrowException_IfNoApiKeyIsGiven()
        {
            var         bittrex = new Bittrex();
            Func <Task> action  = async() => { var _ = await bittrex.GetBalance(DefaultCurrency); };

            action.ShouldThrow <UnauthorizedException>();
        }
예제 #2
0
        public void GetBalance_ShouldNotThrowException()
        {
            var         bittrex = new Bittrex(DefaultApiKey, DefaultApiSecret);
            Func <Task> action  = async() => { var _ = await bittrex.GetBalance(DefaultCurrency); };

            action.ShouldNotThrow();
        }
예제 #3
0
        public async Task <BaseTypes.CurrencyBalance> GetBalance(string Currency, InvokePrint Print)
        {
            try
            {
                var cbal = await bittrex.GetBalance(Currency);

                BaseTypes.CurrencyBalance balance = new BaseTypes.CurrencyBalance
                {
                    Currency  = cbal.Currency,
                    Balance   = cbal.Balance,
                    Available = cbal.Available
                };
                return(balance);
            }
            catch (Exception ex)
            {
                System.Media.SystemSounds.Beep.Play();
                Print(String.Format("Ошибка BittrexApi GetBalance: {0}\r\nCurrency: {1}.", ex.Message, Currency));
                return(null);
            }
        }
예제 #4
0
        public async Task <ApiStatus> CheckKeySecret()
        {
            var task = bittrex.GetBalance("BTC");
            var res  = await Task.WhenAny(task, Task.Delay(10000));

            if (res == task)
            {
                // Task completed within time.
                if (task.Result.Message.CompareTo("APIKEY_INVALID") == 0 ||
                    task.Result.Message.CompareTo("INVALID_SIGNATURE") == 0)
                {
                    return(ApiStatus.FALSE);
                }
                else
                {
                    return(ApiStatus.TRUE);
                }
            }
            else
            {
                // Task timed out
                return(ApiStatus.CONNECTION_TIMEOUT);
            }
        }
예제 #5
0
        /// <summary>
        ///     Function returning the balance of one currency in the portfolio
        ///     <paramref name="currency"/> have to be in <see cref="MainCurrency"/>
        /// </summary>
        /// <param name="currency">the name of the cryptocurrency.</param>
        public double GetBalance(string currency)
        {
            BittrexSharp.Domain.CurrencyBalance one_balance = my_bittrex.GetBalance(currency).Result.Result;

            return((double)one_balance.Available);
        }