From 6e0e1c116bf9858052c9089ab3b19485fd7e11c3 Mon Sep 17 00:00:00 2001 From: nanoric Date: Thu, 11 Oct 2018 22:51:31 -0400 Subject: [PATCH] =?UTF-8?q?[Mod]=20=E5=B0=86RestClient=E5=92=8CWebClient?= =?UTF-8?q?=E7=A7=BB=E5=8A=A8=E5=88=B0api=E6=96=87=E4=BB=B6=E5=A4=B9?= =?UTF-8?q?=E4=B8=AD=EF=BC=8C=E5=B9=B6=E4=BF=AE=E6=94=B9import=E6=96=B9?= =?UTF-8?q?=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/all_test.py | 3 +-- tests/{network => api}/__init__.py | 0 .../base/RestClientTest.py} | 2 +- tests/{network => api/base}/WebSocketClientTest.py | 3 +-- {vnpy/network => tests/api/base}/__init__.py | 0 vnpy/api/okexfuture/OkexFutureApi.py | 2 +- vnpy/api/okexfuture/vnokexFuture.py | 2 +- vnpy/{network => api/rest}/RestClient.py | 0 vnpy/api/rest/__init__.py | 1 + vnpy/{network => api/websocket}/WebSocketClient.py | 10 +++++----- vnpy/api/websocket/__init__.py | 1 + 11 files changed, 12 insertions(+), 12 deletions(-) rename tests/{network => api}/__init__.py (100%) rename tests/{network/RestfulClientTest.py => api/base/RestClientTest.py} (97%) rename tests/{network => api/base}/WebSocketClientTest.py (92%) rename {vnpy/network => tests/api/base}/__init__.py (100%) rename vnpy/{network => api/rest}/RestClient.py (100%) create mode 100644 vnpy/api/rest/__init__.py rename vnpy/{network => api/websocket}/WebSocketClient.py (91%) create mode 100644 vnpy/api/websocket/__init__.py diff --git a/tests/all_test.py b/tests/all_test.py index d8480b5f..44d1f1df 100644 --- a/tests/all_test.py +++ b/tests/all_test.py @@ -1,8 +1,7 @@ import unittest # noinspection PyUnresolvedReferences -from tests.network.RestfulClientTest import * -from tests.network.WebSocketClientTest import * +from api.base import * if __name__ == "__main__": unittest.main() diff --git a/tests/network/__init__.py b/tests/api/__init__.py similarity index 100% rename from tests/network/__init__.py rename to tests/api/__init__.py diff --git a/tests/network/RestfulClientTest.py b/tests/api/base/RestClientTest.py similarity index 97% rename from tests/network/RestfulClientTest.py rename to tests/api/base/RestClientTest.py index 9aa711f4..36da9289 100644 --- a/tests/network/RestfulClientTest.py +++ b/tests/api/base/RestClientTest.py @@ -6,7 +6,7 @@ import unittest from simplejson import JSONDecodeError from Promise import Promise -from vnpy.network.RestClient import RestClient, Request +from vnpy.api.rest.RestClient import RestClient, Request class FailedError(RuntimeError): diff --git a/tests/network/WebSocketClientTest.py b/tests/api/base/WebSocketClientTest.py similarity index 92% rename from tests/network/WebSocketClientTest.py rename to tests/api/base/WebSocketClientTest.py index 4337a3c0..8361f647 100644 --- a/tests/network/WebSocketClientTest.py +++ b/tests/api/base/WebSocketClientTest.py @@ -1,9 +1,8 @@ # encoding: UTF-8 -import json import unittest from Promise import Promise -from vnpy.network.WebSocketClient import WebsocketClient +from vnpy.api.websocket import WebsocketClient class TestWebsocketClient(WebsocketClient): diff --git a/vnpy/network/__init__.py b/tests/api/base/__init__.py similarity index 100% rename from vnpy/network/__init__.py rename to tests/api/base/__init__.py diff --git a/vnpy/api/okexfuture/OkexFutureApi.py b/vnpy/api/okexfuture/OkexFutureApi.py index b0c9787b..54b53ec2 100644 --- a/vnpy/api/okexfuture/OkexFutureApi.py +++ b/vnpy/api/okexfuture/OkexFutureApi.py @@ -3,7 +3,7 @@ from enum import Enum from typing import Any, Callable, List, Union from vnpy.api.okexfuture.vnokexFuture import OkexFutureRestBase -from vnpy.network.RestClient import Request +from vnpy.api.rest import Request ######################################################################## diff --git a/vnpy/api/okexfuture/vnokexFuture.py b/vnpy/api/okexfuture/vnokexFuture.py index 0553827d..535ea7af 100644 --- a/vnpy/api/okexfuture/vnokexFuture.py +++ b/vnpy/api/okexfuture/vnokexFuture.py @@ -4,7 +4,7 @@ import urllib ######################################################################## -from vnpy.network.RestClient import RestClient, Request +from vnpy.api.rest import RestClient, Request ######################################################################## diff --git a/vnpy/network/RestClient.py b/vnpy/api/rest/RestClient.py similarity index 100% rename from vnpy/network/RestClient.py rename to vnpy/api/rest/RestClient.py diff --git a/vnpy/api/rest/__init__.py b/vnpy/api/rest/__init__.py new file mode 100644 index 00000000..f0cbea27 --- /dev/null +++ b/vnpy/api/rest/__init__.py @@ -0,0 +1 @@ +from .RestClient import Request, RequestStatus, RestClient, requestsSessionProvider diff --git a/vnpy/network/WebSocketClient.py b/vnpy/api/websocket/WebSocketClient.py similarity index 91% rename from vnpy/network/WebSocketClient.py rename to vnpy/api/websocket/WebSocketClient.py index f969cfa6..12cbfca5 100644 --- a/vnpy/network/WebSocketClient.py +++ b/vnpy/api/websocket/WebSocketClient.py @@ -9,7 +9,7 @@ import time from abc import abstractmethod from threading import Thread, Lock -import websocket +import vnpy.api.websocket class WebsocketClient(object): @@ -57,12 +57,12 @@ class WebsocketClient(object): #---------------------------------------------------------------------- def sendReq(self, req): # type: (dict)->None """发出请求""" - return self._get_ws().send(json.dumps(req), opcode=websocket.ABNF.OPCODE_TEXT) + return self._get_ws().send(json.dumps(req), opcode=vnpy.api.websocket.ABNF.OPCODE_TEXT) #---------------------------------------------------------------------- def sendText(self, text): # type: (str)->None """发出请求""" - return self._get_ws().send(text, opcode=websocket.ABNF.OPCODE_TEXT) + return self._get_ws().send(text, opcode=vnpy.api.websocket.ABNF.OPCODE_TEXT) #---------------------------------------------------------------------- def sendData(self, data): # type: (bytes)->None @@ -78,7 +78,7 @@ class WebsocketClient(object): #---------------------------------------------------------------------- def _connect(self): """""" - self._ws = websocket.create_connection(self.host, sslopt={'cert_reqs': ssl.CERT_NONE}) + self._ws = vnpy.api.websocket.create_connection(self.host, sslopt={'cert_reqs': ssl.CERT_NONE}) self.onConnect() #---------------------------------------------------------------------- @@ -125,7 +125,7 @@ class WebsocketClient(object): #---------------------------------------------------------------------- def _ping(self): - return self._get_ws().send('ping', websocket.ABNF.OPCODE_PING) + return self._get_ws().send('ping', vnpy.api.websocket.ABNF.OPCODE_PING) #---------------------------------------------------------------------- @abstractmethod diff --git a/vnpy/api/websocket/__init__.py b/vnpy/api/websocket/__init__.py new file mode 100644 index 00000000..3e58eeb4 --- /dev/null +++ b/vnpy/api/websocket/__init__.py @@ -0,0 +1 @@ +from .WebSocketClient import WebsocketClient