Exemple #1
0
        /// <summary>
        /// Account balance
        /// </summary>
        /// <param name="base_name">The type of trading base-currency of which information you want to query for.</param>
        /// <param name="quote_name">The type of trading quote-currency of which information you want to query for.</param>
        /// <param name="args">Add additional attributes for each exchange</param>
        /// <returns></returns>
        public override async ValueTask <Balance> FetchBalanceAsync(string base_name, string quote_name, Dictionary <string, object> args = null)
        {
            var _result = new Balance();

            var _currency_id = await publicApi.LoadCurrencyIdAsync(base_name);

            if (_currency_id.success == true)
            {
                privateClient.ExchangeInfo.ApiCallWait(TradeType.Private);

                var _params = privateClient.MergeParamsAndArgs(args);

                var _json_value = await privateClient.CallApiPost1Async("/balance/", _params);

#if DEBUG
                _result.rawJson = _json_value.Content;
#endif
                var _json_result = privateClient.GetResponseMessage(_json_value.Response);
                if (_json_result.success == true)
                {
                    var _balances = privateClient.DeserializeObject <JObject>(_json_value.Content);
                    {
                        foreach (var _b in _balances)
                        {
                            if (_b.Value.GetType() == typeof(JValue))
                            {
                                continue;
                            }

                            if (_b.Key.ToLower() != _currency_id.result.ToLower())
                            {
                                continue;
                            }

                            var _balance = new CBalanceItem()
                            {
                                free = _b.Value["available"].Value <decimal>(),
                                used = _b.Value["orders"].Value <decimal>()
                            };

                            _balance.currency = base_name;
                            _balance.total    = _balance.free + _balance.used;

                            _result.result = _balance;
                            break;
                        }
                    }
                }

                _result.SetResult(_json_result);
            }
            else
            {
                _result.SetResult(_currency_id);
            }

            return(_result);
        }
Exemple #2
0
        /// <summary>
        /// All account balances
        /// </summary>
        /// <param name="args">Add additional attributes for each exchange</param>
        /// <returns></returns>
        public override async ValueTask <Balances> FetchBalancesAsync(Dictionary <string, object> args = null)
        {
            var _result = new Balances();

            var _markets = await publicApi.LoadMarketsAsync();

            if (_markets.success == true)
            {
                privateClient.ExchangeInfo.ApiCallWait(TradeType.Private);

                var _params = privateClient.MergeParamsAndArgs(args);

                var _json_value = await privateClient.CallApiPost1Async("/balance/", _params);

#if DEBUG
                _result.rawJson = _json_value.Content;
#endif
                var _json_result = privateClient.GetResponseMessage(_json_value.Response);
                if (_json_result.success == true)
                {
                    var _balances = privateClient.DeserializeObject <JToken>(_json_value.Content);
                    {
                        foreach (var _currency_id in _markets.CurrencyNames)
                        {
                            var _balance = new CBalanceItem();

                            if (_balances.SelectToken(_currency_id.Key) != null)
                            {
                                _balance = privateClient.DeserializeObject <CBalanceItem>(_balances[_currency_id.Key].ToString());
                                if (_balance != null)
                                {
                                    _balance.total = _balance.free + _balance.used;
                                }
                            }
                            _balance.currency = _currency_id.Value;

                            _result.result.Add(_balance);
                        }
                    }
                }

                _result.SetResult(_json_result);
            }
            else
            {
                _result.SetResult(_markets);
            }

            return(_result);
        }