Ejemplo n.º 1
0
        public T GetResult <T>(PrivateApiCall call, string requestData)
            where T : IResponse
        {
            var            nonce = DateTime.Now.Ticks.ToString();
            string         requestContentBase64String = string.Empty;
            string         jsonData = JsonConvert.SerializeObject(requestData);
            string         url      = string.Format("{0}/api/v1.1/account/{1}apikey=" + ApiKey + "&nonce=" + nonce, BaseUrl.TrimEnd('/'), requestData);
            HttpWebRequest http     = (HttpWebRequest)WebRequest.Create(new Uri(url));

            http.Accept = "application/json";
            http.Method = "GET";

            var uriBytes       = Encoding.UTF8.GetBytes(url);
            var apiSecretBytes = Encoding.UTF8.GetBytes(ApiSecret);

            using (var hmac = new HMACSHA512(apiSecretBytes))
            {
                var hash     = hmac.ComputeHash(uriBytes);
                var hashText = byteToString(hash);
                http.Headers.Add("apisign: " + hashText);
            }

            var response = http.GetResponse();
            var stream   = response.GetResponseStream();
            var sr       = new StreamReader(stream);
            var content  = sr.ReadToEnd();

            string result = DoPrivate(call, content);

            return(JsonConvert.DeserializeObject <T>(result));
        }
Ejemplo n.º 2
0
        public async Task <T> GetResultOld <T, U>(PrivateApiCall call, U requestData)
            where T : IResponse
            where U : IRequest
        {
            var response = await _privateClient.PostAsJsonAsync <U>(string.Format("{0}/Api/{1}", BaseUrl.TrimEnd('/'), call), requestData);

            return(await response.Content.ReadAsAsync <T>());
        }
Ejemplo n.º 3
0
        public T GetResult <T, U>(PrivateApiCall call, U requestData)
            where T : IResponse
            where U : IRequest
        {
            string         requestContentBase64String = string.Empty;
            string         jsonData   = JsonConvert.SerializeObject(requestData);
            string         url        = string.Format("{0}/Api/{1}", BaseUrl.TrimEnd('/'), call);
            HttpWebRequest http       = (HttpWebRequest)WebRequest.Create(new Uri(url));
            string         requestUri = System.Web.HttpUtility.UrlEncode(http.RequestUri.AbsoluteUri.ToLower());

            http.Accept      = "application/json";
            http.ContentType = "application/json";
            http.Method      = "POST";
            Byte[] bytes = Encoding.UTF8.GetBytes(jsonData);

            if (bytes != null)
            {
                using (var md5 = MD5.Create())
                {
                    var requestContentHash = md5.ComputeHash(bytes);
                    requestContentBase64String = Convert.ToBase64String(requestContentHash);
                }
            }

            //create random nonce for each request
            var nonce = Guid.NewGuid().ToString("N");

            //Creating the raw signature string
            var signatureRawData   = string.Concat(ApiKey, "POST", requestUri, nonce, requestContentBase64String);
            var secretKeyByteArray = Convert.FromBase64String(ApiSecret);
            var signature          = Encoding.UTF8.GetBytes(signatureRawData);

            using (var hmac = new HMACSHA256(secretKeyByteArray))
            {
                var signatureBytes = hmac.ComputeHash(signature);
                var requestSignatureBase64String = Convert.ToBase64String(signatureBytes);

                //Setting the values in the Authorization header using custom scheme (amx)
                //http.Headers.Authorization = new AuthenticationHeaderValue("amx", string.Format("{0}:{1}:{2}", ApiKey, requestSignatureBase64String, nonce));

                http.Headers.Add("Authorization: amx " + string.Format("{0}:{1}:{2}", ApiKey, requestSignatureBase64String, nonce));
            }


            Stream newStream = http.GetRequestStream();

            newStream.Write(bytes, 0, bytes.Length);
            newStream.Close();

            var response = http.GetResponse();

            var stream  = response.GetResponseStream();
            var sr      = new StreamReader(stream);
            var content = sr.ReadToEnd();

            return(JsonConvert.DeserializeObject <T>(content));
        }
Ejemplo n.º 4
0
        public string DoPrivate(PrivateApiCall call, string response)
        {
            string ret = response;

            ret = ret.Replace("\"result\":[", "\"Data\":[");
            ret = ret.Replace("\"success\":", "\"Success\":");
            ret = ret.Replace("\"message\":", "\"Message\":");



            switch (call)
            {
            case PrivateApiCall.GetBalance:
                //encapsulate single data items in a list, since this is what the deserialized object holds.
                if (ret.Contains("\"result\":{"))
                {
                    ret = ret.Replace("\"result\":{", "\"Data\":[{");
                    ret = ret.Replace("}}", "}]}");
                }

                ret = ret.Replace("Currency", "Symbol");
                ret = ret.Replace("Balance", "Total");
                ret = ret.Replace("Pending", "Unconfirmed");
                ret = ret.Replace("CryptoAddress", "Address");
                ret = ret.Replace("UUID", "CurrencyId");
                break;

            case PrivateApiCall.GetDepositAddress:
                ret = ret.Replace("\"result\":", "\"Data\":");
                break;

            case PrivateApiCall.GetTradeHistory:
                if (ret.Contains("\"result\":{"))
                {
                    ret = ret.Replace("\"result\":{", "\"Data\":[{");
                    ret = ret.Replace("}}", "}]}");
                    ret = ret.Replace("OrderUuid", "TradeId");
                    ret = ret.Replace("Exchange", "Market");
                    ret = ret.Replace("OrderType", "Type");
                    ret = ret.Replace("Quantity", "Amount");
                    ret = ret.Replace("Price", "Rate");
                    ret = ret.Replace("Commission", "Fee");
                }
                break;

            case PrivateApiCall.GetTransactions:
                ret = ret.Replace("\"result\":", "\"Data\":");
                ret = ret.Replace("PaymentUuid", "Id");
                ret = ret.Replace("LastUpdated", "Timestamp");
                ret = ret.Replace("Authorized", "Status");
                ret = ret.Replace("TxCost", "Fee");
                break;
            }

            return(ret);
        }
Ejemplo n.º 5
0
        public async Task <T> GetResult <T, U>(PrivateApiCall call, U requestData) where T : IResponse where U : IRequest
        {
            var response = await _client.PostAsJsonAsync <U>(string.Format("{0}/api/private/{1}", _apiBaseAddress.TrimEnd('/'), call.ToString().ToLower()), requestData);

            return(await response.Content.ReadAsAsync <T>());
        }
Ejemplo n.º 6
0
 public T GetResult <T, U>(PrivateApiCall call, U requestData)
     where T : IResponse
     where U : IRequest
 {
     return((T) new object());
 }
Ejemplo n.º 7
0
 public string DoPrivate(PrivateApiCall call, string result)
 {
     return(null);
 }