资源简介
Python+pywinauto操作同花顺客户端自动化执行测试 快速下单 代码为全代码 可以选择性摘抄。
代码片段和文件信息
import tkinter.messageboxos
from tkinter import *
from tkinter.ttk import *
from tkinter import Menu
import datetime
import threading
import pickle
import time
#import tushare as ts
import pywinauto
import pywinauto.clipboard
import pywinauto.application
NUM_OF_STOCKS = 5 # 自定义股票数量
is_start = False
is_monitor = True
set_stocks_info = []
actual_stocks_info = []
consignation_info = []
is_ordered = [1] * NUM_OF_STOCKS # 1:未下单 0:已下单
is_dealt = [0] * NUM_OF_STOCKS # 0: 未成交 负整数:卖出数量, 正整数:买入数量
stock_codes = [‘‘] * NUM_OF_STOCKS
class OperationThs:
def __init__(self):
try:
self.__app = pywinauto.application.Application()
self.__app.connect(title=‘网上股票交易系统5.0‘)
top_hwnd = pywinauto.findwindows.find_window(title=‘网上股票交易系统5.0‘)
dialog_hwnd = pywinauto.findwindows.find_windows(top_level_only=False class_name=‘#32770‘ parent=top_hwnd)[0]
wanted_hwnds = pywinauto.findwindows.find_windows(top_level_only=False parent=dialog_hwnd)
print(‘wanted_hwnds length‘ len(wanted_hwnds))
if len(wanted_hwnds)==0:
tkinter.messagebox.showerror(‘错误‘ ‘无法获得“同花顺双向委托界面”的窗口句柄请将同花顺交易系统切换到“双向委托界面”!‘)
exit()
self.__main_window = self.__app.window_(handle=top_hwnd)
self.__dialog_window = self.__app.window_(handle=dialog_hwnd)
except:
pass
def __buy(self code quantity):
“““买函数
:param code: 代码, 字符串
:param quantity: 数量, 字符串
“““
self.__dialog_window.Edit1.SetFocus()
time.sleep(0.2)
self.__dialog_window.Edit1.SetEditText(code)
time.sleep(0.2)
if quantity != ‘0‘:
self.__dialog_window.Edit3.SetEditText(quantity)
time.sleep(0.2)
self.__dialog_window.Button1.Click()
time.sleep(0.2)
def __sell(self code quantity):
“““
卖函数
:param code: 股票代码, 字符串
:param quantity: 数量, 字符串
“““
self.__dialog_window.Edit4.SetFocus()
time.sleep(0.2)
self.__dialog_window.Edit4.SetEditText(code)
time.sleep(0.2)
if quantity != ‘0‘:
self.__dialog_window.Edit6.SetEditText(quantity)
time.sleep(0.2)
self.__dialog_window.Button2.Click()
time.sleep(0.2)
def __closePopupWindow(self):
“““
关闭一个弹窗。
:return: 如果有弹出式对话框,返回True,否则返回False
“““
popup_hwnd = self.__main_window.PopupWindow()
if popup_hwnd:
popup_window = self.__app.window_(handle=popup_hwnd)
popup_window.SetFocus()
popup_window.Button.Click()
return True
return False
def __closePopupWindows(self):
“““
关闭多个弹出窗口
:return:
“““
while self.__closePopupWindow():
time.sleep(0.5)
def order(self code direc
- 上一篇:python pmw模块
- 下一篇:差分进化算法Python实现.zip
评论
共有 条评论