Exemplo n.º 1
0
        public APIProcessor(string apiKey, string secretKey, IAPICacheManager apiCache, RequestClient requestClient)
        {
            _apiKey    = apiKey;
            _secretKey = secretKey;
            if (apiCache != null)
            {
                _apiCache     = apiCache;
                _cacheEnabled = true;
            }

            _requestClient = requestClient;
            _logger        = NLog.LogManager.GetLogger("APIProcessor");
            _logger.Debug($"API Processor set up. Cache Enabled={_cacheEnabled}");
        }
Exemplo n.º 2
0
        /// <summary>
        /// Processes a POST request
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="endpoint"></param>
        /// <param name="receiveWindow"></param>
        /// <returns></returns>
        public async Task <T> ProcessPostRequest <T>(BinanceEndpointData endpoint, int receiveWindow = 10000) where T : class
        {
            var fullKey = $"{typeof(T).Name}-{endpoint.Uri.AbsoluteUri}";

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

            var timeStampOffset = await GetValidTimestampOffsetAsync();

            RequestClient.SetTimestampOffset(timeStampOffset);

            HttpResponseMessage message;

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

                break;

            case EndpointSecurityType.None:
                throw new ArgumentOutOfRangeException();

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

                break;

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