Comments (11)
@yutiansut 这个项目可以用么? https://github.com/samuel/python-ping
from pytdx.
@yutiansut 虽然是比较老的版本,不过它是直接用python实现的,感觉可以基于这个修改一下,支持2和3
from pytdx.
@rainx 我说的就是这个,这个在windows下安装不起来 不知道什么情况 谷歌了一圈 好像都是走bash的
我想了想 这个类似爬虫里面的ip代理池,虽然不完全一样,我找找方法去
from pytdx.
@yutiansut 嗯嗯,可以参考一下爬虫的实现, 另外,热更换ip我之前也考虑过,不过之前考虑的是加在TdxHq_API类的外部,实现一个连接池,然后根据接口的可用性去选择,之前确实没考虑传输速度这个方面,如果测速的话,我觉得比较直接的方法是通过接口调用某个预知返回固定长度的数据,这样更精准写,ping的话只能单纯从网络的方面提供参考,对行情服务器本身的消息处理速度无法评判
from pytdx.
from pytdx.
@yutiansut great
from pytdx.
from pytdx.
from pytdx.
# coding: utf-8
# In[ ]:
import QUANTAXIS as QA
# In[ ]:
import threading
import queue
# In[ ]:
ip_job=queue.Queue()
ip_task=QA.QA_Queue(ip_job)
# In[ ]:
ip_task.setName('ip_task')
# In[ ]:
ip_task.start()
# In[ ]:
from pytdx.hq import TdxHq_API
# In[ ]:
api=TdxHq_API()
# In[ ]:
#for i in range(5):
# ip_job.put({'fn':print(QA.QAUtil.QA_util_web_ping('www.baidu.com'))})
# In[ ]:
ip_list = [
'119.147.212.81:7709',
'221.231.141.60:7709',
'101.227.73.20:7709',
'101.227.77.254:7709',
'14.215.128.18:7709'
'59.173.18.140:7709',
'58.23.131.163:7709',
'218.6.170.47:7709',
'123.125.108.14:7709',
'60.28.23.80:7709',
'218.60.29.136:7709',
'218.85.139.19:7709',
'218.85.139.20:7709',
'122.192.35.44:7709',
'122.192.35.44:7709'
]
# In[ ]:
ip_addr=[]
for item in ip_list:
ip_addr.append(item.split(':')[0])
# In[ ]:
ip_addr
# In[ ]:
def select_best(url_list):
ms_list=[]
for item in url_list:
ms_list.append(QA.QAUtil.QA_util_web_ping(item))
return url_list[ms_list.index(min(ms_list))]
ip_job.put({'fn':print(select_best(ip_addr))})
# In[ ]:
from pytdx.
封装的时候,就把这个上面的
ip_job.put({'fn':print(select_best(ip_addr))})
里面的print改成send_to_ssdb()或者是扔进一个内存数据结构broker中
等到用到pytdx的时候,再从这个broker中刷出最新的
import threading
timer=threading.Timer(600,ip_job.put({'fn':send_to_redis/ssdb(select_best(ip_addr))})
#这样就变成10分钟,定期往任务队列里面发一个更新最优ip的任务
然而这样会阻塞主进程,因为timer虽然是异步的,但是10分钟的任务结构是会阻塞的
PS: Timer是可以做一个自我循环的,但是那个进程有点不稳定,容易自我死亡,还是再开一个线程,做一个阻塞的任务比较好
所以再开一个任务队列:
import QUANTAXIS as QA
import queue
task_job=queue.Queue()
task_=QA.QA_Queue(task_job)
task_.setName('task_sche')
task_.start()
def ten_min_job():
timer=threading.Timer(600,ip_job.put({'fn':send_to_redis/ssdb(select_best(ip_addr))})
time.sleep(600)
ten_min_job()
task_job.put({'fn':ten_min_job()})
这样就基本实现刚才的那个构想图了
from pytdx.
厉害,学习了...
from pytdx.
Related Issues (20)
- 扩展行情的IP都没有可以连接的。 HOT 1
- 扩展行情里面有没有可以获取多个行情quotes的接口?
- get_security_list 请问一下这个是用来获取股票列表的吗? HOT 2
- 请教一下下载的财务数据的 315个列字段的意义问题. HOT 1
- get_security_list这个函数的pre_close有误 HOT 10
- get_security_bars取出来的vol值差了1个 HOT 4
- 跳过的4个字节估计是上一日收盘价
- get_security_list获取的数据中的pre_close有解析正确有些解析不正确 HOT 1
- 不支持美股了?
- AttributeError: __enter__
- 怎么获取行情服务器的IP HOT 1
- 官方文档代码某行缺失 HOT 1
- 请问有办法获取涨停价和跌停价吗 HOT 1
- 可以获取level2的逐笔成交明细吗? HOT 1
- 心跳包还有多线程有没有详细的文档解释? HOT 1
- TdxDailyBarReader() 读取 上海 688 的时候,异常 Unknown security type ! HOT 1
- 盘口价格是不是颠倒了 HOT 1
- exhq.py文件 运行报错 AttributeError: __enter__
- debian python 3.7 get_security_quotes 解析 servertime 报错 HOT 2
- 如何判断股票代码是否指数
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pytdx.