Example #1
0
        /// <summary>
        /// Finds the expected response object derived from the URI of the call.
        /// </summary>
        /// <returns></returns>
        private object ApiResponseDispatcher()
        {
            // Json is empty > Shit...
            if (String.IsNullOrEmpty(Json))
            {
                //log.Error("Json == null or empty");
                return(null);
            }

            // Uri is empty > Shit...
            if (this.Uri == null || this.Uri.AbsolutePath == "")
            {
                //log.Error("Uri.AbsolutePath null or empty");
                return(null);
            }

            object o;

            // Return the correct type based on the Uri
            switch (this.Uri.AbsolutePath.ToLower())
            {
            case "/api/v1/order":
                if (this.Json.Substring(0, 1) == "[")
                {
                    o = OrdersResponse.FromJson(this.Json);
                }
                else
                {
                    o = OrderResponse.FromJson(this.Json);
                }
                break;

            case "/api/v1/order/all":
            case "/api/v1/order/bulk":
                o = OrdersResponse.FromJson(this.Json);
                break;

            case "/api/v1/position/leverage":
                o = PositionResponse.FromJson(this.Json);
                break;

            case "/api/v1/position":
                o = PositionsResponse.FromJson(this.Json);
                break;

            case "/api/v1/order/closeposition":
                o = OrderResponse.FromJson(this.Json);
                break;

            case "/api/v1/user/wallet":
                o = WalletResponse.FromJson(this.Json);
                break;

            case "/api/v1/order/cancelallafter":
            default:
                o = null;
                //log.Error("Uri unknown. Please add [" + this.Uri.AbsolutePath + "] to the evaluated Uri's.");
                break;
            }

            return(o);
        }