我目前看convert_order_request_lock 这段函数,我现在想要对此增加一个判断需求,在 if td_volume and self.exchange not in close_yd_exchanges: 这段我希望加上一个判断条件是可用资金是否够开目前contract合约, 那么需要用到账户可用资金的判断,请问在这边有什么办法可以解决呢?
我目前看convert_order_request_lock 这段函数,我现在想要对此增加一个判断需求,在 if td_volume and self.exchange not in close_yd_exchanges: 这段我希望加上一个判断条件是可用资金是否够开目前contract合约, 那么需要用到账户可用资金的判断,请问在这边有什么办法可以解决呢?
可以通过在OffsetConverter
中增加get_account
方法来解决。以下是简单实现:
OffsetConverter
中添加get_account
方法def get_account(self) -> AccountData:
"""获取账户信息"""
accounts = self.main_engine.get_all_accounts()
if accounts:
return accounts[0] # 返回第一个账户
return None
convert_order_request_lock
中使用get_account
if td_volume and self.exchange not in close_yd_exchanges:
account = self.get_account()
if account and account.available >= required_funds: # 判断可用资金
req_open: OrderRequest = copy(req)
req_open.offset = Offset.OPEN
return [req_open]
get_account
方法获取账户信息,判断可用资金是否足够开仓。希望这能帮到你!