Example #1
0
 def position(self):
     for i in range(3):
         try:
             self._switch_left_menus(["查询[F4]", "资金股票"])
             return self._get_grid_data(self._config.COMMON_GRID_CONTROL_ID)
         except:
             logger.exception("position error")
             self.wait(5)
Example #2
0
 def balance(self):
     for i in range(3):
         try:
             self._switch_left_menus(["查询[F4]", "资金股票"])
             return self._get_balance_from_statics()
         except:
             logger.exception("balance error")
             self.wait(5)
Example #3
0
 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())
     except (findwindows.ElementNotFoundError, timings.TimeoutError,
             RuntimeError) as ex:
         logger.exception('check pop dialog timeout')
         return False
Example #4
0
    def _get_clipboard_data(self) -> str:
        if Copy._need_captcha_reg:
            if (
                self._trader.app.top_window()
                .window(class_name="Static", title_re="验证码")
                .exists(timeout=1)
            ):
                file_path = "tmp.png"
                count = 5
                found = False
                while count > 0:
                    self._trader.app.top_window().window(
                        control_id=0x965, class_name="Static"
                    ).capture_as_image().save(
                        file_path
                    )  # 保存验证码

                    captcha_num = captcha_recognize(file_path)  # 识别验证码
                    logger.info("captcha result-->" + captcha_num)
                    if len(captcha_num) == 4:
                        self._trader.app.top_window().window(
                            control_id=0x964, class_name="Edit"
                        ).set_text(
                            captcha_num
                        )  # 模拟输入验证码

                        self._trader.app.top_window().set_focus()
                        pywinauto.keyboard.SendKeys("{ENTER}")  # 模拟发送enter,点击确定
                        try:
                            logger.info(
                                self._trader.app.top_window()
                                .window(control_id=0x966, class_name="Static")
                                .window_text()
                            )
                        except Exception as ex:  # 窗体消失
                            logger.exception(ex)
                            found = True
                            break
                    count -= 1
                    self._trader.wait(0.1)
                    self._trader.app.top_window().window(
                        control_id=0x965, class_name="Static"
                    ).click()
                if not found:
                    self._trader.app.top_window().Button2.click()  # 点击取消
            else:
                Copy._need_captcha_reg = False
        count = 5
        while count > 0:
            try:
                return pywinauto.clipboard.GetData()
            # pylint: disable=broad-except
            except Exception as e:
                count -= 1
                logger.exception("%s, retry ......", e)
Example #5
0
 def _get_left_menus_handle(self):
     count = 2
     while True:
         try:
             handle = self._main.child_window(control_id=129,
                                              class_name="SysTreeView32")
             if count <= 0:
                 return handle
             # sometime can't find handle ready, must retry
             handle.wait("ready", 2)
             return handle
         # pylint: disable=broad-except
         except Exception as ex:
             logger.exception(
                 "error occurred when trying to get left menus")
         count = count - 1
Example #6
0
 def track_strategy_worker(self, strategy, name, interval=10, **kwargs):
     """跟踪下单worker
     :param strategy: 策略id
     :param name: 策略名字
     :param interval: 轮询策略的时间间隔,单位为秒"""
     while True:
         try:
             transactions = self.query_strategy_transaction(
                 strategy, **kwargs
             )
         # pylint: disable=broad-except
         except Exception as e:
             logger.exception("无法获取策略 %s 调仓信息, 错误: %s, 跳过此次调仓查询", name, e)
             time.sleep(3)
             continue
         for transaction in transactions:
             trade_cmd = {
                 "strategy": strategy,
                 "strategy_name": name,
                 "action": transaction["action"],
                 "stock_code": transaction["stock_code"],
                 "amount": transaction["amount"],
                 "price": transaction["price"],
                 "datetime": transaction["datetime"],
             }
             if self.is_cmd_expired(trade_cmd):
                 continue
             if trade_cmd["amount"] != 0:
                 logger.info(
                     "策略 [%s] 发送指令到交易队列, 股票: %s 动作: %s 数量: %s 价格: %s 信号产生时间: %s",
                     name,
                     trade_cmd["stock_code"],
                     trade_cmd["action"],
                     trade_cmd["amount"],
                     trade_cmd["price"],
                     trade_cmd["datetime"],
                 )
             self.trade_queue.put(trade_cmd)
             self.add_cmd_to_expired_cmds(trade_cmd)
         try:
             for _ in range(interval):
                 time.sleep(1)
         except KeyboardInterrupt:
             logger.info("程序退出")
             break