Contact : ck@xueqiubot.com/ WeChat@stay37 This policy tests the real network latency between the host and the server by averaging the time between sending the request and receiving the result multiple times. It supports simultaneous testing of multiple exchanges, and adding different trading platforms requires the installation of a numpy module.
# Contact : ck@xueqiubot.com / 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()
High suction low throwThe numpy module is installed on the machine, and the test is fine, but the fmz still prompts line 4, in