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)); }
/// <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 = 5000) 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); } } 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)); }
/// <summary> /// Processes a PUT request /// </summary> /// <typeparam name="T"></typeparam> /// <param name="endpoint"></param> /// <param name="receiveWindow"></param> /// <returns></returns> public async Task <T> ProcessPutRequest <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.PutRequest(endpoint.Uri); break; case EndpointSecurityType.None: case EndpointSecurityType.Signed: default: throw new ArgumentOutOfRangeException(); } return(await HandleResponse <T>(message, endpoint.ToString(), fullKey)); }
/// <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)); }