pywinauto实现中信证券股票交易接口

pywinauto实现中信证券股票交易接口,直接伪造数据包不成功,只能用pywinauto实现交易接口了,用easyocr识别登陆验证码,话说这个模块的识别率不是很高,而且启动还廷耗时,识别模型还要自己下载,

小编用的是中信证券,证券软件文件夹里面有xiadan.exe这个模块,就是操作这个模块来实现自动交易的。

import easyocr
from PIL.ImageGrab import grab
from pywinauto.application import Application
import time
#交易软件可以电脑和手机同时登陆
#print(easyocr.model_storage_directory)
#模型保存路径Windows:C:\Users\<用户名>\.EasyOCR\model
#Linux:~/ .EasyOCR / model
class exchange():
    def __init__(self):
        self.reader = easyocr.Reader(["ch_sim","en"],gpu=False)
        self.app = Application(backend="win32").start(r"C:\xxx\xiadan.exe").Dailog
        self.jpgpath=r"C:\Users\xxx\1.jpg"
        self.numindex=(xx,xx,xx,xx)  #验证码的位置,可以用微信截屏来定位。
    def grabnum(self):
        img=grab(bbox=(self.numindex))
        img.save(self.jpgpath)
    def loadfirst(self):
        self.grabnum()
        while True:  # 这个识别软件老是出错,所以只能这样了。
            try:
                valinum = self.reader.readtext(self.jpgpath)
                valicode = int(valinum[0][1].replace(" ", ""))  # 有时候识别的字符间有空格
            except Exception as e:
                print(e)
                # app.Button10.click() #重新刷新验证码,其实这里可以不用刷新
                continue
            else:
                break
        self.app.Edit3.type_keys(valicode)
        self.app.Botton.click()
    def loadlast(self):
        loadflag = 1
        self.app.Edit2.type_keys("your_password")
        while loadflag:
            self.loadfirst()
            time.sleep(1)
            if self.app[u"验证码错误,请重新输入!"].is_visible():
                self.app[u"确定"].click()  # 这里会自动刷新验证码
            else:
                loadflag = 0
    # app["Button10"].get_properties()
    def load(self):
        try:
            self.loadlast()
        except Exception as e:
            pass

综上所述,就是关于pywinauto实现中信证券股票交易接口的办法。如果大家还想了解中信证券股票交易接口更多信息可以在这里看MetaTradeAPI (metatradeapi) - Gitee.com。同时也可以给小编留言(下方QQ)。 

猜你喜欢

转载自blog.csdn.net/peizitoutiao/article/details/128449160
今日推荐