Пример #1
0
    def load_trader_data(self, account_id):
        """加载交易员数据"""
        account = query_account_one(account_id, self.db)

        if isinstance(account, dict):
            trader = Trader(self.event_engine, account, self.pst_active,
                            LoadDataMode.TRADING, self.db)
            self.trader_dict[account_id] = trader
Пример #2
0
 def creat(self, info: dict):
     """创建账户"""
     account_dict = on_account_add(info, self.db)
     if account_dict:
         token = account_dict['account_id']
         if not self.trader_dict.get(token):
             account = Trader(self.event_engine, account_dict,
                              self.pst_active, LoadDataMode.CREAT, self.db)
             self.trader_dict[token] = account
             return account_dict
Пример #3
0
 def login(self, token: str):
     """
     账户登录
     账户登录的过程就是将账户信息、持仓信息、订单信息加载到内存中,
     并将账户所有信息比拟一个交易员放到交易员字典中
     :param token: 账户ID
     :param db: 数据库对象
     :return: None
     """
     trader = self.trader_dict.get(token)
     # 账户未登陆
     if not trader:
         # 查询账户
         account_dict = query_account_one(token, self.db)
         if account_dict:
             account = Trader(self.event_engine, account_dict,
                              self.pst_active, self.load_data_mode, self.db)
             self.trader_dict[token] = account
             return account_dict
         else:
             return False
     else:
         account = copy.deepcopy(trader.account)
         return account.__dict__