コード例 #1
0
        public async Task <JObject> CallPrivateKrakenApiAsync
            (string function, AccountKeys keys = null, Dictionary <String, String> data = null)
        {
            var account = keys ?? DefaultAccountKeys;

            if (account == null)
            {
                throw new ArgumentNullException("accountKeys", "DefaultAccountKeys was not set and no keys were provided.");
            }
            Stream         reqStream  = null;
            string         path       = string.Format("/0/private/{0}", function);
            string         uri        = ApiUrl + path;
            HttpWebRequest webRequest = (HttpWebRequest)HttpWebRequest.Create(uri);

            webRequest.ContentType = "application/x-www-form-urlencoded";
            webRequest.Method      = "POST";
            webRequest.Headers.Add("API-Key", account.ApiKey);
            reqStream = await webRequest.GetRequestStreamAsync();

            var           nonce = ObtainNonce.Invoke();
            StringBuilder sb    = new StringBuilder();

            sb.AppendFormat("nonce={0}", nonce);
            if (data != null)
            {
                foreach (var kvp in data)
                {
                    sb.AppendFormat("&{0}={1}", kvp.Key, kvp.Value);
                }
            }

            byte[] base64DecodedSecret = Convert.FromBase64String(account.SecretKey);
            var    np           = nonce + Convert.ToChar(0) + sb.ToString();
            var    pathBytes    = ExchangeEncoding.GetBytes(path);
            var    hash256Bytes = HashAsSHA256(ExchangeEncoding.GetBytes(np));
            var    z            = new byte[pathBytes.Count() + hash256Bytes.Count()];

            pathBytes.CopyTo(z, 0);
            hash256Bytes.CopyTo(z, pathBytes.Count());

            var signature = HashAsHMACSHA512(base64DecodedSecret, z);

            webRequest.Headers.Add("API-Sign", Convert.ToBase64String(signature));
            using (var writer = new StreamWriter(reqStream))
            {
                writer.Write(sb.ToString());
            }


            var fullResult = await base.CallApiAsync <JObject>(webRequest);

            return(fullResult);
        }
コード例 #2
0
        public async Task <JObject> CallPrivateBittrexAPIAsync
            (string function, AccountKeys keys = null, Dictionary <String, String> data = null)
        {
            var account = keys ?? DefaultAccountKeys;

            if (account == null)
            {
                throw new ArgumentNullException("accountKeys", "DefaultAccountKeys was not set and no keys were provided.");
            }


            var nonce = ObtainNonce.Invoke();
            var uri   = String.Format("{0}/{1}?apikey={2}&nonce={3}", ApiUrl, function, account.ApiKey, nonce);

            StringBuilder sb = new StringBuilder(uri);

            if (data != null)
            {
                foreach (var kvp in data)
                {
                    sb.AppendFormat("&{0}={1}", kvp.Key, kvp.Value);
                }
            }
            uri = sb.ToString();

            HttpWebRequest webRequest = (HttpWebRequest)HttpWebRequest.Create(uri);

            webRequest.Method = "GET";

            byte[] secretKey = ExchangeEncoding.GetBytes(account.SecretKey);
            var    sign      = base.HashAsHMACSHA512(secretKey, ExchangeEncoding.GetBytes(uri));

            webRequest.Headers.Add("apisign", ByteArrayToHexString(sign));

            try
            {
                var fullResult = await CallApiAsync <JObject>(webRequest);

                return(fullResult);
            }
            finally
            {
            }
        }