Exemple #1
0
        public override Dictionary <string, string> AddAuthenticationToHeaders(string uri, HttpMethod method, Dictionary <string, object> parameters, bool signed, PostParameters postParameterPosition, ArrayParametersSerialization arraySerialization)
        {
            if (!signed && !signPublicRequests)
            {
                return(new Dictionary <string, string>());
            }

            if (Credentials == null || Credentials.Key == null || this.PassPhrase == null)
            {
                throw new ArgumentException("No valid API credentials provided. Key/Secret/PassPhrase needed.");
            }

            var time     = (DateTime.UtcNow.ToUnixTimeMilliSeconds() / 1000.0m).ToString(CultureInfo.InvariantCulture);
            var signtext = time + method.Method.ToUpper() + uri.Replace("https://www.okex.com", "").Trim('?');

            if (method == HttpMethod.Post)
            {
                var bodyString = JsonConvert.SerializeObject(parameters.OrderBy(p => p.Key).ToDictionary(p => p.Key, p => p.Value));
                signtext = signtext + bodyString;
            }

            var signature = OkexAuthenticationProvider.Base64Encode(encryptor.ComputeHash(Encoding.UTF8.GetBytes(signtext)));

            return(new Dictionary <string, string> {
                { "OK-ACCESS-KEY", Credentials.Key.GetString() },
                { "OK-ACCESS-SIGN", signature },
                { "OK-ACCESS-TIMESTAMP", time },
                { "OK-ACCESS-PASSPHRASE", this.PassPhrase.GetString() },
            });
        }
Exemple #2
0
        public async Task <CallResult <bool> > User_Login_Async(string apiKey, string apiSecret, string passPhrase)
        {
            if (string.IsNullOrEmpty(apiKey) || string.IsNullOrEmpty(apiSecret) || string.IsNullOrEmpty(passPhrase))
            {
                return(new CallResult <bool>(false, new NoApiCredentialsError()));
            }

            this.Key        = apiKey.ToSecureString();
            this.Secret     = apiSecret.ToSecureString();
            this.PassPhrase = passPhrase.ToSecureString();

            var time     = (DateTime.UtcNow.ToUnixTimeMilliSeconds() / 1000.0m).ToString(CultureInfo.InvariantCulture);
            var signtext = time + "GET" + "/users/self/verify";

            hmacEncryptor = new HMACSHA256(Encoding.ASCII.GetBytes(this.Secret.GetString()));
            var signature = OkexAuthenticationProvider.Base64Encode(hmacEncryptor.ComputeHash(Encoding.UTF8.GetBytes(signtext)));

            var result = await Query <OkexSocketLoginResponse>(new OkexSocketRequest(OkexSocketOperation.Login, this.Key.GetString(), this.PassPhrase.GetString(), time, signature), false).ConfigureAwait(false);

            this.socketAuthendicated = result.Success;
            return(new CallResult <bool>(result.Success, result.Error));
        }