Пример #1
0
        /// <summary>
        /// Processes a GET request
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="endpoint"></param>
        /// <param name="receiveWindow"></param>
        /// <returns></returns>
        public async Task <T> ProcessGetRequest <T>(BinanceEndpointData endpoint, int receiveWindow = 5000) where T : class
        {
            var fullKey = $"{typeof(T).Name}-{endpoint.Uri.AbsoluteUri}";

            if (_cacheEnabled && endpoint.UseCache)
            {
                if (CheckAndRetrieveCachedItem <T>(fullKey, out var item))
                {
                    return(item);
                }
            }
            HttpResponseMessage message;

            switch (endpoint.SecurityType)
            {
            case EndpointSecurityType.ApiKey:
            case EndpointSecurityType.None:
                message = await RequestClient.GetRequest(endpoint.Uri);

                break;

            case EndpointSecurityType.Signed:
                message = await RequestClient.SignedGetRequest(endpoint.Uri, _apiKey, _secretKey, endpoint.Uri.Query, receiveWindow);

                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
            return(await HandleResponse <T>(message, endpoint.ToString(), fullKey));
        }
Пример #2
0
        private async Task <ServerTimeResponse> ProcessGetServerTimeRequest(BinanceEndpointData endpoint)
        {
            var fullKey = $"ServerTimeResponse-{endpoint.Uri.AbsoluteUri}";
            var message = await RequestClient.GetRequest(endpoint.Uri);

            return(await HandleResponse <ServerTimeResponse>(message, endpoint.ToString(), fullKey));
        }
Пример #3
0
        /// <summary>
        /// Processes a GET request
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="endpoint"></param>
        /// <param name="receiveWindow"></param>
        /// <returns></returns>
        public async Task <T> ProcessGetRequest <T>(BinanceEndpointData endpoint, int receiveWindow = 5000) where T : class
        {
            var fullKey = $"{typeof(T).Name}-{endpoint.Uri.AbsoluteUri}";

            if (_cacheEnabled && endpoint.UseCache)
            {
                if (CheckAndRetrieveCachedItem <T>(fullKey, out var item))
                {
                    return(item);
                }
            }
            HttpResponseMessage message;

            switch (endpoint.SecurityType)
            {
            case EndpointSecurityType.ApiKey:
            //todo fix for margin trading
            //var oldUri = endpoint.Uri.ToString();
            //if (oldUri.Contains("?"))
            //    oldUri += "&";
            //else
            //    oldUri += "?";
            //message = await _requestClient.GetRequest(new Uri(oldUri + "X-MBX-APIKEY=" + _apiKey));
            //break;
            case EndpointSecurityType.None:
                message = await _requestClient.GetRequest(endpoint.Uri);

                break;

            case EndpointSecurityType.Signed:
                message = await _requestClient.SignedGetRequest(endpoint.Uri, _apiKey, _secretKey, endpoint.Uri.Query, receiveWindow);

                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
            return(await HandleResponse <T>(message, endpoint.ToString(), fullKey));
        }