Exemplo n.º 1
0
 public bool OnGetBalances(AccountInfo account, string text) {
     if(string.IsNullOrEmpty(text))
         return false;
     JObject res = JsonConvert.DeserializeObject<JObject>(text);
     if(res.Value<bool>("success") == false) {
         Debug.WriteLine("OnGetBalances fails: " + res.Value<string>("message"));
         return false;
     }
     JArray balances = res.Value<JArray>("result");
     lock(account.Balances) {
         account.Balances.Clear();
         foreach(JObject obj in balances) {
             BitFinexAccountBalanceInfo item = new BitFinexAccountBalanceInfo(account);
             item.Currency = obj.Value<string>("Currency");
             //item.Balance = obj.Value<double>("Balance");
             item.Available = obj.Value<double>("Available");
             //item.Pending = obj.Value<double>("Pending");
             item.DepositAddress = obj.Value<string>("CryptoAddress");
             //item.Requested = obj.Value<bool>("Requested");
             //item.Uuid = obj.Value<string>("Uuid");
             account.Balances.Add(item);
         }
     }
     RaiseBalancesChanged();
     return true;
 }
Exemplo n.º 2
0
        string OnGetDeposit(AccountInfo account, string currency, string text)
        {
            if (string.IsNullOrEmpty(text))
            {
                return(null);
            }
            JObject res = JsonConvert.DeserializeObject <JObject>(text);

            if (res.Value <bool>("success") == false)
            {
                string error = res.Value <string>("message");
                if (error == "ADDRESS_GENERATING")
                {
                    LogManager.Default.AddWarning("Bittrex: OnGetDeposit fails: " + error + ". Try again later after deposit address generate.", "Currency = " + currency);
                }
                else
                {
                    LogManager.Default.AddError("Bittrex: OnGetDeposit fails: " + error, "Currency = " + currency);
                }
                return(null);
            }
            JObject addr = res.Value <JObject>("result");
            BitFinexAccountBalanceInfo info = (BitFinexAccountBalanceInfo)account.Balances.FirstOrDefault(b => b.Currency == currency);

            info.Currency = addr.Value <string>("Address");
            return(info.Currency);
        }
Exemplo n.º 3
0
 public bool OnGetBalance(AccountInfo account, string text) {
     if(string.IsNullOrEmpty(text))
         return false;
     JObject res = JsonConvert.DeserializeObject<JObject>(text);
     if(res.Value<bool>("success") == false) {
         Debug.WriteLine("OnGetBalance fails: " + res.Value<string>("message"));
         return false;
     }
     JObject obj = res.Value<JObject>("result");
     lock(account.Balances) {
         string currency = obj.Value<string>("Currency");
         BitFinexAccountBalanceInfo info = (BitFinexAccountBalanceInfo)account.Balances.FirstOrDefault((b) => b.Currency == currency);
         if(info == null) {
             info = new BitFinexAccountBalanceInfo(account);
             info.Currency = obj.Value<string>("Currency");
             //info.Requested = obj.Value<bool>("Requested");
             //info.Uuid = obj.Value<string>("Uuid");
             account.Balances.Add(info);
         }
         info.LastAvailable = info.Available;
         info.Available = obj.Value<string>("Available") == null ? 0 : obj.Value<double>("Available");
         //info.Balance = obj.Value<string>("Balance") == null ? 0 : obj.Value<double>("Balance");
         //info.Pending = obj.Value<string>("Pending") == null ? 0 : obj.Value<double>("Pending");
         info.DepositAddress = obj.Value<string>("CryptoAddress");
     }
     return true;
 }
Exemplo n.º 4
0
        public override bool UpdateBalances(AccountInfo account)
        {
            if (Currencies.Count == 0)
            {
                if (!GetCurrenciesInfo())
                {
                    return(false);
                }
            }
            string    address = string.Format("https://bittrex.com/api/v1.1/account/getbalances?apikey={0}&nonce={1}", Uri.EscapeDataString(account.ApiKey), GetNonce());
            WebClient client  = GetWebClient();

            client.Headers.Clear();
            client.Headers.Add("apisign", account.GetSign(address));
            try {
                byte[] bytes = client.DownloadData(address);


                if (bytes == null)
                {
                    return(false);
                }

                int startIndex = 1;
                if (!JSonHelper.Default.SkipSymbol(bytes, ':', 3, ref startIndex))
                {
                    return(false);
                }

                List <string[]> res = JSonHelper.Default.DeserializeArrayOfObjects(bytes, ref startIndex, new string[] {
                    "Currency",
                    "Balance",
                    "Available",
                    "Pending",
                    "CryptoAddress"
                });

                foreach (string[] item in res)
                {
                    BitFinexAccountBalanceInfo binfo = (BitFinexAccountBalanceInfo)account.Balances.FirstOrDefault(b => b.Currency == item[0]);
                    if (binfo == null)
                    {
                        binfo          = new BitFinexAccountBalanceInfo(account);
                        binfo.Currency = item[0];
                        account.Balances.Add(binfo);
                    }
                    //info.Balance = FastDoubleConverter.Convert(item[1]);
                    binfo.Available = FastValueConverter.Convert(item[2]);
                    //info.Pending = FastDoubleConverter.Convert(item[3]);
                    binfo.DepositAddress = item[4];
                }
            }
            catch (Exception) {
                return(false);
            }
            return(true);
        }