[Mod] HttClient:修改对应的测试
[Del] 删除了HeadersAuthenticateHttpClient,因为不再需要了 该版本的测试可以通过
This commit is contained in:
parent
5d0de90e60
commit
486e6055e6
@ -6,7 +6,7 @@ import unittest
|
||||
from simplejson import JSONDecodeError
|
||||
|
||||
from Promise import Promise
|
||||
from vnpy.network.HttpClient import HttpClient
|
||||
from vnpy.network.HttpClient import HttpClient, Request
|
||||
|
||||
|
||||
class FailedError(RuntimeError):
|
||||
@ -22,9 +22,10 @@ class TestHttpClient(HttpClient):
|
||||
|
||||
self.p = Promise()
|
||||
|
||||
def beforeRequest(self, method, path, params, data):
|
||||
data = json.dumps(data)
|
||||
return method, path, params, data, {'Content-Type': 'application/json'}
|
||||
def beforeRequest(self, req): #type: (Request)->Request
|
||||
req.data = json.dumps(req.data)
|
||||
req.headers = {'Content-Type': 'application/json'}
|
||||
return req
|
||||
|
||||
def onError(self, exceptionType, exceptionValue, tb, req):
|
||||
self.p.set_exception(exceptionValue)
|
||||
|
@ -4,7 +4,7 @@ import urllib
|
||||
|
||||
|
||||
########################################################################
|
||||
from vnpy.network.HttpClient import HttpClient
|
||||
from vnpy.network.HttpClient import HttpClient, Request
|
||||
|
||||
|
||||
########################################################################
|
||||
@ -25,9 +25,9 @@ class OkexFutureHttpClient(HttpClient):
|
||||
self.apiSecret = apiSecret
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
def beforeRequest(self, method, path, params, data): # type: (str, str, dict, dict)->(str, str, dict, dict, dict)
|
||||
args = params or {}
|
||||
args.update(data or {})
|
||||
def beforeRequest(self, req): # type: (Request)->Request
|
||||
args = req.params or {}
|
||||
args.update(req.data or {})
|
||||
if 'sign' in args:
|
||||
args.pop('sign')
|
||||
if 'apiKey' not in args:
|
||||
@ -38,5 +38,6 @@ class OkexFutureHttpClient(HttpClient):
|
||||
sign = hashlib.md5(data.encode()).hexdigest().upper()
|
||||
data += "&sign=" + sign
|
||||
|
||||
return method, path, params, data, {'Content-Type': 'application/x-www-form-urlencoded'}
|
||||
req.headers = {'Content-Type': 'application/x-www-form-urlencoded'}
|
||||
return req
|
||||
|
||||
|
@ -1,38 +0,0 @@
|
||||
# encoding: UTF-8
|
||||
|
||||
|
||||
########################################################################
|
||||
from abc import abstractmethod
|
||||
|
||||
from vnpy.network.HttpClient import HttpClient
|
||||
|
||||
|
||||
########################################################################
|
||||
class HeadersAuthenticateHttpClient(HttpClient):
|
||||
"""
|
||||
该类简化了RESTFulAPI客户端的重载。
|
||||
该类提供了一个setUser函数,可以方便地设置apiKey和apiSecret。
|
||||
使用self.apiKey和self.apiSecret便可以访问设置后的值
|
||||
要建立一个签名在HTTP Headers的RESTFul客户端,继承该类并重载authencitate即可。
|
||||
"""
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
def __init__(self):
|
||||
super(HeadersAuthenticateHttpClient, self).__init__()
|
||||
self.apiKey = None # type: str
|
||||
self.apiSecret = None # type: str
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
def beforeRequest(self, method, path, params, data): # type: (str, str, dict, dict)->(str, str, dict, dict, dict)
|
||||
return method, path, params, data, self.onAuthenticate(method, path, params, data)
|
||||
|
||||
#----------------------------------------------------------------------
|
||||
@abstractmethod
|
||||
def onAuthenticate(self, method, path, params, data):
|
||||
"""
|
||||
重载该函数以添加签名到头部
|
||||
该函数在每个请求之前都会被调用。
|
||||
@:return dict 返回的数据会被加入到HTTP请求头部中
|
||||
|
||||
"""
|
||||
return {}
|
Loading…
Reference in New Issue
Block a user