Exemplo n.º 1
0
        public override Balances GetBalances(params object[] _symbols)
        {
            try
            {
                string _url = "/v1.1/account/getbalances";

                IList <object> _values = new List <object>();
                _values.Add("apikey");
                _values.Add(this.Key);
                _values.Add("nonce");
                _values.Add(DateTimePlus.DateTime2JSTime(DateTime.UtcNow));

                JToken _token = base.HttpCall(HttpCallMethod.Get, "GET", _url, true, _values.ToArray());
                if (_token == null || _token.ToString(Newtonsoft.Json.Formatting.None).Trim() == "{}")
                {
                    return(null);
                }

                Balances _balances = new Balances();
                foreach (JToken _item in _token)
                {
                    _balances[_item["Currency"].ToString()] = new BalanceItem()
                    {
                        Symbol = _item["Currency"].ToString(),
                        Free   = _item["Available"].ToString() == "" ? 0 : _item["Available"].Value <decimal>(),
                        Lock   = _item["Pending"].ToString() == "" ? 0 : _item["Pending"].Value <decimal>()
                    };
                }
                foreach (string _symbol in _symbols)
                {
                    if (!_balances.ContainsKey(_symbol.ToUpper()))
                    {
                        _balances[_symbol.ToUpper()] = new BalanceItem()
                        {
                            Symbol = _symbol.ToUpper(),
                            Free   = 0M,
                            Lock   = 0M
                        };
                    }
                }
                return(_balances);
            }
            catch (Exception)
            {
                return(null);
            }
        }
Exemplo n.º 2
0
        public override Balances GetBalances(params object[] _pairs)
        {
            string _url   = "/v2/accounts/balance";
            JToken _token = base.HttpCall(HttpCallMethod.Get, "GET", _url, true);

            if (_token == null)
            {
                return(null);
            }

            Balances _balances = new Balances();

            foreach (JToken _item in _token.Value <JArray>())
            {
                _balances[_item["currency"].Value <string>()] = new BalanceItem()
                {
                    Symbol = _item["currency"].Value <string>(),
                    Free   = _item["available"].Value <decimal>(),
                    Lock   = _item["frozen"].Value <decimal>()
                };
            }
            return(_balances);
        }
Exemplo n.º 3
0
        public override Balances GetBalances(params object[] _pairs)
        {
            string _url   = "/accounts";
            JToken _token = base.HttpCall(HttpCallMethod.Get, "GET", _url, true);

            if (_token == null)
            {
                return(null);
            }

            Balances _balances = new Balances();

            foreach (JToken _item in _token)
            {
                _balances[_item["currency"].ToString()] = new BalanceItem()
                {
                    Symbol = _item["currency"].ToString(),
                    Free   = _item["balance"].Value <decimal>(),
                    Lock   = _item["locked"].Value <decimal>()
                };
            }
            return(_balances);
        }
Exemplo n.º 4
0
        public override Balances GetBalances(params object[] _symbols)
        {
            string _url   = "/api/spot/v3/accounts";
            JToken _token = base.HttpCall(HttpCallMethod.Json, "GET", _url, true);

            if (_token == null)
            {
                return(null);
            }

            JArray _jArray = JArray.Parse(_token.ToString());

            Balances _balances = new Balances();

            foreach (JToken _item in _jArray)
            {
                _balances[_item["currency"].ToString()] = new BalanceItem()
                {
                    Symbol = _item["currency"].ToString(),
                    Free   = _item["available"].ToString() == "" ? 0 : _item["available"].Value <decimal>(),
                    Lock   = _item["hold"].ToString() == "" ? 0 : _item["hold"].Value <decimal>()
                };
            }
            foreach (string _symbol in _symbols)
            {
                if (!_balances.ContainsKey(_symbol.ToUpper()))
                {
                    _balances[_symbol.ToUpper()] = new BalanceItem()
                    {
                        Symbol = _symbol.ToUpper(),
                        Free   = 0M,
                        Lock   = 0M
                    };
                }
            }
            return(_balances);
        }
Exemplo n.º 5
0
        public override Balances GetBalances(params object[] _symbols)
        {
            string _url       = "/api/v3/account";
            string _timestamp = DateTimePlus.DateTime2JSTime(DateTime.UtcNow.AddSeconds(-1)).ToString() + DateTime.UtcNow.Millisecond.ToString();
            JToken _token     = base.HttpCall(HttpCallMethod.Get, "GET", _url, true, "timestamp", _timestamp);

            if (_token == null)
            {
                return(null);
            }

            Balances _balances = new Balances();

            foreach (JToken _item in _token["balances"])
            {
                _balances[_item["asset"].ToString()] = new BalanceItem()
                {
                    Symbol = _item["asset"].ToString(),
                    Free   = _item["free"].Value <decimal>(),
                    Lock   = _item["locked"].Value <decimal>()
                };
            }
            foreach (string _symbol in _symbols)
            {
                if (!_balances.ContainsKey(_symbol.ToUpper()))
                {
                    _balances[_symbol.ToUpper()] = new BalanceItem()
                    {
                        Symbol = _symbol.ToUpper(),
                        Free   = 0M,
                        Lock   = 0M
                    };
                }
            }
            return(_balances);
        }
Exemplo n.º 6
0
        public override Balances GetBalances(params object[] _pairs)
        {
            string _url   = "/v1/balance/";
            JToken _token = base.HttpCall(HttpCallMethod.Get, "GET", _url, true);

            if (_token == null)
            {
                return(null);
            }

            Balances _balances = new Balances();

            foreach (JToken _item in _token)
            {
                JProperty _property = (JProperty)_item;
                _balances[_property.Name] = new BalanceItem()
                {
                    Symbol = _property.Name,
                    Free   = _property.Value["available"].Value <decimal>(),
                    Lock   = _property.Value["frozen"].Value <decimal>()
                };
            }
            return(_balances);
        }