Ejemplo n.º 1
0
        public static async Task <T> InvokeHttpCall <T>(
            string args,
            InvokeMethod method,
            SecurityType token,
            string apiKey,
            string secretKey)
        {
            string endpoint = endpointBase + args;

            if (token == SecurityType.TRADE || token == SecurityType.USER_DATA)
            {
                endpoint += "&recvWindow=5000";

                long timestamp = JsTimeConverter.TimeToMs(DateTime.UtcNow - _offset);
                endpoint += "&timestamp=" + timestamp.ToString();

                var signature = Crypto(endpoint, secretKey);
                endpoint += "&signature=" + signature;
            }

            if (_httpClient.DefaultRequestHeaders.Contains("X-MBX-APIKEY"))
            {
                _httpClient.DefaultRequestHeaders.Remove("X-MBX-APIKEY");
            }

            if (token != SecurityType.NONE)
            {
                _httpClient.DefaultRequestHeaders.Add("X-MBX-APIKEY", apiKey);
            }

            HttpResponseMessage res;

            switch (method)
            {
            case InvokeMethod.GET:
                res = await _httpClient.GetAsync(endpoint);

                break;

            case InvokeMethod.DELETE:
                res = await _httpClient.DeleteAsync(endpoint);

                break;

            case InvokeMethod.POST:
                res = await _httpClient.PostAsync(endpoint, null);

                break;

            case InvokeMethod.PUT:
                res = await _httpClient.PutAsync(endpoint, null);

                break;

            default:
                res = null;
                break;
            }

            string data = await res.Content.ReadAsStringAsync();

            if (!res.IsSuccessStatusCode)
            {
                throw new HttpRequestException(data);
            }

            return(ConvertHelper.DataConvert <T>(data));
        }
Ejemplo n.º 2
0
 string AppendPeriod(DateTime startTime, DateTime endTime)
 {
     return("&startTime=" + JsTimeConverter.TimeToMs(startTime).ToString()
            + "&endTime=" + JsTimeConverter.TimeToMs(endTime).ToString());
 }