Skip to content

Commit

Permalink
py, best ip
Browse files Browse the repository at this point in the history
  • Loading branch information
yssource committed Apr 29, 2023
1 parent 4d2b0ea commit 6ca0b9d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
1 change: 1 addition & 0 deletions abquant/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,7 @@ def make_stock_ip_list():
else:
Setting.stock_ip_list = [
# added 20190222 from tdx
{"ip": "124.71.187.122", "port": 7709, "name": "上海双线主站14"},
{"ip": "106.120.74.86", "port": 7711, "name": "北京行情主站1"},
{"ip": "113.105.73.88", "port": 7709, "name": "深圳行情主站"},
{"ip": "113.105.73.88", "port": 7711, "name": "深圳行情主站"},
Expand Down
10 changes: 7 additions & 3 deletions abquant/data/tdx_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ def select_best_ip():

ipdefault = Setting.get_setting(Setting.NETWORK_IP_INI, "IPLIST", "default")

ipdefault = eval(ipdefault) if isinstance(ipdefault, str) else ipdefault
ipdefault = json.loads(ipdefault) if isinstance(ipdefault, str) else ipdefault
assert isinstance(ipdefault, dict)

stock_ip_list = Setting.make_stock_ip_list()
Expand Down Expand Up @@ -150,8 +150,11 @@ def get_ip_list_by_multi_process_ping(ip_list=[], n=0, _type="stock", cache_age=
results = [x[1] for x in sorted(results, key=lambda x: x[0])]
if _type:
# store the data as binary data stream
cache.set(_type, results, age=cache_age)
slog.debug("saving ip list to {} cache {}".format(_type, len(results)))
try:
cache.set(_type, results, age=cache_age)
slog.debug("saving ip list to {} cache {}".format(_type, len(results)))
except Exception:
results = []
if len(results) > 0:
if n == 0 and len(results) > 0:
return results
Expand Down Expand Up @@ -191,6 +194,7 @@ def get_mainmarket_ip(ip, port):
port = best_ip["stock"]["port"]
else:
pass
assert ip is not None and ip != "", "Best IP is None, Abort TDX!"
return ip, port


Expand Down
4 changes: 2 additions & 2 deletions abquant/utils/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ def set(self, key, data, age=-1):
if age == -1:
self.time[key] = -1
else:
self.time[key] = time() + age
self.time[key] = time.time() + age
return True

def get(self, key):
"""获取键key对应的值"""
if key in self.mem.keys():
if self.time[key] == -1 or self.time[key] > time():
if self.time[key] == -1 or self.time[key] > time.time():
return self.mem[key]
else:
self.delete(key)
Expand Down

0 comments on commit 6ca0b9d

Please sign in to comment.