xinxin
This commit is contained in:
parent
3ed88fc5bb
commit
54d999b15a
@ -25,7 +25,10 @@ root_path = Path(__file__).parent.parent
|
||||
|
||||
path = os.path.join(root_path,'broker_xiadan','金长江网上交易汇智版','xiadan.exe')
|
||||
|
||||
|
||||
global engine
|
||||
engine = create_engine(
|
||||
'mysql+pymysql://cn_ainvest_db:cn_ainvest_sd3a1@rm-2zewagytttzk6f24xno.mysql.rds.aliyuncs.com:3306'
|
||||
)
|
||||
class ChangJiangClientTrader:
|
||||
"""
|
||||
基于同花顺委托下单程序的"长城证券客户端"自动交易程序
|
||||
@ -100,13 +103,12 @@ class ChangJiangClientTrader:
|
||||
#启动软件进程,输入账号密码
|
||||
self.log.info('Start login')
|
||||
|
||||
# 重置mac
|
||||
# 重置mac并尝试连接WiFi
|
||||
set_mac = SetMac()
|
||||
set_mac.run()
|
||||
# 尝试连接WiFi
|
||||
connect_wifi(ssid, password)
|
||||
|
||||
|
||||
# 获取非重复的IP
|
||||
get_ip_times = 0
|
||||
while get_ip_times < 10:
|
||||
try:
|
||||
@ -121,7 +123,7 @@ class ChangJiangClientTrader:
|
||||
self.log.error(f'获取IP失败,请检查网络连接{e}')
|
||||
time.sleep(5)
|
||||
|
||||
# 设置全局代理
|
||||
# 为代理程序设置代理IP和端口
|
||||
proxy_ip = item['ip']
|
||||
proxy_port = item['port']
|
||||
set_proxy(proxy_ip, proxy_port)
|
||||
@ -164,22 +166,22 @@ class ChangJiangClientTrader:
|
||||
except Exception:
|
||||
break
|
||||
|
||||
|
||||
self._app.window(title_re='网上股票交易系统5.0.*').wait("ready",timeout=60)
|
||||
# ip入库
|
||||
engine_ip = create_engine(
|
||||
'mysql+pymysql://cn_ainvest_db:cn_ainvest_sd3a1@rm-2zewagytttzk6f24xno.mysql.rds.aliyuncs.com:3306'
|
||||
)
|
||||
insert_data = {'As_Of_Date': datetime.date.today(),
|
||||
# ip和mac入库
|
||||
new_mac = set_mac.get_macinfos()
|
||||
insert_data_df = pd.DataFrame([{'As_Of_Date': datetime.date.today(),
|
||||
'Broker': '长江证券',
|
||||
'Account_Number': self.account_name,
|
||||
'Timestamp': datetime.datetime.now(),
|
||||
'Proxy': True,
|
||||
'IP_Type': '动态IP',
|
||||
'Mac': new_mac,
|
||||
'IP': proxy_ip,
|
||||
'Port': proxy_port}
|
||||
conn = engine_ip.connect()
|
||||
conn.execute(text("INSERT INTO user_center.trade_proxyip (As_Of_Date, Broker, Account_Number, Timestamp, Proxy, IP, Port) VALUES (:As_Of_Date, :Broker, :Account_Number, :Timestamp, :Proxy, :IP, :Port)"), insert_data)
|
||||
conn.close()
|
||||
'Port': proxy_port,
|
||||
'Location': item['prov'] + ':' + item['city']}])
|
||||
insert_data_df.to_sql('trade_proxyip', engine, schema='user_center', index=False, if_exists='append')
|
||||
self.log.info(f'IP:{proxy_ip} MAC:{new_mac} 已入库')
|
||||
|
||||
#关闭弹窗
|
||||
for i in range(3):
|
||||
self._turn_off_advertising()
|
||||
|
@ -122,21 +122,17 @@ class DongWuClientTrader:
|
||||
|
||||
#启动软件进程,输入账号密码
|
||||
self.logger.info('Start login')
|
||||
start_time = time.time()
|
||||
|
||||
# 重置mac
|
||||
# 重置mac并尝试连接WiFi
|
||||
set_mac = SetMac()
|
||||
set_mac.run()
|
||||
# 尝试连接WiFi
|
||||
connect_wifi(ssid,password)
|
||||
|
||||
get_ip_times = 0
|
||||
writer = ExcelDataWriter() # 初始化ip_records 表格
|
||||
used_ip = writer.get_unavailable_ips(broker, account_name)
|
||||
while get_ip_times<10:
|
||||
try:
|
||||
item = get_ip_data() #获取动态IP
|
||||
if item['ip'] in used_ip:
|
||||
item = get_ip_data()
|
||||
if check_ip_duplicate(self.account_name, item['ip']):
|
||||
get_ip_times += 1
|
||||
self.logger.warning(f'代理IP重复,重新获取IP')
|
||||
else:
|
||||
@ -145,36 +141,14 @@ class DongWuClientTrader:
|
||||
except Exception as e:
|
||||
self.logger.error(f'获取IP失败,请检查网络连接{e}')
|
||||
time.sleep(5)
|
||||
# raise ConnectionError(f"获取IP失败,请检查网络连接。错误详情: {e}")
|
||||
|
||||
|
||||
#设置全局代理
|
||||
proxy_ip = item['ip']
|
||||
proxy_port = item['port']
|
||||
set_proxy(proxy_ip,proxy_port)
|
||||
|
||||
# exit_ip = get_proxy_ip(proxy_ip,proxy_port)
|
||||
time_with_change_proxy = time.time()-start_time
|
||||
self.logger.info('全局代理设置成功')
|
||||
|
||||
insert_data= {'as_of_date':datetime.datetime.fromtimestamp(start_time).strftime('%Y-%m-%d %H:%M:%S.%f'),
|
||||
'broker':broker,
|
||||
'account': account_name,
|
||||
'proxy_ip': proxy_ip,
|
||||
'proxy_port':proxy_port,
|
||||
'ip_location': item['prov']+':'+item['city'],
|
||||
#'exit_ip': exit_ip,
|
||||
'ip_cross_check_result': '一致',
|
||||
'ip_switch_time':time_with_change_proxy,
|
||||
#'ip_expire_time':item['expire']
|
||||
'ip_survival_time':'5min'
|
||||
}
|
||||
# 写入数据表
|
||||
writer = ExcelDataWriter() # 初始化ip_records 表格
|
||||
writer.write_data(insert_data)
|
||||
|
||||
# 检查IP是否可用
|
||||
|
||||
# 开始登录
|
||||
time.sleep(2)
|
||||
self._app = pywinauto.Application().start(self.path)
|
||||
@ -189,40 +163,23 @@ class DongWuClientTrader:
|
||||
self._app.window(title_re='用户登录.*').Edit2.type_keys(self.securities_password)
|
||||
time.sleep(0.1)
|
||||
|
||||
# # 验证码登录
|
||||
# while True:
|
||||
# #获取id_code
|
||||
# id_code = self.verify_code(0x5DB)
|
||||
# time.sleep(0.2)
|
||||
# self._app.window(title_re='用户登录.*').Edit3.type_keys('{BACKSPACE}' * 6)
|
||||
# time.sleep(0.2)
|
||||
# self._app.window(title_re='用户登录.*').Edit3.type_keys(id_code)
|
||||
# time.sleep(0.2)
|
||||
# pywinauto.keyboard.send_keys("{ENTER}")
|
||||
# time.sleep(0.5)
|
||||
# try:
|
||||
# self._app.top_window().set_focus()
|
||||
# result_idcode = self._app.window(control_id=0x0, class_name='#32770',found_index = 0).window(control_id=0x3EC, class_name='Static').window_text()
|
||||
# self.log.softInfo(result_idcode)
|
||||
# if '验证码错误' in result_idcode or '连接委托主站失败' in result_idcode:
|
||||
# self.log.warn('Verification code error')
|
||||
# self._app.window(control_id=0x0, class_name='#32770',found_index = 0).window(control_id=0x2, class_name='Button').click()
|
||||
# time.sleep(0.5)
|
||||
# else:
|
||||
# break
|
||||
# except Exception as e:
|
||||
# self.log.info(f'登录失败:{e}')
|
||||
# break
|
||||
#
|
||||
# time.sleep(10) # 这里sleep(10)是?
|
||||
# while True:
|
||||
# try:
|
||||
# self._app.window(title_re='网上股票交易系统5.0.*').wait("ready")
|
||||
# break
|
||||
# except RuntimeError:
|
||||
# pass
|
||||
pywinauto.keyboard.send_keys("{ENTER}")
|
||||
self._app.window(title_re='网上股票交易系统5.0.*').wait("ready",timeout=60)
|
||||
self._app.window(title_re='网上股票交易系统5.0.*').wait("ready",timeout=30)
|
||||
|
||||
# ip和mac入库
|
||||
new_mac = set_mac.get_macinfos()
|
||||
insert_data_df = pd.DataFrame([{'As_Of_Date': datetime.date.today(),
|
||||
'Broker': '东吴证券',
|
||||
'Account_Number': self.account_name,
|
||||
'Timestamp': datetime.datetime.now(),
|
||||
'Proxy': True,
|
||||
'IP_Type': '动态IP',
|
||||
'Mac': new_mac,
|
||||
'IP': proxy_ip,
|
||||
'Port': proxy_port,
|
||||
'Location': item['prov'] + ':' + item['city']}])
|
||||
insert_data_df.to_sql('trade_proxyip', engine, schema='user_center', index=False, if_exists='append')
|
||||
self.logger.info(f'IP:{proxy_ip} MAC:{new_mac} 已入库')
|
||||
#关闭弹窗
|
||||
for i in range(3):
|
||||
self._turn_off_advertising()
|
||||
@ -231,26 +188,6 @@ class DongWuClientTrader:
|
||||
self.main_wnd = self._app.window(title='网上股票交易系统5.0')
|
||||
self.left_wnd = self.main_wnd.window(class_name='AfxWnd140s', control_id=0xC8,found_index=0).window(class_name='SysTreeView32',control_id=0x81)
|
||||
|
||||
# #使用的ip mac入库
|
||||
# ip = get_ip()
|
||||
# mac_info = subprocess.check_output('GETMAC /v /FO list', stderr=subprocess.STDOUT)
|
||||
# mac_info = mac_info.decode('gbk')
|
||||
# # 想要匹配的连接名
|
||||
# target_connection_name = "WLAN 2"
|
||||
#
|
||||
# # 构建正则表达式模式
|
||||
# pattern = re.compile(
|
||||
# r"连接名:\s+" + re.escape(target_connection_name) + r".*?物理地址:\s+([0-9A-Fa-f-]+)",
|
||||
# re.DOTALL
|
||||
# )
|
||||
# # 执行搜索
|
||||
# mac = pattern.search(mac_info).group(1)
|
||||
# data = {'As_Of_Date': datetime.datetime.now(), 'Account_Name': account_name, 'Broker': broker, 'MAC': mac,
|
||||
# 'IP': ip}
|
||||
# aaa = pd.DataFrame([data])
|
||||
# aaa.to_sql('trade_mac_ip', engine, schema='auth_center', index=False, if_exists='append')
|
||||
# self.log.info('IP:' + ip + ' MAC:' + mac)
|
||||
|
||||
|
||||
|
||||
def _turn_off_advertising(self):
|
||||
|
@ -26,6 +26,11 @@ root_path = Path(__file__).parent.parent
|
||||
from config import ssid,password
|
||||
path = os.path.join(root_path,'broker_xiadan','gfzqrzrq','xiadan.exe')
|
||||
|
||||
global engine
|
||||
engine = create_engine(
|
||||
'mysql+pymysql://cn_ainvest_db:cn_ainvest_sd3a1@rm-2zewagytttzk6f24xno.mysql.rds.aliyuncs.com:3306'
|
||||
)
|
||||
|
||||
class GFClientTrader:
|
||||
"""
|
||||
基于同花顺委托下单程序的"长城证券客户端"自动交易程序
|
||||
@ -80,25 +85,18 @@ class GFClientTrader:
|
||||
#启动软件进程,输入账号密码
|
||||
self.log.info('Start login')
|
||||
|
||||
|
||||
broker = '广发证券'
|
||||
start_time = time.time()
|
||||
|
||||
# 重置mac
|
||||
# 重置mac并尝试连接WiFi
|
||||
set_mac = SetMac()
|
||||
set_mac.run()
|
||||
# 尝试连接WiFi
|
||||
connect_wifi(ssid, password)
|
||||
|
||||
get_ip_times = 0
|
||||
writer = ExcelDataWriter() # 初始化ip_records 表格
|
||||
used_ip = writer.get_unavailable_ips(broker, self.account_name)
|
||||
while get_ip_times < 10:
|
||||
try:
|
||||
item = get_ip_data() # 获取动态IP
|
||||
if item['ip'] in used_ip:
|
||||
item = get_ip_data()
|
||||
if check_ip_duplicate(self.account_name, item['ip']):
|
||||
get_ip_times += 1
|
||||
self.log.warning(f'代理IP重复,重新获取IP')
|
||||
self.log.warn(f'代理IP重复,重新获取IP')
|
||||
else:
|
||||
self.log.info(f'代理IP已经获取{item}')
|
||||
break
|
||||
@ -111,29 +109,9 @@ class GFClientTrader:
|
||||
proxy_ip = item['ip']
|
||||
proxy_port = item['port']
|
||||
set_proxy(proxy_ip, proxy_port)
|
||||
|
||||
# exit_ip = get_proxy_ip(proxy_ip,proxy_port)
|
||||
time_with_change_proxy = time.time() - start_time
|
||||
self.log.info('全局代理设置成功')
|
||||
|
||||
insert_data = {'as_of_date': datetime.datetime.fromtimestamp(start_time).strftime('%Y-%m-%d %H:%M:%S.%f'),
|
||||
'broker': broker,
|
||||
'account': self.account_name,
|
||||
'proxy_ip': proxy_ip,
|
||||
'proxy_port': proxy_port,
|
||||
'ip_location': item['prov'] + ':' + item['city'],
|
||||
# 'exit_ip': exit_ip,
|
||||
'ip_cross_check_result': '一致',
|
||||
'ip_switch_time': time_with_change_proxy,
|
||||
# 'ip_expire_time':item['expire']
|
||||
'ip_survival_time': '5min'
|
||||
}
|
||||
# 写入数据表
|
||||
writer = ExcelDataWriter() # 初始化ip_records 表格
|
||||
writer.write_data(insert_data)
|
||||
|
||||
|
||||
|
||||
# 启动软件进程,输入账号密码
|
||||
self._app = pywinauto.Application().start(self.path)
|
||||
while True:
|
||||
try:
|
||||
@ -149,41 +127,26 @@ class GFClientTrader:
|
||||
self._app.window(title_re='用户登录.*').window(control_id = 0x3F4,class_name = 'Edit',found_index = 0).type_keys(self.securities_password)
|
||||
time.sleep(1)
|
||||
|
||||
# 验证码登录
|
||||
# while True:
|
||||
# #获取id_code
|
||||
# id_code = self.verify_code(0x5DB)
|
||||
# time.sleep(0.2)
|
||||
# self._app.window(title_re='用户登录.*').Edit3.type_keys('{BACKSPACE}' * 6)
|
||||
# time.sleep(0.2)
|
||||
# self._app.window(title_re='用户登录.*').Edit3.type_keys(id_code)
|
||||
# time.sleep(0.2)
|
||||
# pywinauto.keyboard.send_keys("{ENTER}")
|
||||
# time.sleep(0.5)
|
||||
# try:
|
||||
# self._app.top_window().set_focus()
|
||||
# result_idcode = self._app.window(title_re='用户登录.*').window(control_id=0x3EC, class_name='Static').window_text()
|
||||
# self.log.softInfo(result_idcode)
|
||||
# if '验证码错误' in result_idcode:
|
||||
# self.log.warn('Verification code error')
|
||||
# self._app.window(title_re='用户登录.*').window(control_id=0x2, class_name="Button").click()
|
||||
# time.sleep(0.5)
|
||||
# else:
|
||||
# break
|
||||
# except Exception:
|
||||
# break
|
||||
|
||||
# while True:
|
||||
# try:
|
||||
# self._app.window(title_re='核新网上交易系统7.76.*').wait("ready")
|
||||
# break
|
||||
# except RuntimeError:
|
||||
# pass
|
||||
time.sleep(0.2)
|
||||
pywinauto.keyboard.send_keys("{ENTER}")
|
||||
time.sleep(8)
|
||||
|
||||
self._close_prompt_windows()
|
||||
self._app.window(title_re='核新网上交易系统.*').wait("ready",timeout=60)
|
||||
|
||||
# ip和mac入库
|
||||
new_mac = set_mac.get_macinfos()
|
||||
insert_data_df = pd.DataFrame([{'As_Of_Date': datetime.date.today(),
|
||||
'Broker': '广发证券',
|
||||
'Account_Number': self.account_name,
|
||||
'Timestamp': datetime.datetime.now(),
|
||||
'Proxy': True,
|
||||
'IP_Type': '动态IP',
|
||||
'Mac': new_mac,
|
||||
'IP': proxy_ip,
|
||||
'Port': proxy_port,
|
||||
'Location': item['prov'] + ':' + item['city']}])
|
||||
insert_data_df.to_sql('trade_proxyip', engine, schema='user_center', index=False, if_exists='append')
|
||||
self.log.info(f'IP:{proxy_ip} MAC:{new_mac} 已入库')
|
||||
#关闭弹窗
|
||||
# for i in range(3):
|
||||
# self._turn_off_advertising()
|
||||
|
@ -128,20 +128,16 @@ class HLClientTrader:
|
||||
# 启动软件进程,输入账号密码
|
||||
self.logger.info('Start login')
|
||||
|
||||
start_time = time.time()
|
||||
|
||||
# 重置mac
|
||||
# 重置mac并尝试连接WiFi
|
||||
set_mac = SetMac()
|
||||
set_mac.run()
|
||||
# 尝试连接WiFi
|
||||
connect_wifi(ssid,password)
|
||||
|
||||
get_ip_times = 0
|
||||
writer = ExcelDataWriter() # 初始化ip_records 表格
|
||||
used_ip = writer.get_unavailable_ips(broker, account_name)
|
||||
while get_ip_times < 10:
|
||||
try:
|
||||
item = get_ip_data() # 获取动态IP
|
||||
if item['ip'] in used_ip:
|
||||
item = get_ip_data()
|
||||
if check_ip_duplicate(self.account_name, item['ip']):
|
||||
get_ip_times += 1
|
||||
self.logger.warning(f'代理IP重复,重新获取IP')
|
||||
else:
|
||||
@ -155,28 +151,9 @@ class HLClientTrader:
|
||||
proxy_ip = item['ip']
|
||||
proxy_port = item['port']
|
||||
set_proxy(proxy_ip, proxy_port)
|
||||
|
||||
# exit_ip = get_proxy_ip(proxy_ip,proxy_port)
|
||||
time_with_change_proxy = time.time() - start_time
|
||||
self.logger.info('全局代理设置成功')
|
||||
|
||||
insert_data = {'as_of_date': datetime.datetime.fromtimestamp(start_time).strftime('%Y-%m-%d %H:%M:%S.%f'),
|
||||
'broker': broker,
|
||||
'account': account_name,
|
||||
'proxy_ip': proxy_ip,
|
||||
'proxy_port': proxy_port,
|
||||
'ip_location': item['prov'] + ':' + item['city'],
|
||||
# 'exit_ip': exit_ip,
|
||||
'ip_cross_check_result': '一致',
|
||||
'ip_switch_time': time_with_change_proxy,
|
||||
# 'ip_expire_time':item['expire']
|
||||
'ip_survival_time': '5min'
|
||||
}
|
||||
# 写入数据表
|
||||
writer = ExcelDataWriter() # 初始化ip_records 表格
|
||||
writer.write_data(insert_data)
|
||||
|
||||
time.sleep(2)
|
||||
#启动软件进程,输入账号密码
|
||||
self._app = pywinauto.Application().start(self.path)
|
||||
|
||||
@ -233,7 +210,22 @@ class HLClientTrader:
|
||||
|
||||
# 关闭弹窗
|
||||
# self._close_prompt_windows()
|
||||
self._app.window(title_re='通达信网上交易.*').wait("ready",timeout=60)
|
||||
self._app.window(title_re='通达信网上交易.*').wait("ready",timeout=30)
|
||||
|
||||
# ip和mac入库
|
||||
new_mac = set_mac.get_macinfos()
|
||||
insert_data_df = pd.DataFrame([{'As_Of_Date': datetime.date.today(),
|
||||
'Broker': '华龙证券',
|
||||
'Account_Number': self.account_name,
|
||||
'Timestamp': datetime.datetime.now(),
|
||||
'Proxy': True,
|
||||
'IP_Type': '动态IP',
|
||||
'Mac': new_mac,
|
||||
'IP': proxy_ip,
|
||||
'Port': proxy_port,
|
||||
'Location': item['prov'] + ':' + item['city']}])
|
||||
insert_data_df.to_sql('trade_proxyip', engine, schema='user_center', index=False, if_exists='append')
|
||||
self.logger.info(f'IP:{proxy_ip} MAC:{new_mac} 已入库')
|
||||
|
||||
|
||||
#设置主窗口及菜单窗口
|
||||
|
@ -25,6 +25,11 @@ root_path = Path(__file__).parent.parent
|
||||
from config import ssid,password
|
||||
path = os.path.join(root_path,'broker_xiadan','华泰证券网上交易委托系统','xiadan.exe')
|
||||
|
||||
global engine
|
||||
engine = create_engine(
|
||||
'mysql+pymysql://cn_ainvest_db:cn_ainvest_sd3a1@rm-2zewagytttzk6f24xno.mysql.rds.aliyuncs.com:3306'
|
||||
)
|
||||
|
||||
|
||||
class HTClientTrader:
|
||||
"""
|
||||
@ -81,23 +86,19 @@ class HTClientTrader:
|
||||
|
||||
#启动软件进程,输入账号密码
|
||||
self.log.info('Start login')
|
||||
broker = '华泰证券'
|
||||
start_time = time.time()
|
||||
# 重置mac
|
||||
|
||||
# 重置mac并尝试连接WiFi
|
||||
set_mac = SetMac()
|
||||
set_mac.run()
|
||||
# 尝试连接WiFi
|
||||
connect_wifi(ssid, password)
|
||||
|
||||
get_ip_times = 0
|
||||
writer = ExcelDataWriter() # 初始化ip_records 表格
|
||||
used_ip = writer.get_unavailable_ips(broker, self.account_name)
|
||||
while get_ip_times < 10:
|
||||
try:
|
||||
item = get_ip_data() # 获取动态IP
|
||||
if item['ip'] in used_ip:
|
||||
if check_ip_duplicate(self.account_name, item['ip']):
|
||||
get_ip_times += 1
|
||||
self.log.warning(f'代理IP重复,重新获取IP')
|
||||
self.log.warn(f'代理IP重复,重新获取IP')
|
||||
else:
|
||||
self.log.info(f'代理IP已经获取{item}')
|
||||
break
|
||||
@ -110,28 +111,8 @@ class HTClientTrader:
|
||||
proxy_ip = item['ip']
|
||||
proxy_port = item['port']
|
||||
set_proxy(proxy_ip, proxy_port)
|
||||
|
||||
# exit_ip = get_proxy_ip(proxy_ip,proxy_port)
|
||||
time_with_change_proxy = time.time() - start_time
|
||||
self.log.info('全局代理设置成功')
|
||||
|
||||
insert_data = {'as_of_date': datetime.datetime.fromtimestamp(start_time).strftime('%Y-%m-%d %H:%M:%S.%f'),
|
||||
'broker': broker,
|
||||
'account': self.account_name,
|
||||
'proxy_ip': proxy_ip,
|
||||
'proxy_port': proxy_port,
|
||||
'ip_location': item['prov'] + ':' + item['city'],
|
||||
# 'exit_ip': exit_ip,
|
||||
'ip_cross_check_result': '一致',
|
||||
'ip_switch_time': time_with_change_proxy,
|
||||
# 'ip_expire_time':item['expire']
|
||||
'ip_survival_time': '5min'
|
||||
}
|
||||
# 写入数据表
|
||||
writer = ExcelDataWriter() # 初始化ip_records 表格
|
||||
writer.write_data(insert_data)
|
||||
|
||||
|
||||
self._app = pywinauto.Application().start(self.path)
|
||||
while True:
|
||||
try:
|
||||
@ -142,7 +123,6 @@ class HTClientTrader:
|
||||
pass
|
||||
time.sleep(1)
|
||||
self._app.window(title_re='用户登录.*').window(control_id=0x68B, class_name='Button').click()
|
||||
# # pyautogui.click(1002, 504)
|
||||
pyautogui.click(1038, 529)
|
||||
time.sleep(1)
|
||||
self._app.window(title_re='用户登录.*').window(class_name='Edit', control_id=0x3E9,found_index=0).type_keys(self.securities_name)
|
||||
@ -153,11 +133,26 @@ class HTClientTrader:
|
||||
|
||||
time.sleep(2)
|
||||
pywinauto.keyboard.send_keys("{ENTER}")
|
||||
time.sleep(10)
|
||||
# #关闭弹窗
|
||||
# for i in range(3):
|
||||
# self._turn_off_advertising()
|
||||
self._app.window(title_re='网上股票交易系统5.0.*').wait("ready",timeout=60)
|
||||
self._app.window(title_re='网上股票交易系统5.0.*').wait("ready",timeout=30)
|
||||
# ip和mac入库
|
||||
new_mac = set_mac.get_macinfos()
|
||||
insert_data_df = pd.DataFrame([{'As_Of_Date': datetime.date.today(),
|
||||
'Broker': '华泰证券',
|
||||
'Account_Number': self.account_name,
|
||||
'Timestamp': datetime.datetime.now(),
|
||||
'Proxy': True,
|
||||
'IP_Type': '动态IP',
|
||||
'Mac': new_mac,
|
||||
'IP': proxy_ip,
|
||||
'Port': proxy_port,
|
||||
'Location': item['prov'] + ':' + item['city']}])
|
||||
insert_data_df.to_sql('trade_proxyip', engine, schema='user_center', index=False, if_exists='append')
|
||||
self.log.info(f'IP:{proxy_ip} MAC:{new_mac} 已入库')
|
||||
|
||||
# 关闭弹窗
|
||||
self._close_prompt_windows()
|
||||
#设置主窗口及菜单窗口
|
||||
self.main_wnd = self._app.window(title='网上股票交易系统5.0')
|
||||
|
@ -24,7 +24,10 @@ from pathlib import Path
|
||||
root_path = Path(__file__).parent.parent
|
||||
|
||||
path = os.path.join(root_path,'broker_xiadan','中信建投网上交易极速版(同花顺)','xiadan.exe')
|
||||
|
||||
global engine
|
||||
engine = create_engine(
|
||||
'mysql+pymysql://cn_ainvest_db:cn_ainvest_sd3a1@rm-2zewagytttzk6f24xno.mysql.rds.aliyuncs.com:3306'
|
||||
)
|
||||
|
||||
class ZXJTClientTrader:
|
||||
"""
|
||||
@ -78,64 +81,36 @@ class ZXJTClientTrader:
|
||||
self.log.warn('There are running programs, and there are processes in retreat')
|
||||
except Exception:
|
||||
pass
|
||||
broker = '中信建投'
|
||||
|
||||
#启动软件进程,输入账号密码
|
||||
self.log.info('Start login')
|
||||
start_time = time.time()
|
||||
# 重置mac
|
||||
|
||||
# 重置mac并尝试连接WiFi
|
||||
set_mac = SetMac()
|
||||
set_mac.run()
|
||||
# 尝试连接WiFi
|
||||
connect_wifi(ssid, password)
|
||||
|
||||
get_ip_times = 0
|
||||
writer = ExcelDataWriter() # 初始化ip_records 表格
|
||||
used_ip = writer.get_unavailable_ips(broker, self.account_name)
|
||||
while get_ip_times < 10:
|
||||
try:
|
||||
item = get_ip_data() # 获取动态IP
|
||||
if item['ip'] in used_ip:
|
||||
item = get_ip_data()
|
||||
if check_ip_duplicate(self.account_name, item['ip']):
|
||||
get_ip_times += 1
|
||||
self.log.warning(f'代理IP重复,重新获取IP')
|
||||
self.log.warn(f'代理IP重复,重新获取IP')
|
||||
else:
|
||||
self.log.info(f'代理IP已经获取{item}')
|
||||
break
|
||||
except Exception as e:
|
||||
self.log.error(f'获取IP失败,请检查网络连接{e}')
|
||||
time.sleep(5)
|
||||
# raise ConnectionError(f"获取IP失败,请检查网络连接。错误详情: {e}")
|
||||
|
||||
# 设置全局代理
|
||||
proxy_ip = item['ip']
|
||||
proxy_port = item['port']
|
||||
set_proxy(proxy_ip, proxy_port)
|
||||
|
||||
# exit_ip = get_proxy_ip(proxy_ip,proxy_port)
|
||||
time_with_change_proxy = time.time() - start_time
|
||||
self.log.info('全局代理设置成功')
|
||||
|
||||
insert_data = {'as_of_date': datetime.datetime.fromtimestamp(start_time).strftime('%Y-%m-%d %H:%M:%S.%f'),
|
||||
'broker': broker,
|
||||
'account': self.account_name,
|
||||
'proxy_ip': proxy_ip,
|
||||
'proxy_port': proxy_port,
|
||||
'ip_location': item['prov'] + ':' + item['city'],
|
||||
# 'exit_ip': exit_ip,
|
||||
'ip_cross_check_result': '一致',
|
||||
'ip_switch_time': time_with_change_proxy,
|
||||
# 'ip_expire_time':item['expire']
|
||||
'ip_survival_time': '5min'
|
||||
}
|
||||
# 写入数据表
|
||||
writer = ExcelDataWriter() # 初始化ip_records 表格
|
||||
writer.write_data(insert_data)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# 启动软件进程,输入账号密码
|
||||
self._app = pywinauto.Application().start(self.path)
|
||||
time.sleep(0.5)
|
||||
while True:
|
||||
@ -151,41 +126,23 @@ class ZXJTClientTrader:
|
||||
self._app.window(title_re='用户登录.*').Edit2.type_keys(self.securities_password)
|
||||
time.sleep(0.1)
|
||||
self._app.window(title_re='用户登录.*').window(control_id=0x3EE, class_name='Button').click()
|
||||
# 验证码登录
|
||||
# while True:
|
||||
# #获取id_code
|
||||
# id_code = self.verify_code(0x5DB)
|
||||
# print(id_code)
|
||||
# time.sleep(0.2)
|
||||
# self._app.window(title_re='用户登录.*').window(control_id=0x3EB, class_name='Edit').type_keys('{BACKSPACE}' * 6)
|
||||
# time.sleep(0.2)
|
||||
# self._app.window(title_re='用户登录.*').window(control_id=0x3EB, class_name='Edit').type_keys(id_code)
|
||||
#
|
||||
# time.sleep(0.2)
|
||||
# pywinauto.keyboard.send_keys("{ENTER}")
|
||||
# time.sleep(0.5)
|
||||
# try:
|
||||
# self._app.top_window().set_focus()
|
||||
# result_idcode = self._app.window(title_re='用户登录.*').window(control_id=0x3EB, class_name='Edit').window_text()
|
||||
# self.log.softInfo(result_idcode)
|
||||
# if '验证码错误' in result_idcode:
|
||||
# self.log.warn('Verification code error')
|
||||
# self._app.window(title_re='用户登录.*').window(control_id=0x2, class_name="Button").click()
|
||||
# time.sleep(0.5)
|
||||
# else:
|
||||
# break
|
||||
# except Exception as e:
|
||||
# self.log.info(f'登录失败:{e}')
|
||||
# break
|
||||
|
||||
time.sleep(6)
|
||||
# while True:
|
||||
# try:
|
||||
# self._app.window(title_re='网上股票交易系统.*').wait("ready")
|
||||
# break
|
||||
# except RuntimeError:
|
||||
# pass
|
||||
self._app.window(title_re='网上股票交易系统.*').wait("ready",timeout=60)
|
||||
self._app.window(title_re='网上股票交易系统.*').wait("ready",timeout=30)
|
||||
|
||||
# ip和mac入库
|
||||
new_mac = set_mac.get_macinfos()
|
||||
insert_data_df = pd.DataFrame([{'As_Of_Date': datetime.date.today(),
|
||||
'Broker': '中信建投',
|
||||
'Account_Number': self.account_name,
|
||||
'Timestamp': datetime.datetime.now(),
|
||||
'Proxy': True,
|
||||
'IP_Type': '动态IP',
|
||||
'Mac': new_mac,
|
||||
'IP': proxy_ip,
|
||||
'Port': proxy_port,
|
||||
'Location': item['prov'] + ':' + item['city']}])
|
||||
insert_data_df.to_sql('trade_proxyip', engine, schema='user_center', index=False, if_exists='append')
|
||||
self.log.info(f'IP:{proxy_ip} MAC:{new_mac} 已入库')
|
||||
#关闭弹窗
|
||||
self._close_prompt_windows()
|
||||
|
||||
|
2
tools.py
2
tools.py
@ -285,7 +285,7 @@ def set_proxy(proxy_ip: str, proxy_port: str):
|
||||
except Exception as e:
|
||||
logger.info(f"Proxifier未运行或连接失败: {e}")
|
||||
try:
|
||||
app = pywinauto.Application().start(f'"{proxifier_path}" "{new_ppx_path}"')
|
||||
app = pywinauto.Application().start(proxifier_path)
|
||||
window_title_pattern = r'temp\d+ - Proxifier'
|
||||
main_window = app.window(title_re=window_title_pattern).wait("ready", timeout=20)
|
||||
main_window.set_focus()
|
||||
|
Loading…
x
Reference in New Issue
Block a user