Skip to content

Commit 1d81f46

Browse files
committed
[Mod] 增加基于vt_symbol和direction的持仓查询函数
1 parent 516c26f commit 1d81f46

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

vnpy_scripttrader/engine.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,15 @@ def get_position(self, vt_positionid: str, use_df: bool = False) -> PositionData
255255
""""""
256256
return get_data(self.main_engine.get_position, arg=vt_positionid, use_df=use_df)
257257

258+
def get_position_(self, vt_symbol: str, direction: Direction, use_df: bool = False) -> PositionData:
259+
""""""
260+
contract: ContractData = self.main_engine.get_contract(vt_symbol)
261+
if not contract:
262+
return None
263+
264+
vt_positionid: str = f"{contract.gateway_name}.{contract.vt_symbol}.{direction.value}"
265+
return get_data(self.main_engine.get_position, arg=vt_positionid, use_df=use_df)
266+
258267
def get_all_positions(self, use_df: bool = False) -> Sequence[PositionData]:
259268
""""""
260269
return get_data(self.main_engine.get_all_positions, use_df=use_df)

0 commit comments

Comments
 (0)