All account and order data is obtained via the Accounts property of the Host. The Accounts object contains a list of all the accounts that the user can see. This list is requested as soon as login has succeeded. AccountDetails events are raised as each account is received. All account updates (details, updates, and positions) are buffered and raised in batches where possible. The account events are raised from the Account object itself, and from the AccountList object as well. The PositionUpdate event is also raised from the Position object as well (found within the Account’s Positon List).
To receive account updates, positions and order information you must first subscribe to the account:
' Reference to the accounts list.
Private WithEvents moAccounts As AccountList
…
' Set the account list reference so that we can get Account and order events.
moAccounts = moAPI.Accounts
' Display the account list.
For Each oAccount As Account In moAPI.Accounts
Trace.WriteLine("Account: " & oAccount.Description)
' Subscribe to the account.
oAccount.Subscribe()
Next
The
AccountUpdate event is raised when the account’s overall balance, P&L, margin or status changes. The update is applied to the Account object itself.
' Event that is raised when the accounts overall balance, P&L or margin details have changed.
Private Sub moAccounts_AccountUpdate(ByVal poAccounts As T4.API.AccountList.UpdateList) Handles moAccounts.AccountUpdate
' Display the account balance.
For Each oAccount As Account In poAccounts
Trace.WriteLine("Account: " & oAccount.Description _
& ", Balance: " & oAccount.Balance)
Next
End Sub
The properties of the Account object are described
here.
The
PositionUpdate event is raised when the account’s position in an individual market changes. This includes changes to the P&L, margin, net position, working position. The update is applied to the Position object itself (which is found in the Account position list).
' Event that is raised when positions for accounts have changed.
Private Sub moAccounts_PositionUpdate(ByVal poPositions As T4.API.AccountList.PositionUpdateList) Handles moAccounts.PositionUpdate
' Display the position details.
For Each oUpdate As AccountList.PositionUpdateList.PositionUpdate In poPositions
Trace.WriteLine("Account: " & _
oUpdate.Account.Description & ", Market: " & _
oUpdate.Position.Market.Description & _
", Net: " & oUpdate.Position.Net)
Next
End Sub
Note: When a position or order update is sent the server checks to see if you have the market details that it applies to, if not then you will receive the market details prior to receiving the position and order details. This means that if you are creating an application that just watches the orders in the system that you do not have to request the details of all the markets. They will automatically be sent to the API as needed.
The properties of the Position object are described
here.