Beispiel #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="response">response value arrive from exchange's server</param>
        /// <returns></returns>
        public override BoolResult GetResponseMessage(IRestResponse response = null)
        {
            var _result = new BoolResult();

            if (response != null)
            {
                if (response.IsSuccessful == true)
                {
                    var _json_result = this.DeserializeObject <JToken>(response.Content);

                    var _json_error = _json_result.SelectToken("status");
                    if (_json_error != null && _json_error.Value <string>() != "ok")
                    {
                        var _error_msg = _json_result.SelectToken("err-msg").Value <string>();
                        _result.SetFailure(
                            _error_msg,
                            ErrorCode.ResponseDataError
                            );
                    }
                }

                if (_result.success == true && response.IsSuccessful == false)
                {
                    _result.SetFailure(
                        response.ErrorMessage ?? response.StatusDescription,
                        ErrorCode.ResponseRestError,
                        (int)response.StatusCode,
                        false
                        );
                }
            }

            return(_result);
        }
Beispiel #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="response">response value arrive from exchange's server</param>
        /// <returns></returns>
        public override BoolResult GetResponseMessage(IRestResponse response = null)
        {
            var _result = new BoolResult();

            if (response != null)
            {
                if (String.IsNullOrEmpty(response.Content) == false && response.Content[0] == '{')
                {
                    var _json_result = this.DeserializeObject <JToken>(response.Content);

                    var _json_message = _json_result.SelectToken("errormsg");
                    if (_json_message != null)
                    {
                        _result.SetFailure(
                            _json_message.Value <string>(),
                            ErrorCode.ExchangeError
                            );
                    }
                }

                if (_result.success == true && response.IsSuccessful == false)
                {
                    _result.SetFailure(
                        response.ErrorMessage ?? response.StatusDescription,
                        ErrorCode.ResponseRestError,
                        (int)response.StatusCode,
                        false
                        );
                }
            }

            return(_result);
        }
Beispiel #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="response">response value arrive from exchange's server</param>
        /// <returns></returns>
        public override BoolResult GetResponseMessage(IRestResponse response = null)
        {
            var _result = new BoolResult();

            if (response != null)
            {
                if (response.IsSuccessful == false)
                {
                    if (String.IsNullOrEmpty(response.Content) == false && (response.Content[0] == '{' || response.Content[0] == '['))
                    {
                        var _json_result = this.DeserializeObject <JToken>(response.Content);

                        var _error_code = ErrorCode.ExchangeError;
                        var _error_msg  = "";
                        {
                            var _json_message = _json_result.SelectToken("message");
                            var _json_errors  = _json_result.SelectToken("errors");

                            if (_json_message != null)
                            {
                                _error_msg = _json_message.Value <string>();
                            }
                            else if (_json_errors != null)
                            {
                                _error_msg = _json_errors.Value <string>();
                            }
                        }

                        if (String.IsNullOrEmpty(_error_msg) == false)
                        {
                            if (ErrorMessages.ContainsKey(_error_msg) == true)
                            {
                                _error_code = ErrorMessages[_error_msg];
                            }

                            _result.SetFailure(_error_msg, _error_code);
                        }
                    }
                }

                if (_result.success == true && response.IsSuccessful == false)
                {
                    _result.SetFailure(
                        response.ErrorMessage ?? response.StatusDescription,
                        ErrorCode.ResponseRestError,
                        (int)response.StatusCode,
                        false
                        );
                }
            }

            return(_result);
        }
Beispiel #4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="response">response value arrive from exchange's server</param>
        /// <returns></returns>
        public override BoolResult GetResponseMessage(IRestResponse response = null)
        {
            var _result = new BoolResult();

            if (response != null)
            {
                if (response.IsSuccessful == true)
                {
                    if (String.IsNullOrEmpty(response.Content) == false && response.Content != "[]")
                    {
                        var _json_result = this.DeserializeObject <JToken>(response.Content);

                        var _json_status = _json_result.SelectToken("status");
                        if (_json_status != null)
                        {
                            var _json_message = _json_status.Value <string>();
                            if (_json_message != "success")
                            {
                                _result.SetFailure(
                                    _json_message,
                                    ErrorCode.ResponseDataError
                                    );
                            }
                        }
                    }
                    else
                    {
                        _result.SetFailure(errorCode: ErrorCode.NotFoundData);
                    }
                }

                if (_result.success == true && response.IsSuccessful == false)
                {
                    var _message = response.ErrorMessage ?? response.StatusDescription;

                    var _warning = response.Headers.Where(h => h.Name.ToLower() == "warning").SingleOrDefault();
                    if (_warning != null)
                    {
                        _message = _warning.Value.ToString();
                    }

                    _result.SetFailure(
                        _message,
                        ErrorCode.ResponseRestError,
                        (int)response.StatusCode,
                        false
                        );
                }
            }

            return(_result);
        }
Beispiel #5
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="response">response value arrive from exchange's server</param>
        /// <returns></returns>
        public override BoolResult GetResponseMessage(IRestResponse response = null)
        {
            var _result = new BoolResult();

            if (response != null)
            {
                if (String.IsNullOrEmpty(response.Content) == false && response.Content[0] == '{')
                {
                    var _json_result = this.DeserializeObject <JToken>(response.Content);

                    var _error_code = ErrorCode.ExchangeError;
                    var _error_msg  = response.Content;

                    var _json_error = _json_result.SelectToken("error_code");
                    if (_json_error != null)
                    {
                        var _error_number = _json_error.Value <int>();
                        if (ErrorMessages.ContainsKey(_error_number) == true)
                        {
                            _error_code = GetErrorMessage(_error_number);
                        }

                        _result.SetFailure(_error_msg, _error_code, _error_number);
                    }
                    else
                    {
                        var _json_return = _json_result.SelectToken("result");
                        if (_json_return != null)
                        {
                            if (_json_return.Value <bool>() == false)
                            {
                                _result.SetFailure(_error_msg, _error_code);
                            }
                        }
                    }
                }

                if (_result.success == true && response.IsSuccessful == false)
                {
                    _result.SetFailure(
                        response.ErrorMessage ?? response.StatusDescription,
                        ErrorCode.ResponseRestError,
                        (int)response.StatusCode,
                        false
                        );
                }
            }

            return(_result);
        }
Beispiel #6
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="response">response value arrive from exchange's server</param>
        /// <returns></returns>
        public override BoolResult GetResponseMessage(IRestResponse response = null)
        {
            var _result = new BoolResult();

            if (response != null)
            {
                if (String.IsNullOrEmpty(response.Content) == false && response.Content != "[]")
                {
                    var _json_result = this.DeserializeObject <JToken>(response.Content);

                    var _json_error = _json_result.SelectToken("error");
                    if (_json_error == null)
                    {
                        var _json_success = _json_result.SelectToken("success");
                        if (_json_success != null && _json_success.Value <long>() != 1)
                        {
                            var _message = _result.message;

                            var _json_message = _json_result.SelectToken("response");
                            if (_json_message != null)
                            {
                                _message = _json_message.Value <string>();
                            }

                            _result.SetFailure(_message, ErrorCode.ResponseDataError);
                        }
                    }
                    else
                    {
                        _result.SetFailure(_json_error.Value <string>(), ErrorCode.ResponseDataError);
                    }
                }
                else
                {
                    _result.SetFailure(errorCode: ErrorCode.NotFoundData);
                }

                if (_result.success == true && response.IsSuccessful == false)
                {
                    _result.SetFailure(
                        response.ErrorMessage ?? response.StatusDescription,
                        ErrorCode.ResponseRestError,
                        (int)response.StatusCode,
                        false
                        );
                }
            }

            return(_result);
        }
Beispiel #7
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="response">response value arrive from exchange's server</param>
        /// <returns></returns>
        public override BoolResult GetResponseMessage(IRestResponse response = null)
        {
            var _result = new BoolResult();

            if (response != null)
            {
                if (String.IsNullOrEmpty(response.Content) == false && response.Content[0] == '{')
                {
                    var _json_result = this.DeserializeObject <JToken>(response.Content);

                    //{"error":{"name":"V1::Exceptions::OrderNotFound","message":"주문을 찾지 못했습니다.","dialog":"client","origin":"member126085 order_uuid:4e493427-0ba8-4bd0-b2f1-0170ae978209"}}
                    var _json_error = _json_result.SelectToken("error");
                    if (_json_error != null)
                    {
                        var _error_code = ErrorCode.ExchangeError;
                        var _error_msg  = _json_error["message"].Value <string>();

                        var _json_name = _json_error["name"];
                        if (_json_name != null)
                        {
                            var _names = _json_name.Value <string>().Split(new string[] { "::" }, StringSplitOptions.None);
                            if (_names.Length > 2)
                            {
                                var _error_enum = Enum.Parse(typeof(ErrorCode), _names[2]);
                                if (_error_enum != null)
                                {
                                    _error_code = (ErrorCode)_error_enum;
                                }
                            }
                        }

                        _result.SetFailure(_error_msg, _error_code);
                    }
                }

                if (_result.success == true && response.IsSuccessful == false)
                {
                    _result.SetFailure(
                        response.ErrorMessage ?? response.StatusDescription,
                        ErrorCode.ResponseRestError,
                        (int)response.StatusCode,
                        false
                        );
                }
            }

            return(_result);
        }
Beispiel #8
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="response">response value arrive from exchange's server</param>
        /// <returns></returns>
        public override BoolResult GetResponseMessage(IRestResponse response = null)
        {
            var _result = new BoolResult();

            if (response != null)
            {
                if (String.IsNullOrEmpty(response.Content) == false && (response.Content[0] == '{' || response.Content[0] == '['))
                {
                    var _json_result = this.DeserializeObject <JToken>(response.Content);

                    var _json_status = _json_result.SelectToken("status");
                    if (_json_status != null)
                    {
                        var _status_code = _json_status.Value <int>();
                        if (_status_code != 0)
                        {
                            var _message = GetErrorMessage(_status_code);

                            var _json_message = _json_result.SelectToken("message");
                            if (_json_message != null)
                            {
                                _message = _json_message.Value <string>();
                            }

                            _result.SetFailure(
                                _message,
                                ErrorCode.ResponseDataError,
                                _status_code
                                );
                        }
                    }
                }

                if (_result.success == true && response.IsSuccessful == false)
                {
                    _result.SetFailure(
                        response.ErrorMessage ?? response.StatusDescription,
                        ErrorCode.ResponseRestError,
                        (int)response.StatusCode,
                        false
                        );
                }
            }

            return(_result);
        }
Beispiel #9
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="response">response value arrive from exchange's server</param>
        /// <returns></returns>
        public override BoolResult GetResponseMessage(IRestResponse response = null)
        {
            var _result = new BoolResult();

            if (response != null)
            {
                if (response.IsSuccessful == true)
                {
                    if (response.Content.Length > 0 && response.Content[0] == '{')
                    {
                        var _json_result = this.DeserializeObject <JObject>(response.Content);

                        var _json_code = _json_result.SelectToken("errorCode");
                        if (_json_code != null)
                        {
                            var _status_code = _json_code.Value <int>();
                            if (_status_code != 0)
                            {
                                _result.SetFailure(
                                    GetErrorMessage(_status_code),
                                    ErrorCode.ResponseDataError,
                                    _status_code
                                    );
                            }
                        }
                    }
                    else
                    {
                        _result.SetFailure(errorCode: ErrorCode.ResponseDataError);
                    }
                }

                if (_result.success == true && response.IsSuccessful == false)
                {
                    _result.SetFailure(
                        response.ErrorMessage ?? response.StatusDescription,
                        ErrorCode.ResponseRestError,
                        (int)response.StatusCode,
                        false
                        );
                }
            }

            return(_result);
        }
Beispiel #10
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="response">response value arrive from exchange's server</param>
        /// <returns></returns>
        public override BoolResult GetResponseMessage(IRestResponse response = null)
        {
            var _result = new BoolResult();

            if (response != null)
            {
                if (String.IsNullOrEmpty(response.Content) == false)
                {
                    var _json_result = this.DeserializeObject <JObject>(response.Content);

                    var _json_success = true;

                    if (_json_result.ContainsKey("result"))
                    {
                        _json_success = _json_result["result"].Value <bool>();
                    }
                    else
                    {
                        _json_success = _json_result.Count > 0;
                    }

                    if (_json_success != true)
                    {
                        var _error_code = ErrorCode.ExchangeError;
                        var _error_msg  = _error_code.ToString();

                        _result.SetFailure(_error_msg, _error_code);
                    }
                }

                if (_result.success == true && response.IsSuccessful == false)
                {
                    _result.SetFailure(
                        response.ErrorMessage ?? response.StatusDescription,
                        ErrorCode.ResponseRestError,
                        (int)response.StatusCode,
                        false
                        );
                }
            }

            return(_result);
        }
Beispiel #11
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="response">response value arrive from exchange's server</param>
        /// <returns></returns>
        public override BoolResult GetResponseMessage(IRestResponse response = null)
        {
            var _result = new BoolResult();

            if (response != null)
            {
                if (response.IsSuccessful == false)
                {
                    var _json_result = this.DeserializeObject <JToken>(response.Content);

                    var _description = _json_result.SelectToken("description");
                    var _statusValue = _json_result.SelectToken("code");

                    if (_statusValue != null && _description != null)
                    {
                        var _json_message = _description.Value <string>();
                        var _json_code    = _statusValue.Value <int>();

                        _result.SetFailure(
                            _json_message,
                            ErrorCode.ResponseDataError,
                            _json_code
                            );
                    }
                }

                if (_result.success == true && response.IsSuccessful == false)
                {
                    _result.SetFailure(
                        response.ErrorMessage ?? response.StatusDescription,
                        ErrorCode.ResponseRestError,
                        (int)response.StatusCode,
                        false
                        );
                }
            }

            return(_result);
        }
Beispiel #12
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="response">response value arrive from exchange's server</param>
        /// <returns></returns>
        public override BoolResult GetResponseMessage(IRestResponse response = null)
        {
            var _result = new BoolResult();

            if (response != null)
            {
                if (response.IsSuccessful == true)
                {
                    var _json_result = this.DeserializeObject <JToken>(response.Content);

                    var _json_error = _json_result.SelectToken("code");
                    if (_json_error != null)
                    {
                        var _error_code = _json_error.Value <int>();
                        if (_error_code != 1000)
                        {
                            _result.SetFailure(
                                GetErrorMessage(_error_code),
                                ErrorCode.ResponseDataError,
                                _error_code
                                );
                        }
                    }
                }

                if (_result.success == true && response.IsSuccessful == false)
                {
                    _result.SetFailure(
                        response.ErrorMessage ?? response.StatusDescription,
                        ErrorCode.ResponseRestError,
                        (int)response.StatusCode,
                        false
                        );
                }
            }

            return(_result);
        }
Beispiel #13
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="response">response value arrive from exchange's server</param>
        /// <returns></returns>
        public override BoolResult GetResponseMessage(IRestResponse response = null)
        {
            var _result = new BoolResult();

            if (response != null)
            {
                if (response.IsSuccessful == true)
                {
                    var _json_result = this.DeserializeObject <JToken>(response.Content);

                    var _json_success = _json_result["result"];
                    if (_json_success != null)
                    {
                        if (_json_success.Value <string>() != "success")
                        {
                            _result.SetFailure(
                                _json_result["data"]["message"].Value <string>(),
                                ErrorCode.ResponseDataError
                                );
                        }
                    }
                }

                if (_result.success == true && response.IsSuccessful == false)
                {
                    _result.SetFailure(
                        response.ErrorMessage ?? response.StatusDescription,
                        ErrorCode.ResponseRestError,
                        (int)response.StatusCode,
                        false
                        );
                }
            }

            return(_result);
        }
Beispiel #14
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="response">response value arrive from exchange's server</param>
        /// <returns></returns>
        public override BoolResult GetResponseMessage(IRestResponse response = null)
        {
            var _result = new BoolResult();

            if (response != null)
            {
                var _error_code = ErrorCode.Success;
                var _error_msg  = "";

                if ((int)response.StatusCode == 418 || (int)response.StatusCode == 429)
                {
                    _error_code = ErrorCode.DDoSProtection;
                    _error_msg  = response.Content;
                }
                else if ((int)response.StatusCode >= 400)
                {
                    if (response.Content.IndexOf("Price * QTY is zero or less") >= 0)
                    {
                        _error_code = ErrorCode.InvalidOrder;
                        _error_msg  = "order cost = amount * price is zero or less " + response.Content;
                    }
                    else if (response.Content.IndexOf("LOT_SIZE") >= 0)
                    {
                        _error_code = ErrorCode.InvalidOrder;
                        _error_msg  = "order amount should be evenly divisible by lot size, use this.amountToLots (symbol, amount) " + response.Content;
                    }
                    else if (response.Content.IndexOf("PRICE_FILTER") >= 0)
                    {
                        _error_code = ErrorCode.InvalidOrder;
                        _error_msg  = "order price exceeds allowed price precision or invalid, use this.priceToPrecision (symbol, amount) " + response.Content;
                    }
                }

                if (_error_code == ErrorCode.Success)
                {
                    if (String.IsNullOrEmpty(response.Content) == false && response.Content[0] == '{')
                    {
                        var _json_result = this.DeserializeObject <JToken>(response.Content);

                        // check success value for wapi endpoints
                        // response in format {'msg': 'The coin does not exist.', 'success': true/false}

                        var _json_success = _json_result.SelectToken("success");
                        if (_json_success != null)
                        {
                            var _success = _json_success.Value <bool>();
                            if (_success == false)
                            {
                                var _json_message = _json_result.SelectToken("msg");
                                if (_json_message != null)
                                {
                                    var _msg = _json_message.Value <string>();
                                    _json_result = this.DeserializeObject <JToken>(_msg);
                                }
                            }
                        }

                        var _json_error = _json_result.SelectToken("code");
                        if (_json_error != null)
                        {
                            _result.statusCode = _json_error.Value <int>();

                            if (ErrorMessages.ContainsKey(_result.statusCode) == true)
                            {
                                // a workaround for {"code":-2015,"msg":"Invalid API-key, IP, or permissions for action."}
                                // despite that their message is very confusing, it is raised by Binance
                                // on a temporary ban (the API key is valid, but disabled for a while)

                                if (_result.statusCode == -2015 && this.ExchangeInfo.Options.hasAlreadyAuthenticatedSuccessfully == true)
                                {
                                    _error_code = ErrorCode.DDoSProtection;
                                    _error_msg  = "temporary banned: " + response.Content;
                                }
                                else
                                {
                                    var _json_message = _json_result.SelectToken("msg");
                                    if (_json_message != null)
                                    {
                                        var _msg = _json_message.Value <string>();

                                        if (_msg == "Order would trigger immediately.")
                                        {
                                            _error_code = ErrorCode.InvalidOrder;
                                            _error_msg  = response.Content;
                                        }
                                        else if (_msg == "Account has insufficient balance for requested action.")
                                        {
                                            _error_code = ErrorCode.InsufficientFunds;
                                            _error_msg  = response.Content;
                                        }
                                        else if (_msg == "Rest API trading is not enabled.")
                                        {
                                            _error_code = ErrorCode.ExchangeNotAvailable;
                                            _error_msg  = response.Content;
                                        }
                                    }

                                    if (_error_code == ErrorCode.Success)
                                    {
                                        _error_code = ErrorMessages[_result.statusCode];
                                        _error_msg  = response.Content;
                                    }
                                }
                            }
                            else
                            {
                                _error_code = ErrorCode.ExchangeError;
                                _error_msg  = "unknown error code: " + response.Content;
                            }
                        }
                        else if (_result.success == false)
                        {
                            _error_code = ErrorCode.ExchangeError;
                            _error_msg  = "success value false: " + response.Content;
                        }
                    }
                }

                if (_error_code != ErrorCode.Success)
                {
                    _result.SetFailure(_error_msg, _error_code);
                }

                if (_result.success == true && response.IsSuccessful == false)
                {
                    _result.SetFailure(
                        response.ErrorMessage ?? response.StatusDescription,
                        ErrorCode.ResponseRestError,
                        (int)response.StatusCode,
                        false
                        );
                }
            }

            return(_result);
        }
Beispiel #15
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="response">response value arrive from exchange's server</param>
        /// <returns></returns>
        public override BoolResult GetResponseMessage(IRestResponse response = null)
        {
            var _result = new BoolResult();

            if (response != null)
            {
                if (response.IsSuccessful == true)
                {
                    var _json_result = this.DeserializeObject <JToken>(response.Content);

                    var _json_error = _json_result.SelectToken("error");
                    if (_json_error != null && _json_error.Count() > 0)
                    {
                        var _message = "";
                        {
                            if (_json_error.GetType() == typeof(JArray))
                            {
                                if (_json_error.Count() > 0)
                                {
                                    _message = _json_error[0].Value <string>();
                                }
                            }
                            else if (_json_error.GetType() == typeof(JValue))
                            {
                                _message = _json_error.Value <string>();
                            }
                        }

                        if (String.IsNullOrEmpty(_message) == false)
                        {
                            var _error_code = ErrorMessages
                                              .Where(e => _message.IndexOf(e.Key) >= 0)
                                              .OrderByDescending(e => e.Key.Length)
                                              .FirstOrDefault();

                            if (_error_code.Key != null)
                            {
                                _result.errorCode = _error_code.Value;
                            }
                            else
                            {
                                _result.errorCode = ErrorCode.ResponseDataError;
                            }

                            _result.SetFailure(
                                _message,
                                _result.errorCode
                                );
                        }
                        else
                        {
                            var _token_result = _json_result.SelectToken("result");
                            if (_token_result == null ||
                                (
                                    _token_result != null &&
                                    _token_result.GetType() == typeof(JArray) &&
                                    _token_result.Count() <= 0
                                )
                                )
                            {
                                _result.SetFailure(errorCode: ErrorCode.NotFoundData);
                            }
                        }
                    }
                }

                if (_result.success == true && response.IsSuccessful == false)
                {
                    _result.SetFailure(
                        response.ErrorMessage ?? response.StatusDescription,
                        ErrorCode.ResponseRestError,
                        (int)response.StatusCode,
                        false
                        );
                }
            }

            return(_result);
        }
Beispiel #16
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="response">response value arrive from exchange's server</param>
        /// <returns></returns>
        public override BoolResult GetResponseMessage(IRestResponse response = null)
        {
            var _result = new BoolResult();

            if (response != null)
            {
                if (String.IsNullOrEmpty(response.Content) == false && response.Content[0] == '{')
                {
                    var _error_code = ErrorCode.ExchangeError;
                    var _error_msg  = "";

                    var _json_result = this.DeserializeObject <JToken>(response.Content);     // { success: false, message: "message" }
                    if (_json_result != null)
                    {
                        var _success = _json_result["success"].Value <bool>();
                        if (_success == false)
                        {
                            _error_msg = _json_result["message"].Value <string>();

                            if (_error_msg == "APIKEY_INVALID")
                            {
                                _error_code = ErrorCode.DDoSProtection;
                                _error_msg  = response.Content;
                            }
                            else if (_error_msg == "DUST_TRADE_DISALLOWED_MIN_VALUE_50K_SAT")
                            {
                                _error_code = ErrorCode.InvalidOrder;
                                _error_msg  = "order cost should be over 50k satoshi: " + response.Content;
                            }
                            else if (_error_msg == "INVALID_ORDER")
                            {
                                // Bittrex will return an ambiguous INVALID_ORDER message
                                // upon canceling already-canceled and closed orders
                                // therefore this special case for cancelOrder
                                // let url = 'https://bittrex.com/api/v1.1/market/cancel?apikey=API_KEY&uuid=ORDER_UUID'
                                if (response.ResponseUri.AbsoluteUri.IndexOf("cancel") >= 0)
                                {
                                    var _ulrs = response.ResponseUri.AbsoluteUri.Split('?');
                                    if (_ulrs.Length > 1)
                                    {
                                        var _parts = _ulrs[1].Split('&');

                                        var _order_id = "";
                                        foreach (var _part in _parts)
                                        {
                                            var _key_value = _part.Split('=');
                                            if (_key_value[0] == "uuid")
                                            {
                                                _order_id = _key_value[1];
                                                break;
                                            }
                                        }

                                        _error_code = ErrorCode.OrderNotFound;

                                        if (String.IsNullOrEmpty(_order_id) == false)
                                        {
                                            _error_msg = $"cancelOrder: {_order_id} => " + response.Content;
                                        }
                                        else
                                        {
                                            _error_msg = $"cancelOrder: " + response.Content;
                                        }
                                    }
                                }
                            }
                            else if (ErrorMessages.ContainsKey(_error_msg) == true)
                            {
                                _error_code = ErrorMessages[_error_msg];
                                _error_msg  = response.Content;
                            }
                            else if (String.IsNullOrEmpty(_error_msg) == false)
                            {
                                if (_error_msg.IndexOf("throttled. Try again") >= 0)
                                {
                                    _error_code = ErrorCode.DDoSProtection;
                                    _error_msg  = response.Content;
                                }
                                else if (_error_msg.IndexOf("problem") >= 0)
                                {
                                    _error_code = ErrorCode.ExchangeNotAvailable;   // 'There was a problem processing your request.  If this problem persists, please contact...')
                                    _error_msg  = response.Content;
                                }
                            }

                            _result.SetFailure(_error_msg, _error_code);
                        }
                    }
                    else
                    {
                        _error_msg = "malformed response: " + response.Content;
                        _result.SetFailure(_error_msg, _error_code);
                    }
                }

                if (_result.success == true && response.IsSuccessful == false)
                {
                    _result.SetFailure(
                        response.ErrorMessage ?? response.StatusDescription,
                        ErrorCode.ResponseRestError,
                        (int)response.StatusCode,
                        false
                        );
                }
            }

            return(_result);
        }
Beispiel #17
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="response">response value arrive from exchange's server</param>
        /// <returns></returns>
        public override BoolResult GetResponseMessage(IRestResponse response = null)
        {
            var _result = new BoolResult();

            if (response != null)
            {
                if (response.IsSuccessful == false) // (int) StatusCode >= 200 && (int) StatusCode <= 299 && ResponseStatus == ResponseStatus.Completed;
                {
                    if ((int)response.StatusCode != 429)
                    {
                        if (String.IsNullOrEmpty(response.Content) == false && response.Content[0] == '{')
                        {
                            var _json_result = this.DeserializeObject <JToken>(response.Content);

                            var _json_error = _json_result.SelectToken("error");
                            if (_json_error != null)
                            {
                                var _json_message = _json_error.SelectToken("message");
                                if (_json_message != null)
                                {
                                    var _error_code = ErrorCode.ExchangeError;

                                    var _error_msg = _json_message.Value <string>();
                                    if (String.IsNullOrEmpty(_error_msg) == false)
                                    {
                                        if (ErrorMessages.ContainsKey(_error_msg) == true)
                                        {
                                            _error_code = ErrorMessages[_error_msg];
                                        }
                                    }
                                    else
                                    {
                                        _error_msg = response.Content;
                                    }

                                    _result.SetFailure(_error_msg, _error_code);
                                }
                            }
                        }
                    }
                    else
                    {
                        _result.SetFailure(
                            response.ErrorMessage ?? response.StatusDescription,
                            ErrorCode.DDoSProtection,
                            (int)response.StatusCode,
                            false
                            );
                    }
                }

                if (_result.success == true && response.IsSuccessful == false)
                {
                    _result.SetFailure(
                        response.ErrorMessage ?? response.StatusDescription,
                        ErrorCode.ResponseRestError,
                        (int)response.StatusCode,
                        false
                        );
                }
            }

            return(_result);
        }
Beispiel #18
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="response">response value arrive from exchange's server</param>
        /// <returns></returns>
        public override BoolResult GetResponseMessage(IRestResponse response = null)
        {
            var _result = new BoolResult();

            if (response != null)
            {
                if (String.IsNullOrEmpty(response.Content) == false && (response.Content[0] == '{' || response.Content[0] == '['))
                {
                    var _json_result = this.DeserializeObject <JToken>(response.Content);

                    var _error_code = ErrorCode.ExchangeError;
                    var _error_msg  = response.Content;

                    var _json_error = _json_result.SelectToken("error");
                    if (_json_error != null)
                    {
                        var _error = _json_error.Value <string>();
                        if (String.IsNullOrEmpty(_error) == false)
                        {
                            if (ErrorMessages.ContainsKey(_error) == true)
                            {
                                _error_code = ErrorMessages[_error];
                            }

                            _error_msg = _error;
                        }

                        _result.SetFailure(_error_msg, _error_code);
                    }

                    if (_result.success == true)
                    {
                        var _json_status = _json_result.SelectToken("status");
                        if (_json_status != null)
                        {
                            var _status = _json_status.Value <string>();
                            if (_status == "error")
                            {
                                var _json_code = _json_result.SelectToken("code");
                                if (_json_code != null)
                                {
                                    var _code = _json_code.Value <string>();
                                    if (_code == "API0005")
                                    {
                                        _error_code = ErrorCode.AuthenticationError;
                                        _error_msg  = "invalid signature, use the uid for the main account if you have subaccounts";
                                    }
                                }

                                _result.SetFailure(_error_msg, _error_code);
                            }
                        }
                    }
                }

                if (_result.success == true && response.IsSuccessful == false)
                {
                    _result.SetFailure(
                        response.ErrorMessage ?? response.StatusDescription,
                        ErrorCode.ResponseRestError,
                        (int)response.StatusCode,
                        false
                        );
                }
            }

            return(_result);
        }
Beispiel #19
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="response">response value arrive from exchange's server</param>
        /// <returns></returns>
        public override BoolResult GetResponseMessage(IRestResponse response = null)
        {
            var _result = new BoolResult();

            if (response != null)
            {
                if (String.IsNullOrEmpty(response.Content) == false && response.Content != "[]")
                {
                    if (response.IsSuccessful == false && response.Content[0] == '{')
                    {
                        var _json_result = this.DeserializeObject <JToken>(response.Content);

                        var _json_status = _json_result.SelectToken("status");
                        if (_json_status == null || (_json_status != null && _json_status.Value <string>() != "success"))
                        {
                            var _message = "";

                            var _json_error = _json_result.SelectToken("error");

                            var _json_message = _json_result.SelectToken("message");
                            if (_json_message != null)
                            {
                                _message = _json_message.Value <string>();
                            }
                            else if (_json_error != null)
                            {
                                _message = _json_error.Value <string>();
                            }
                            else
                            {
                                _result.SetFailure(
                                    response.Content,
                                    ErrorCode.ResponseDataError
                                    );
                            }

                            if (String.IsNullOrEmpty(_message) == false)
                            {
                                var _error_code = ErrorMessages
                                                  .Where(e => _message.IndexOf(e.Key) >= 0)
                                                  .OrderByDescending(e => e.Key.Length)
                                                  .FirstOrDefault();

                                if (_error_code.Key != null)
                                {
                                    _result.errorCode = _error_code.Value;
                                }
                                else
                                {
                                    _result.errorCode = ErrorCode.ResponseDataError;
                                }

                                _result.SetFailure(
                                    _message,
                                    _result.errorCode
                                    );
                            }
                        }
                    }
                }

                if (_result.success == true && response.IsSuccessful == false)
                {
                    _result.SetFailure(
                        response.ErrorMessage ?? response.StatusDescription,
                        ErrorCode.ResponseRestError,
                        (int)response.StatusCode,
                        false
                        );
                }
            }

            return(_result);
        }