Ejemplo n.º 1
0
        internal dynamic SendRequest(string url, MethodsType method    = MethodsType.GET,
                                     Dictionary <string, string> query = null, object objectToSend = null)
        {
            SendRequestAndGetResponse(method, url, query, objectToSend);

            return(TryGetResponseDynamic(client));
        }
Ejemplo n.º 2
0
        internal Excepted SendRequest <Excepted>(string url, MethodsType method    = MethodsType.GET,
                                                 Dictionary <string, string> query = null, object objectToSend = null)
        {
            SendRequestAndGetResponse(method, url, query, objectToSend);

            return(TryGetResponse <Excepted>(client));
        }
Ejemplo n.º 3
0
            public WhereOptions(MethodsType methodType, string[] parameters, string property, bool exact = false)
            {
                Method = new WhereMethodCall
                {
                    MethodType = methodType,
                    Parameters = parameters,
                    Property   = property
                };

                Exact = exact;
            }
Ejemplo n.º 4
0
        internal Excepted SendRequest <Excepted>(string url, MethodsType method    = MethodsType.GET,
                                                 Dictionary <string, string> query = null, object objectToSend = null, ICustomDeserializer <Excepted> customDeserializer = null)
        {
            SendRequestAndGetResponse(method, url, query, objectToSend);

            if (customDeserializer == null)
            {
                return(TryGetResponse <Excepted>(client));
            }
            else
            {
                return(TryGetResponseWithCustomDeserializer <Excepted>(client, customDeserializer));
            }
        }
Ejemplo n.º 5
0
        void SendRequestAndGetResponse(MethodsType method, string url, Dictionary <string, string> query = null, object objectToSend = null)
        {
            client = new RestClient(url);
            string queryString = "";

            if (query != null)
            {
                queryString = client.AddQuery(query);
            }

            Autorize(queryString);

            client.Send(method, objectToSend);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Send request with data using checked method.
        /// </summary>
        /// <param name="method">Method type.</param>
        /// <param name="objectToSend">Data to send.</param>
        public void Send(MethodsType method, object objectToSend = null, bool serializeDataToSend = true)
        {
            if (method != MethodsType.POST || method != MethodsType.PUT)
            {
                Send(method);
            }

            switch (method)
            {
            case MethodsType.POST:
                SendPOST(objectToSend, serializeDataToSend);
                break;

            case MethodsType.PUT:
                SendPUT(objectToSend, serializeDataToSend);
                break;
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Send request using checked method.
        /// </summary>
        /// <param name="method">Method type.</param>
        public void Send(MethodsType method)
        {
            switch (method)
            {
            case MethodsType.GET:
                SendGET();
                break;

            case MethodsType.DELETE:
                SendDELETE();
                break;

            case MethodsType.POST:
                SendPOST <object>(null);
                break;

            case MethodsType.PUT:
                SendPUT <object>(null);
                break;
            }
        }
Ejemplo n.º 8
0
        void SendRequestAndGetResponse(MethodsType method, string url, Dictionary <string, string> query = null, object objectToSend = null)
        {
            if (method != MethodsType.POST)
            {
                client = new RestClient(url);
            }
            else
            {
                client = new RestClient(url, "application/x-www-form-urlencoded");
            }

            Dictionary <string, string> newQuery = AddTwoDictionary(query, this.query);

            string bodyString = AddQueryAndAutorize(method, newQuery, objectToSend);

            if (bodyString == string.Empty)
            {
                client.Send(method);
            }
            else
            {
                client.Send(method, bodyString, false);
            }
        }
Ejemplo n.º 9
0
        string AddQueryAndAutorize(MethodsType method, Dictionary <string, string> query = null, object objectBody = null)
        {
            if (autorization == Autorization.NONE)
            {
                client.AddQuery(query);
            }
            else if (autorization == Autorization.MARKET)
            {
                if (!session.IsMarketAutorized)
                {
                    throw new UnautorizedClientException("Client is unautorized, use SetAutorizationData() method for autorize client, " +
                                                         "method required public api key.");
                }

                client.AddQuery(query);
                client.AddOwnHeaderToRequest("X-MBX-APIKEY", session.PublicKey);
            }
            else if (autorization == Autorization.TRADING)
            {
                if (!session.IsTradingAutorized)
                {
                    throw new UnautorizedClientException("Client is unautorized, use SetAutorizationData() method for autorize client, " +
                                                         "method required public and private api key.");
                }

                client.AddOwnHeaderToRequest("X-MBX-APIKEY", session.PublicKey);

                string totalParmas = string.Empty;

                if (query != null)
                {
                    totalParmas += client.AddQuery(query);
                }

                string body = string.Empty;
                if (objectBody != null)
                {
                    body = ObjectToQueryConverter.Convert(objectBody);

                    if (method != MethodsType.POST)
                    {
                        totalParmas += client.AddStringToEndOfQuery("&" + body);
                    }
                    else
                    {
                        totalParmas += body;
                    }
                }
                else
                {
                    if (method == MethodsType.POST)
                    {
                        body         = "null";
                        totalParmas += body;
                    }
                }

                if (query != null)
                {
                    client.AddStringToEndOfQuery("&signature=" + HashManager.HashHMACHex(session.PrivateKey, totalParmas.Substring(1)));
                }
                else
                {
                    client.AddStringToEndOfQuery("?signature=" + HashManager.HashHMACHex(session.PrivateKey, totalParmas.Substring(1)));
                }

                if (method == MethodsType.POST)
                {
                    return(body);
                }
            }

            return("");
        }