测试托管者与交易所服务器的真实网络延迟/ 支持同时测试多个交易所
0
Follow
14
Followers
Contact : [email protected] / WeChat@stay37
本策略为测试托管者到服务器之间的真实网络延迟,测试方法为:对比发送请求的时间和收到结果的时间,多次取平均值。
支持多个交易所同时测试,添加不同交易平台即可,需要安装numpy模块。
Source
Python
# Contact : [email protected] / WeChat@stay37
import time
import numpy as np
def test():
#延迟数据接收器
delay_list = []
for i in range(len(exchanges)):
delay_list.append([])
while True:
#延迟数据获取
for i in range(len(exchanges)):
send_t = time.time()
ticker = exchanges[i].GetTicker()
delay_list[i].append(round((time.time() - send_t) * 1000 , 2))
#数据输出
delay_table = {"type":'table',"title":'延迟数据',"cols": ['账号序号','最近一次延迟','平均延迟','已测试次数'],"rows":[]}
for i in range(len(delay_list)):
delay_table['rows'].append([i + 1, str(delay_list[i][-1])+' ms', str(round(np.mean(delay_list[i]) , 2)) + ' ms', len(delay_list[i])])
LogStatus("输出的延迟为:发送一次get_ticker请求到获取到数据的真实时间" + "\n" + "`" + json.dumps(delay_table) + "`")
time.sleep(0.05)
def main():
for i in range(len(exchanges)):
exchanges[i].SetContractType('swap')
test()
Related strategies
Comment
All comments (1)
本机安装了numpy模块, 测试也没问题 ,可是fmz上依然提示 line 4, in <module> ModuleNotFoundError: No module named 'numpy'
~$ python
Python 2.7.17 (default, Sep 30 2020, 13:38:04)
[GCC 7.5.0] on linux2
Type "help", "copyright", "credits" or "license" for more information.
import numpy
exit()
6 years ago
- 1
