예제 #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 Get(apiAction.Action, getQueryParams)));

            case HttpMethods.POST:
                var postQueryParams = @params as IJsonQueryParams;
                return(JsonConvert.DeserializeObject <TResult>(
                           await Post(apiAction.Action, postQueryParams)));

            case HttpMethods.PUT:
                var putQueryParams = @params as IJsonQueryParams;
                return(JsonConvert.DeserializeObject <TResult>(
                           await Put(apiAction.Action, putQueryParams)));

            //case HttpMethods.DELETE:
            //    var deleteQueryParams = @params as IQueryStringParams;
            //    return JsonConvert.DeserializeObject<TResult>(
            //        await Delete(apiAction.Action, deleteQueryParams));
            default:
                throw new ArgumentOutOfRangeException();
            }
        }
예제 #2
0
        public async Task <ApiResult <TResult> > Execute <TParams, TResult>(ApiActionAttributes <TParams, TResult> apiAction, TParams @params)
        {
            _logger.LogInformation("Method: Execute");
            switch (apiAction.Method)
            {
            case Core.Models.HttpMethods.POST:
                var postQueryParams  = @params as IBodyParams;
                var serializedResult = await _apiProxy.Post(apiAction.Action, postQueryParams);

                var deserializedResult = JsonConvert.DeserializeObject <TResult>(serializedResult.Result);
                return(serializedResult.ToResultType <TResult>(deserializedResult));

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
예제 #3
0
        private async Task <OrderDto> ExecuteTakeProfitOrder(string market, int quantity, decimal price, decimal trigger, OrderSide orderSide)
        {
            var apiActionAttributes = new ApiActionAttributes <OrderPOSTRequestParams, OrderDto>("order", HttpMethods.POST);

            return(await _bitmexApiService.Execute(apiActionAttributes, new OrderPOSTRequestParams
            {
                Symbol = market,
                Side = Enum.GetName(typeof(OrderSide), orderSide),
                OrderQty = quantity,
                OrdType = "LimitIfTouched",
                StopPx = trigger,
                Price = price,
                ExecInst = "Close,LastPrice",
                TimeInForce = "GoodTillCancel"
            }));
        }
예제 #4
0
        private async Task <OrderDto> ExecuteStopLossOrder(string market, int quantity, decimal price, decimal trigger, OrderSide orderSide)
        {
            var apiActionAttributes = new ApiActionAttributes <OrderPOSTRequestParams, OrderDto>("order", HttpMethods.POST);

            Logger.Info($"Stop loss trigger at {trigger}, {orderSide} at {price}");
            return(await _bitmexApiService.Execute(apiActionAttributes, new OrderPOSTRequestParams
            {
                Symbol = market,
                Side = Enum.GetName(typeof(OrderSide), orderSide),
                OrderQty = quantity,
                OrdType = "StopLimit",
                StopPx = trigger,
                Price = price,
                ExecInst = "Close,LastPrice",
            }));
        }
예제 #5
0
        private async Task <OrderDto> ExecuteStopLossOrder(string market, int quantity, decimal sellPrice, decimal trigger, OrderSide orderSide)
        {
            var apiActionAttributes = new ApiActionAttributes <OrderPOSTRequestParams, OrderDto>("order", HttpMethods.POST);

            return(await _bitmexApiService.Execute(apiActionAttributes, new OrderPOSTRequestParams
            {
                Symbol = market,
                Side = Enum.GetName(typeof(OrderSide), orderSide),
                OrderQty = quantity,
                OrdType = "StopLimit",
                StopPx = trigger,
                Price = sellPrice,
                ExecInst = "Close,LastPrice",
            }));

            /*return await _bitmexApiService.Execute(BitmexApiUrls.Order.PostOrder,
             *  OrderPOSTRequestParams.CreateLimitStopOrder(market, quantity, trigger, sellPrice, orderSide));*/
        }