예제 #1
0
        protected override object[] HttpCallAuth(HttpClient _http, string _method, ref string _url, object[] _keyValues)
        {
            IList <object> _result = new List <object>();
            string         _time   = DateTime.Now.Ticks.ToString();

            _result.Add("request");
            _result.Add(_url);
            _result.Add("nonce");
            _result.Add(_time);

            JObject _json = new JObject();

            _json["request"] = _url;
            _json["nonce"]   = _time;
            for (int i = 0; i < _keyValues.Length; i += 2)
            {
                Type _valueType = _keyValues[i + 1].GetType();
                if (_valueType == typeof(int))
                {
                    _json[_keyValues[i]] = (int)_keyValues[i + 1];
                }
                else if (_valueType == typeof(bool))
                {
                    _json[_keyValues[i]] = (bool)_keyValues[i + 1];
                }
                else if (_valueType == typeof(long))
                {
                    _json[_keyValues[i]] = (long)_keyValues[i + 1];
                }
                else if (_valueType == typeof(JArray))
                {
                    _json[_keyValues[i]] = (JArray)_keyValues[i + 1];
                }
                else
                {
                    _json[_keyValues[i]] = _keyValues[i + 1].ToString();
                }

                _result.Add(_keyValues[i]);
                _result.Add(_keyValues[i + 1]);
            }

            string _payload       = _json.ToString(Newtonsoft.Json.Formatting.None);
            string _payloadBase64 = Base64.Encode(Encoding.UTF8.GetBytes(_payload));
            string _sign          = SHA.EncodeHMACSHA384(_payloadBase64, base.Secret);

            _http.Headers.Add("Content-Type", "application/json");
            _http.Headers.Add("Accept", "application/json");
            _http.Headers.Add("X-BFX-APIKEY", base.Key);
            _http.Headers.Add("X-BFX-PAYLOAD", _payloadBase64);
            _http.Headers.Add("X-BFX-SIGNATURE", _sign);

            return(_result.ToArray());
        }