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