In SaxoTraderGo, the list of streaming NetPositions can be expanded to reveal the underlying positions. Here is a short demonstration of how it is done.
Upon login a single NetPosition subscription is started. All accounts/single account mode is determined by the state of the account selector.
By default, all Netpositions are collapsed. Note the EURUSD Netposition:
Request to start the subscription:
POST https://gateway.saxotrader.com/sim/openapi/port/v1/netpositions/subscriptions/active HTTP/1.1 201 Created { "Arguments":{ "FieldGroups":["NetPositionBase","NetPositionView","DisplayAndFormat","ExchangeInfo","SingleAndClosedPositionsBase","SingleAndClosedPositionsView","SingleAndClosedPositions"]", "ClientKey":"6LvV4vnUsU8782kJtBgnjQ==", "AccountKey":"1gm4hJD76DKVkt5XBSYyrw==" }, "RefreshRate":2000, "ContextId":"123456789", "ReferenceId":"1" }
The initial snapshot of Netpositions is used to populate the list and streaming updates are applied as the are received. In SaxoTraderGo, NetPositions consisting of a single position cannot be expanded and related order details are included (see AUDNZD). To allow this they use fields from the SingleAndClosedPositions FieldGroups. These entities include related order details and are only populated if the Netposition consist of a single or of closed positions.
If the user expands a Netposition, a new position subscription with a netposition filter is started.
Example of the Position subscription with a NetPositionId:
POST https://gateway.saxotrader.com/sim/openapi/port/v1/positions/subscriptions/active HTTP/1.1 201 Created { "Arguments":{ "NetPositionId":"EURUSD_FxSpot", "ClientKey":"6LvV4vnUsU8782kJtBgnjQ==", "AccountKey":"1gm4hJD76DKVkt5XBSYyrw==" }, "RefreshRate":2000, "ContextId":"123456789", "ReferenceId":"2" }
When the Netposition is contracted, the position subscription is removed. Since only a limited amount of simultaneous Position subscriptions are allowed, it is important to disable the position subscription.
DELETE https://gateway.saxobank.com/sim/openapi/port/v1/positions/subscriptions/123456789/2