Git Product home page Git Product logo

Comments (11)

rainx avatar rainx commented on July 23, 2024

@yutiansut 这个项目可以用么? https://github.com/samuel/python-ping

from pytdx.

rainx avatar rainx commented on July 23, 2024

@yutiansut 虽然是比较老的版本,不过它是直接用python实现的,感觉可以基于这个修改一下,支持2和3

from pytdx.

yutiansut avatar yutiansut commented on July 23, 2024

@rainx 我说的就是这个,这个在windows下安装不起来 不知道什么情况 谷歌了一圈 好像都是走bash的

我想了想 这个类似爬虫里面的ip代理池,虽然不完全一样,我找找方法去

from pytdx.

rainx avatar rainx commented on July 23, 2024

@yutiansut 嗯嗯,可以参考一下爬虫的实现, 另外,热更换ip我之前也考虑过,不过之前考虑的是加在TdxHq_API类的外部,实现一个连接池,然后根据接口的可用性去选择,之前确实没考虑传输速度这个方面,如果测速的话,我觉得比较直接的方法是通过接口调用某个预知返回固定长度的数据,这样更精准写,ping的话只能单纯从网络的方面提供参考,对行情服务器本身的消息处理速度无法评判

from pytdx.

yutiansut avatar yutiansut commented on July 23, 2024

我想了想 准备这么搞 在你的外面加包一层
构想

from pytdx.

rainx avatar rainx commented on July 23, 2024

@yutiansut great

from pytdx.

yutiansut avatar yutiansut commented on July 23, 2024


先用我自己的那套试了试 应该可行

from pytdx.

yutiansut avatar yutiansut commented on July 23, 2024

这个是结果

from pytdx.

yutiansut avatar yutiansut commented on July 23, 2024
# 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.

yutiansut avatar yutiansut commented on July 23, 2024

封装的时候,就把这个上面的

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.

rainx avatar rainx commented on July 23, 2024

厉害,学习了...

from pytdx.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.