Skip to content

Commit

Permalink
同花顺网上交易5.0 刷新(refresh)
Browse files Browse the repository at this point in the history
  • Loading branch information
qzhjiang committed Jun 4, 2020
1 parent a86bd22 commit 38a83c3
Showing 1 changed file with 23 additions and 21 deletions.
44 changes: 23 additions & 21 deletions easytrader/clienttrader.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ def __init__(self):
self._config = client.create(self.broker_type)
self._app = None
self._main = None
self._toolbar = None

def _set_foreground(self, grid=None):
if grid is None:
Expand Down Expand Up @@ -121,6 +122,7 @@ def connect(self, exe_path=None, **kwargs):
self._app = pywinauto.Application().connect(path=connect_path, timeout=10)
self._close_prompt_windows()
self._main = self._app.top_window()
self._toolbar = self._main.child_window(class_name="ToolbarWindow32")

@property
def broker_type(self):
Expand Down Expand Up @@ -241,6 +243,7 @@ def market_trade(self, security, amount, ttype=None, limit_price=None, **kwargs)
:param ttype: 市价委托类型,默认客户端默认选择,
深市可选 ['对手方最优价格', '本方最优价格', '即时成交剩余撤销', '最优五档即时成交剩余 '全额成交或撤销']
沪市可选 ['最优五档成交剩余撤销', '最优五档成交剩余转限价']
:param limit_price:
:return: {'entrust_no': '委托单号'}
"""
Expand Down Expand Up @@ -287,9 +290,7 @@ def auto_ipo(self):

if len(stock_list) == 0:
return {"message": "今日无新股"}
invalid_list_idx = [
i for i, v in enumerate(stock_list) if v[self.config.AUTO_IPO_NUMBER] <= 0
]
invalid_list_idx = [i for i, v in enumerate(stock_list) if v[self.config.AUTO_IPO_NUMBER] <= 0]

if len(stock_list) == len(invalid_list_idx):
return {"message": "没有发现可以申购的新股"}
Expand All @@ -309,8 +310,8 @@ def auto_ipo(self):
def _click_grid_by_row(self, row):
x = self._config.COMMON_GRID_LEFT_MARGIN
y = (
self._config.COMMON_GRID_FIRST_ROW_HEIGHT
+ self._config.COMMON_GRID_ROW_HEIGHT * row
self._config.COMMON_GRID_FIRST_ROW_HEIGHT
+ self._config.COMMON_GRID_ROW_HEIGHT * row
)
self._app.top_window().child_window(
control_id=self._config.COMMON_GRID_CONTROL_ID,
Expand All @@ -322,12 +323,12 @@ def is_exist_pop_dialog(self):
self.wait(0.5) # wait dialog display
try:
return (
self._main.wrapper_object() != self._app.top_window().wrapper_object()
self._main.wrapper_object() != self._app.top_window().wrapper_object()
)
except (
findwindows.ElementNotFoundError,
timings.TimeoutError,
RuntimeError,
findwindows.ElementNotFoundError,
timings.TimeoutError,
RuntimeError,
) as ex:
logger.exception("check pop dialog timeout")
return False
Expand Down Expand Up @@ -387,8 +388,8 @@ def __get_top_window_pop_dialog(self):
def _get_pop_dialog_title(self):
return (
self._app.top_window()
.child_window(control_id=self._config.POP_DIALOD_TITLE_CONTROL_ID)
.window_text()
.child_window(control_id=self._config.POP_DIALOD_TITLE_CONTROL_ID)
.window_text()
)

def _set_trade_params(self, security, price, amount):
Expand Down Expand Up @@ -480,16 +481,17 @@ def _get_left_menus_handle(self):
def _cancel_entrust_by_double_click(self, row):
x = self._config.CANCEL_ENTRUST_GRID_LEFT_MARGIN
y = (
self._config.CANCEL_ENTRUST_GRID_FIRST_ROW_HEIGHT
+ self._config.CANCEL_ENTRUST_GRID_ROW_HEIGHT * row
self._config.CANCEL_ENTRUST_GRID_FIRST_ROW_HEIGHT
+ self._config.CANCEL_ENTRUST_GRID_ROW_HEIGHT * row
)
self._app.top_window().child_window(
control_id=self._config.COMMON_GRID_CONTROL_ID,
class_name="CVirtualGridCtrl",
).double_click(coords=(x, y))

def refresh(self):
self._switch_left_menus_by_shortcut("{F5}", sleep=0.1)
# self._switch_left_menus(["买入[F1]"], sleep=0.05)
self._toolbar.button(3).click() # 我的交易客户端工具栏中“刷新”是排在第4个的,所以其索引值是3

@perf_clock
def _handle_pop_dialogs(self, handler_class=pop_dialog_handler.PopDialogHandler):
Expand All @@ -514,13 +516,13 @@ def login(self, user, password, exe_path, comm_password=None, **kwargs):
pass

def prepare(
self,
config_path=None,
user=None,
password=None,
exe_path=None,
comm_password=None,
**kwargs
self,
config_path=None,
user=None,
password=None,
exe_path=None,
comm_password=None,
**kwargs
):
"""
登陆客户端
Expand Down

0 comments on commit 38a83c3

Please sign in to comment.