public async Task <TResult> Execute <TParams, TResult>(ApiActionAttributes <TParams, TResult> apiAction, TParams @params) { switch (apiAction.Method) { case HttpMethods.GET: var getQueryParams = @params as IQueryStringParams; return(JsonConvert.DeserializeObject <TResult>( await _bitmexApiProxy.Get(apiAction.Action, getQueryParams))); case HttpMethods.POST: var postQueryParams = @params as IJsonQueryParams; return(JsonConvert.DeserializeObject <TResult>( await _bitmexApiProxy.Post(apiAction.Action, postQueryParams))); case HttpMethods.PUT: var putQueryParams = @params as IJsonQueryParams; return(JsonConvert.DeserializeObject <TResult>( await _bitmexApiProxy.Put(apiAction.Action, putQueryParams))); case HttpMethods.DELETE: var deleteQueryParams = @params as IJsonQueryParams; return(JsonConvert.DeserializeObject <TResult>( await _bitmexApiProxy.Delete(apiAction.Action, deleteQueryParams))); default: throw new ArgumentOutOfRangeException(); } }
public async Task <BitmexApiResult <TResult> > Execute <TParams, TResult>(ApiActionAttributes <TParams, TResult> apiAction, TParams @params) { switch (apiAction.Method) { case HttpMethods.GET: { var getQueryParams = @params as IQueryStringParams; //Log.Debug(getQueryParams.ToQueryString()); var serializedResult = await _bitmexApiProxy.Get(apiAction.Action, getQueryParams); //Log.Debug(serializedResult.Result); var deserializedResult = JsonConvert.DeserializeObject <TResult>(serializedResult.Result); return(serializedResult.ToResultType <TResult>(deserializedResult)); } case HttpMethods.POST: { var postQueryParams = @params as IJsonQueryParams; //Log.Debug("1." + postQueryParams.ToJson()); var serializedResult = await _bitmexApiProxy.Post(apiAction.Action, postQueryParams); //Log.Debug("2." + serializedResult.Result); var deserializedResult = JsonConvert.DeserializeObject <TResult>(serializedResult.Result); return(serializedResult.ToResultType <TResult>(deserializedResult)); } case HttpMethods.PUT: { var putQueryParams = @params as IJsonQueryParams; //Log.Debug(putQueryParams.ToJson()); var serializedResult = await _bitmexApiProxy.Put(apiAction.Action, putQueryParams); //Log.Debug(serializedResult.Result); var deserializedResult = JsonConvert.DeserializeObject <TResult>(serializedResult.Result); return(serializedResult.ToResultType <TResult>(deserializedResult)); } case HttpMethods.DELETE: { var deleteQueryParams = @params as IQueryStringParams; //Log.Debug(deleteQueryParams.ToQueryString()); var serializedResult = await _bitmexApiProxy.Delete(apiAction.Action, deleteQueryParams); //Log.Debug(serializedResult.Result); var deserializedResult = JsonConvert.DeserializeObject <TResult>(serializedResult.Result); return(serializedResult.ToResultType <TResult>(deserializedResult)); } default: throw new ArgumentOutOfRangeException(); } }