Exemple #1
0
        protected override object[] HttpCallAuth(HttpClient _http, string _method, ref string _url, object[] _keyValues)
        {
            IList <object> _result            = new List <object>();
            JObject        _json              = new JObject();
            Dictionary <string, string> _list = new Dictionary <string, string>();

            for (int i = 0; i < _keyValues.Length; i += 2)
            {
                _json[_keyValues[i].ToString()] = _keyValues[i + 1].ToString();

                _result.Add(_keyValues[i]);
                _result.Add(_keyValues[i + 1]);
            }
            string _sign = "";
            string _time = DateTime.UtcNow.ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ss.fffZ");

            _sign = $"{_time}{_method.ToUpper()}{_url}";
            if (_keyValues.Length > 0)
            {
                _sign += _json.ToString(Newtonsoft.Json.Formatting.None);
            }
            _list.Add("timestamp", _time);
            _list.Add("method", _method.ToUpper());
            _list.Add("requestPath", _url);

            _sign = SHA.EncodeHMACSHA256ToBase64(_sign, this.Secret);

            _http.Headers.Add("OK-ACCESS-KEY", this.Key);
            _http.Headers.Add("OK-ACCESS-SIGN", _sign);
            _http.Headers.Add("OK-ACCESS-TIMESTAMP", _time);
            _http.Headers.Add("OK-ACCESS-PASSPHRASE", this.PassPhrase);

            return(_result.ToArray());
        }
Exemple #2
0
        protected override object[] HttpCallAuth(HttpClient _http, string _method, ref string _url, object[] _keyValues)
        {
            string _time = DateTime.UtcNow.ToString("yyyy-MM-ddTHH:mm:ss");

            if (_method == "GET")
            {
                #region GET
                IList <object> _result = new List <object>();
                string         _query  = "AccessKeyId=" + base.Key;
                _query += "&SignatureMethod=HmacSHA256";
                _query += "&SignatureVersion=2";
                _query += "&Timestamp=" + _time;

                _result.Add("AccessKeyId");
                _result.Add(base.Key);
                _result.Add("SignatureMethod");
                _result.Add("HmacSHA256");
                _result.Add("SignatureVersion");
                _result.Add("2");
                _result.Add("Timestamp");
                _result.Add(_time);

                for (int i = 0; i < (_keyValues.Length - 1); i += 2)
                {
                    if (_keyValues[i + 1] == null)
                    {
                        continue;
                    }
                    _query += "&" + _keyValues[i] + "=" + _keyValues[i + 1];

                    _result.Add(_keyValues[i]);
                    _result.Add(_keyValues[i + 1]);
                }
                string _sign   = _method + "\napi.huobi.pro\n" + _url + "\n" + _query.Replace(":", "%3A");
                string _signed = SHA.EncodeHMACSHA256ToBase64(_sign, base.Secret);

                _result.Add("Signature");
                _result.Add(_signed);
                return(_result.ToArray());

                #endregion
            }
            else
            {
                #region POST
                string _query = "AccessKeyId=" + base.Key;
                _query += "&SignatureMethod=HmacSHA256";
                _query += "&SignatureVersion=2";

                string _sign   = _method + "\napi.huobi.pro\n" + _url + "\n" + _query + "&Timestamp=" + _time.Replace(":", "%3A");
                string _signed = SHA.EncodeHMACSHA256ToBase64(_sign, base.Secret);
                _url += "?" + _query + "&Timestamp=" + HttpUtility.UrlEncode(_time) + "&Signature=" + HttpUtility.UrlEncode(_signed);
                return(_keyValues);

                #endregion
            }
        }