Exemple #1
0
        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();
            }
        }
Exemple #2
0
        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;
                var serializedResult = await _bitmexApiProxy.Get(apiAction.Action, getQueryParams);

                var deserializedResult = BitmexJsonSerializer.Deserialize <TResult>(serializedResult.Result);
                return(serializedResult.ToResultType <TResult>(deserializedResult));
            }

            case HttpMethods.POST:
            {
                var postQueryParams  = @params as IJsonQueryParams;
                var serializedResult = await _bitmexApiProxy.Post(apiAction.Action, postQueryParams);

                var deserializedResult = BitmexJsonSerializer.Deserialize <TResult>(serializedResult.Result);
                return(serializedResult.ToResultType <TResult>(deserializedResult));
            }

            case HttpMethods.PUT:
            {
                var putQueryParams   = @params as IJsonQueryParams;
                var serializedResult = await _bitmexApiProxy.Put(apiAction.Action, putQueryParams);

                var deserializedResult = BitmexJsonSerializer.Deserialize <TResult>(serializedResult.Result);
                return(serializedResult.ToResultType <TResult>(deserializedResult));
            }

            case HttpMethods.DELETE:
            {
                var deleteQueryParams = @params as IQueryStringParams;
                var serializedResult  = await _bitmexApiProxy.Delete(apiAction.Action, deleteQueryParams);

                var deserializedResult = BitmexJsonSerializer.Deserialize <TResult>(serializedResult.Result);
                return(serializedResult.ToResultType <TResult>(deserializedResult));
            }

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
Exemple #3
0
 public async Task <TResult> Execute <TParams, TResult>(IBitmexAuthorization bitmexAuthorization,
                                                        ApiActionAttributes <TParams, TResult> apiAction, TParams @params)
 {
     return(JsonConvert.DeserializeObject <TResult>(await _bitmexApiProxy.RequestAsync(bitmexAuthorization,
                                                                                       ToHttpMethod(apiAction.Method), apiAction.Action, @params)));
 }
Exemple #4
0
 public Task <TResult> Execute <TParams, TResult>(ApiActionAttributes <TParams, TResult> apiAction,
                                                  TParams @params)
 {
     return(_apiService.Execute(_bitmexAuthorization, apiAction, @params));
 }
Exemple #5
0
        public TResult ExecuteSyncErrorHandler <TParams, TResult>(ApiActionAttributes <TParams, TResult> apiAction, TParams @params)
        {
            switch (apiAction.Method)
            {
            case HttpMethods.GET:

                TResult GetResponseResult = default(TResult);
                lock (_syncObjMain)
                {
                    try
                    {
                        var    getQueryParams = @params as IQueryStringParams;
                        string getResponse    = _bitmexApiProxy.GetSync(apiAction.Action, getQueryParams);
                        if (getResponse != "ErrorOnSendAndGetResponseSync")
                        {
                            GetResponseResult = JsonConvert.DeserializeObject <TResult>(getResponse);
                        }
                    }
                    catch (Exception ex)
                    {
                        Log.Error(ex.Message + ex.StackTrace);
                    }
                    Thread.Sleep(new TimeSpan(0, 0, 0, 1, 10));
                }

                return(GetResponseResult);

            case HttpMethods.POST:

                TResult PostResponseResult = default(TResult);
                lock (_syncObjMain)
                {
                    try
                    {
                        var    postQueryParams = @params as IJsonQueryParams;
                        string postResponse    = _bitmexApiProxy.PostSync(apiAction.Action, postQueryParams);
                        if (postResponse != "ErrorOnSendAndGetResponseSync")
                        {
                            PostResponseResult = JsonConvert.DeserializeObject <TResult>(postResponse);
                        }
                    }
                    catch (Exception ex)
                    {
                        Log.Error(ex.Message + ex.StackTrace);
                    }
                    Thread.Sleep(new TimeSpan(0, 0, 0, 1, 10));
                }

                return(PostResponseResult);

            case HttpMethods.PUT:

                TResult PutResponseResult = default(TResult);
                lock (_syncObjMain)
                {
                    try
                    {
                        var    putQueryParams = @params as IJsonQueryParams;
                        string putResponse    = _bitmexApiProxy.PutSync(apiAction.Action, putQueryParams);
                        if (putResponse != "ErrorOnSendAndGetResponseSync")
                        {
                            PutResponseResult = JsonConvert.DeserializeObject <TResult>(putResponse);
                        }
                    }
                    catch (Exception ex)
                    {
                        Log.Error(ex.Message + ex.StackTrace);
                    }
                    Thread.Sleep(new TimeSpan(0, 0, 0, 1, 10));
                }

                return(PutResponseResult);

            case HttpMethods.DELETE:
                TResult DeleteResponseResult = default(TResult);
                lock (_syncObjMain)
                {
                    try
                    {
                        var    deleteQueryParams = @params as IQueryStringParams;
                        string deleteResponse    = _bitmexApiProxy.DeleteSync(apiAction.Action, deleteQueryParams);
                        if (deleteResponse != "ErrorOnSendAndGetResponseSync")
                        {
                            DeleteResponseResult = JsonConvert.DeserializeObject <TResult>(deleteResponse);
                        }
                    }
                    catch (Exception ex)
                    {
                        Log.Error(ex.Message + ex.StackTrace);
                    }
                    Thread.Sleep(new TimeSpan(0, 0, 0, 1, 10));
                }

                return(DeleteResponseResult);

            default:
                throw new ArgumentOutOfRangeException();
            }
        }