Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
developers:websocket:accounts [2025/03/14 23:04] – chad | developers:websocket:accounts [2025/03/15 13:18] (current) – chad | ||
---|---|---|---|
Line 23: | Line 23: | ||
Once subscribed, the server will begin streaming real-time updates for the selected accounts. | Once subscribed, the server will begin streaming real-time updates for the selected accounts. | ||
+ | |||
+ | |||
===== Handling Account Updates ===== | ===== Handling Account Updates ===== | ||
Line 28: | Line 30: | ||
The server sends account-related updates as separate messages. These include: | The server sends account-related updates as separate messages. These include: | ||
+ | * **AccountSubscribeResponse** – A response message indicating whether the account subscription was successful or not. | ||
+ | * **AccountSnapshot** – A batch message containing the latest state of the account. | ||
* **AccountDetails** – Provides static information about the account. | * **AccountDetails** – Provides static information about the account. | ||
* **AccountUpdate** – Sends real-time updates for account values. | * **AccountUpdate** – Sends real-time updates for account values. | ||
* **AccountPosition** – Reports current open positions. | * **AccountPosition** – Reports current open positions. | ||
- | * **AccountSnapshot** – A batch message containing the latest state of the account. | ||
* **OrderUpdateMulti** – Sends batch updates for a position. | * **OrderUpdateMulti** – Sends batch updates for a position. | ||
+ | * **MarketDetails** – Market details are always sent before a new position is sent to ensure the client has the altest pricing details for the market. | ||
Example message handling structure: | Example message handling structure: | ||
- | private void HandleAccountMessage(ServerMessage serverMessage) { switch (serverMessage.PayloadCase) { case ServerMessage.PayloadOneofCase.AccountSubscribeResponse: | + | <code c#> |
+ | private void HandleAccountMessage(ServerMessage serverMessage) | ||
+ | { | ||
+ | | ||
+ | | ||
+ | | ||
+ | | ||
+ | serverMessage.AccountSubscribeResponse.Errors.ToList().ForEach(e => _logger.LogWarning(" | ||
+ | | ||
- | cpp | + | |
- | Copy | + | |
- | Edit | + | break; |
- | | + | |
- | case ServerMessage.PayloadOneofCase.AccountUpdate: | + | |
- | case ServerMessage.PayloadOneofCase.AccountPosition: | + | |
- | case ServerMessage.PayloadOneofCase.AccountSnapshot: | + | |
- | case ServerMessage.PayloadOneofCase.OrderUpdateMulti: | + | |
- | HandleAccountUpdate(serverMessage); | + | |
- | break; | + | |
- | | + | |
- | | + | |
- | break; | + | break; |
- | default: | + | case ServerMessage.PayloadOneofCase.AccountPosition: |
- | _logger.LogWarning(" | + | ProcessAccountPosition(serverMessage.AccountPosition); |
- | break; | + | break; |
- | } | + | |
+ | | ||
+ | ProcessAccountSnapshot(serverMessage.AccountSnapshot); | ||
+ | break; | ||
+ | |||
+ | case ServerMessage.PayloadOneofCase.OrderUpdateMulti: | ||
+ | ProcessOrderUpdateMulti(serverMessage.OrderUpdateMulti); | ||
+ | break; | ||
+ | |||
+ | case ServerMessage.PayloadOneofCase.MarketDetails: | ||
+ | ProcessMarketDetails(serverMessage.MarketDetails); | ||
+ | break; | ||
+ | |||
+ | default: | ||
+ | | ||
+ | break; | ||
+ | } | ||
} | } | ||
+ | </ | ||
+ | |||
- | markdown | ||
- | Copy | ||
- | Edit | ||
===== Account Snapshot ===== | ===== Account Snapshot ===== | ||
- | The **AccountSnapshot** message is a **batch message** that contains the latest state of an account. Instead of sending individual updates for each position or order, the snapshot provides a consolidated view of: | + | The **AccountSnapshot** message is a **batch message** that contains the latest state of an account |
* Account balances | * Account balances | ||
Line 71: | Line 91: | ||
* Working orders | * Working orders | ||
- | Clients should process **AccountSnapshot** messages carefully as they represent the most recent known state of | + | <code c#> |
+ | private void ProcessAccountSnapshot(AccountSnapshot | ||
+ | { | ||
+ | switch (snapshotMessage.PayloadCase) | ||
+ | { | ||
+ | case AccountSnapshotMessage.PayloadOneofCase.AccountDetails: | ||
+ | | ||
+ | | ||
+ | |||
+ | case AccountSnapshotMessage.PayloadOneofCase.AccountUpdate: | ||
+ | | ||
+ | | ||
+ | |||
+ | case AccountSnapshotMessage.PayloadOneofCase.AccountPosition: | ||
+ | { | ||
+ | var position = _positions.AddOrUpdate( | ||
+ | | ||
+ | // Add new Position if key doesn' | ||
+ | _ => new Position(this, | ||
+ | // Update existing Position | ||
+ | (_, existingPosition) => existingPosition); | ||
+ | |||
+ | if (position != null) | ||
+ | { | ||
+ | | ||
+ | | ||
+ | } | ||
+ | |||
+ | _logger.LogInformation(" | ||
+ | } | ||
+ | | ||
+ | |||
+ | case AccountSnapshotMessage.PayloadOneofCase.OrderUpdateMulti: | ||
+ | var orderMultiUpdates = ProcessOrderUpdateMulti(snapshotMessage.OrderUpdateMulti); | ||
+ | | ||
+ | | ||
+ | | ||
+ | |||
+ | default: | ||
+ | | ||
+ | | ||
+ | } | ||
+ | |||
+ | } | ||
+ | </ | ||
+ |