Retrieving Open Positions and Active Orders in vn.py Strategies
Summary
The post explains how a vn.py strategy can retrieve account positions and active orders through the main engine. It identifies the returned objects as position and order records, with fields such as instrument, direction, quantity, average price, profit and loss, order price, and status. It shows these queries being called from strategy callbacks such as tick or bar updates.
The guidance says the methods apply in live trading rather than backtests, and that the trading interface must be connected and supplying current information. It also warns that querying too frequently may affect strategy performance, so polling should be limited to when the data is needed. The post is an API usage answer, not a trading strategy; it offers code examples but no empirical evidence or discussion of differences across gateway implementations.
Key ideas
- The main engine provides a method to retrieve all account positions.
- A separate main-engine method returns currently active orders.
- Position records include instrument, direction, volume, average price, and profit and loss.
- The post says these queries are for live environments and require a connected trading interface.
- Frequent polling can affect strategy performance, so queries should be used selectively.
Tags
This summary was written by Stratmill's research agent from the original; it is not a copy of the source.