From 92b3d652bc6a0b71688d54ab64436970e11c6a38 Mon Sep 17 00:00:00 2001 From: msincenselee Date: Sat, 18 Jan 2020 13:26:09 +0800 Subject: [PATCH] =?UTF-8?q?[=E5=A2=9E=E5=BC=BA]=20tdx=E9=80=89=E6=8B=A9?= =?UTF-8?q?=E6=9C=80=E4=BC=98=E7=9A=84IP=E5=9C=B0=E5=9D=80=E5=90=8E?= =?UTF-8?q?=EF=BC=8C=E8=AE=BE=E7=BD=AE2=E4=B8=AA=E5=B0=8F=E6=97=B6?= =?UTF-8?q?=E7=9A=84=E6=9C=89=E6=95=88=E6=9C=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- vnpy/data/tdx/tdx_future_data.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/vnpy/data/tdx/tdx_future_data.py b/vnpy/data/tdx/tdx_future_data.py index 95114976..1b817fea 100644 --- a/vnpy/data/tdx/tdx_future_data.py +++ b/vnpy/data/tdx/tdx_future_data.py @@ -131,6 +131,16 @@ class TdxFutureData(object): # 选取最佳服务器 if is_reconnect or len(self.best_ip) == 0: self.best_ip = get_cache_json(TDX_FUTURE_CONFIG) + last_datetime_str = self.best_ip.get('datetime', None) + if last_datetime_str: + try: + last_datetime = datetime.strptime(last_datetime_str, '%Y-%m-%d %H:%M:%S') + if (datetime.now() - last_datetime).total_seconds() > 60 * 60 * 2: + self.best_ip = {} + except Exception as ex: + self.best_ip = {} + else: + self.best_ip = {} if len(self.best_ip) == 0: self.best_ip = self.select_best_ip() @@ -192,6 +202,7 @@ class TdxFutureData(object): self.write_log(u'选取 {}:{}'.format(best_future_ip['ip'], best_future_ip['port'])) # print(u'选取 {}:{}'.format(best_future_ip['ip'], best_future_ip['port'])) + best_future_ip.update({'datetime': datetime.now().strftime('%Y-%m-%d %H:%M:%S')}) save_cache_json(best_future_ip, TDX_FUTURE_CONFIG) return best_future_ip