trade29.sc.SCBridge.subscribe_to_position_updates#
- SCBridge.subscribe_to_position_updates(key: str, update_on_qty_changes: bool = True, update_on_open_pnl_changes: bool = True) int#
Subscribes to updates on the account position; including quantity, average price, and open profit/loss.
Given a key, this method subscribes to information on the account position from the same chart on which the SC-dX study with the matching key is applied. With the returned request id, the bridge’s response queue can be filtered for updates.
- Parameters:
- keystr
The key matching the key given to the SC-dX custom study in Sierra Chart.
- update_on_qty_changesbool, default True
Whether or not to send updates when the position quantity changes. The update will still contain information on position quantity if this is
False. If both this and update_on_open_pnl_changes are set toFalsethen no position updates can be sent.- update_on_open_pnl_changesbool, default True
Whether or not to send updates when the open profit/loss changes. The update will still contain information on open p/l if this is
False. If both this and update_on_qty_changes are set toFalsethen no position updates can be sent.
- Returns:
- int
A request id that can be used to filter the SCBridge’s
get_response_queue()for position updates.
Examples
from trade29.sc import SCBridge bridge = SCBridge() # Subscribe to updates on the position request_id = bridge.subscribe_to_position_updates(key = 'xx') response_queue = bridge.get_response_queue() while True: msg = response_queue.get() if msg.request_id == request_id: print(f"qty: {msg.position_quantity}, avg_price: {msg.average_price}, open_p/l: {msg.open_profit_loss}") # Play with the trade window and verify that new positions are printed