From 66cdf33b2343dd2d48b7224c449547363fdc4c41 Mon Sep 17 00:00:00 2001 From: "vn.py" Date: Wed, 8 May 2019 11:19:21 +0800 Subject: [PATCH] [Add] sync request function of RestClient --- vnpy/api/rest/rest_client.py | 40 +++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/vnpy/api/rest/rest_client.py b/vnpy/api/rest/rest_client.py index 7ae2c386..255ba35f 100644 --- a/vnpy/api/rest/rest_client.py +++ b/vnpy/api/rest/rest_client.py @@ -30,7 +30,7 @@ class Request(object): params: dict, data: dict, headers: dict, - callback: Callable, + callback: Callable = None, on_failed: Callable = None, on_error: Callable = None, extra: Any = None, @@ -284,3 +284,41 @@ class RestClient(object): """ url = self.url_base + path return url + + def request( + self, + method: str, + path: str, + params: dict = None, + data: dict = None, + headers: dict = None, + ): + """ + Add a new request. + :param method: GET, POST, PUT, DELETE, QUERY + :param path: + :param params: dict for query string + :param data: dict for body + :param headers: dict for headers + :return: requests.Response + """ + request = Request( + method, + path, + params, + data, + headers + ) + request = self.sign(request) + + url = self.make_full_url(request.path) + + response = requests.request( + request.method, + url, + headers=request.headers, + params=request.params, + data=request.data, + proxies=self.proxies, + ) + return response