示例#1
0
    def __init__(self):
        # TODO: 上传结算单
        logger.info("start")

        QCoreApplication.setAttribute(Qt.AA_EnableHighDpiScaling)
        QCoreApplication.setAttribute(Qt.AA_UseHighDpiPixmaps)

        super(RQAmsHelper, self).__init__()

        self._ctp_controller = CtpController()
        self._ctp_controller.update_state_info.connect(self._update_account_state_info)
        self._ctp_controller.on_trades.connect(self._on_trades)
        self._persister = Persister()

        self._app = QApplication()
        self._main_window = MainWindow(self._persister)
        self._login_window = LoginWindow()
        self._create_account_window = CreateAccountWindow()
        self._modify_account_window = ModifyAccountWindow()

        self._login_window.login.connect(self._login)
        self._main_window.logout_button_pushed.connect(self._switch_to_login_window)
        self._main_window.create_button_pushed.connect(self._open_create_account_window)
        self._main_window.modify_button_pushed.connect(self._open_modify_account_window)
        self._main_window.connect_account.connect(self._connect_account)
        self._main_window.disconnect_account.connect(self._disconnect_account)
        self._modify_account_window.account_modified.connect(self._account_modified)
        self._create_account_window.account_created.connect(self._account_created)
        self._server_url = os.environ.get("RQAMS_URL", "https://www.ricequant.com")

        self._uploaded_exec_ids = set(self._persister.get_uploaded_exec_ids())

        LoginExpiredException.after_msg_box_slot = self._switch_to_login_window
示例#2
0
 def _handle_exception(self, e):
     if isinstance(e, RQAmsHelperException):
         e.exec_msg_box()
     else:
         logger.error("consumer failed: " + str(e))
     logger.info("restart consumer")
     self.stop()
     self.start()
示例#3
0
 def connect_account(self, ctp_account: CtpAccount):
     logger.info(f"create account {ctp_account.account}")
     account = ctp_account.account
     with self._lock:
         self._account_cache[account] = ctp_account
         if account in self._api_pool:
             self.update_state_info.emit(account, *self._api_pool[account].state_info)
         else:
             self._api_pool[account] = CtpTraderApi(ctp_account, self._state_queue, self._trade_queue)
示例#4
0
    def _on_trades(self, trades: List[Tuple[str, Trade]]):
        trade_dicts = {}
        exec_ids = set()
        for account, trade in trades:
            if trade.exec_id in self._uploaded_exec_ids:
                continue
            trade_dicts.setdefault(account, {})[trade.exec_id] = trade
            exec_ids.add(trade.exec_id)

        for account, trade_dict in trade_dicts.items():
            current_accounts = self._main_window.current_accounts
            if account in current_accounts:
                current_accounts[account].portfolio.trades.update(trade_dict)
                logger.info(f"trades pushed: {trade_dict}")
        self._persister.save_upload_exec_id(exec_ids)
        self._uploaded_exec_ids.update(exec_ids)
示例#5
0
 def disconnect_account(self, account: str):
     logger.info(f"disconnect account {account}")
     with self._lock:
         if account in self._api_pool:
             self._api_pool.pop(account).Release()
         self.update_state_info.emit(account, False, "已断开")
示例#6
0
 def _log_info(self, msg: str):
     logger.info("{}__{}__{}: {}".format(
         self._account.account, self._connect_state, self._login_state, msg
     ))