[Mod] HttpClient改名为RestClient
This commit is contained in:
parent
f0aa9c7172
commit
e6f7781a47
@ -6,18 +6,18 @@ import unittest
|
|||||||
from simplejson import JSONDecodeError
|
from simplejson import JSONDecodeError
|
||||||
|
|
||||||
from Promise import Promise
|
from Promise import Promise
|
||||||
from vnpy.network.HttpClient import HttpClient, Request
|
from vnpy.network.RestClient import RestClient, Request
|
||||||
|
|
||||||
|
|
||||||
class FailedError(RuntimeError):
|
class FailedError(RuntimeError):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class TestHttpClient(HttpClient):
|
class TestRestClient(RestClient):
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
urlBase = 'https://httpbin.org'
|
urlBase = 'https://httpbin.org'
|
||||||
super(TestHttpClient, self).__init__()
|
super(TestRestClient, self).__init__()
|
||||||
self.init(urlBase)
|
self.init(urlBase)
|
||||||
|
|
||||||
self.p = Promise()
|
self.p = Promise()
|
||||||
@ -37,7 +37,7 @@ class TestHttpClient(HttpClient):
|
|||||||
class RestfulClientTest(unittest.TestCase):
|
class RestfulClientTest(unittest.TestCase):
|
||||||
|
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.c = TestHttpClient()
|
self.c = TestRestClient()
|
||||||
self.c.start()
|
self.c.start()
|
||||||
|
|
||||||
def tearDown(self):
|
def tearDown(self):
|
||||||
|
@ -4,15 +4,15 @@ import urllib
|
|||||||
|
|
||||||
|
|
||||||
########################################################################
|
########################################################################
|
||||||
from vnpy.network.HttpClient import HttpClient, Request
|
from vnpy.network.RestClient import RestClient, Request
|
||||||
|
|
||||||
|
|
||||||
########################################################################
|
########################################################################
|
||||||
class OkexFutureHttpClient(HttpClient):
|
class OkexFutureRestClient(RestClient):
|
||||||
|
|
||||||
#----------------------------------------------------------------------
|
#----------------------------------------------------------------------
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super(OkexFutureHttpClient, self).__init__()
|
super(OkexFutureRestClient, self).__init__()
|
||||||
self.apiKey = None
|
self.apiKey = None
|
||||||
self.apiSecret = None
|
self.apiSecret = None
|
||||||
|
|
||||||
@ -20,7 +20,7 @@ class OkexFutureHttpClient(HttpClient):
|
|||||||
# noinspection PyMethodOverriding
|
# noinspection PyMethodOverriding
|
||||||
def init(self, apiKey, apiSecret):
|
def init(self, apiKey, apiSecret):
|
||||||
# type: (str, str) -> any
|
# type: (str, str) -> any
|
||||||
super(OkexFutureHttpClient, self).init('https://www.okex.com/api/v1')
|
super(OkexFutureRestClient, self).init('https://www.okex.com/api/v1')
|
||||||
self.apiKey = apiKey
|
self.apiKey = apiKey
|
||||||
self.apiSecret = apiSecret
|
self.apiSecret = apiSecret
|
||||||
|
|
||||||
|
@ -70,9 +70,9 @@ class Request(object):
|
|||||||
|
|
||||||
|
|
||||||
########################################################################
|
########################################################################
|
||||||
class HttpClient(object):
|
class RestClient(object):
|
||||||
"""
|
"""
|
||||||
HTTP 客户端。目前是为了对接各种RESTFulAPI而设计的。
|
HTTP 客户端。目前是为了对接各种RESTfulAPI而设计的。
|
||||||
|
|
||||||
如果需要给请求加上签名,请重载beforeRequest函数。
|
如果需要给请求加上签名,请重载beforeRequest函数。
|
||||||
如果需要处理非200的请求,请重载onFailed函数。
|
如果需要处理非200的请求,请重载onFailed函数。
|
@ -5,8 +5,8 @@ from __future__ import print_function
|
|||||||
import json
|
import json
|
||||||
from abc import abstractmethod, abstractproperty
|
from abc import abstractmethod, abstractproperty
|
||||||
|
|
||||||
from vnpy.api.okexfuture.vnokexFuture import OkexFutureHttpClient
|
from vnpy.api.okexfuture.vnokexFuture import OkexFutureRestClient
|
||||||
from vnpy.network.HttpClient import Request
|
from vnpy.network.RestClient import Request
|
||||||
from vnpy.trader.vtFunction import getJsonPath
|
from vnpy.trader.vtFunction import getJsonPath
|
||||||
from vnpy.trader.vtGateway import *
|
from vnpy.trader.vtGateway import *
|
||||||
|
|
||||||
@ -351,7 +351,7 @@ class OkexFutureApi(ApiBase):
|
|||||||
self.gateway = gateway # type: OkexFutureGateway
|
self.gateway = gateway # type: OkexFutureGateway
|
||||||
|
|
||||||
self.localID = 0
|
self.localID = 0
|
||||||
self.client = OkexFutureHttpClient()
|
self.client = OkexFutureRestClient()
|
||||||
|
|
||||||
#----------------------------------------------------------------------
|
#----------------------------------------------------------------------
|
||||||
def onOrderSent(self, data, req): # type: (dict, Request)->None
|
def onOrderSent(self, data, req): # type: (dict, Request)->None
|
||||||
|
Loading…
Reference in New Issue
Block a user