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:11] – chad | developers:websocket:accounts [2025/03/15 13:18] (current) – chad | ||
|---|---|---|---|
| Line 24: | Line 24: | ||
| 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. | ||
| - | |||
| - | ===== Account Snapshot ===== | ||
| - | |||
| - | The **AccountSnapshot** message is a **batch message** that contains the latest state of an account including: | ||
| - | |||
| - | * Account balances | ||
| - | * Open positions | ||
| - | * Working orders | ||
| Line 38: | 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: | ||
| - | < | + | < |
| - | ```csharp | + | |
| private void HandleAccountMessage(ServerMessage serverMessage) | private void HandleAccountMessage(ServerMessage serverMessage) | ||
| { | { | ||
| Line 59: | Line 52: | ||
| case ServerMessage.PayloadOneofCase.AccountDetails: | case ServerMessage.PayloadOneofCase.AccountDetails: | ||
| ProcessAccountDetails(serverMessage.AccountDetails); | ProcessAccountDetails(serverMessage.AccountDetails); | ||
| - | _logger.LogInformation(" | ||
| break; | break; | ||
| case ServerMessage.PayloadOneofCase.AccountUpdate: | case ServerMessage.PayloadOneofCase.AccountUpdate: | ||
| ProcessAccountUpdate(serverMessage.AccountUpdate); | ProcessAccountUpdate(serverMessage.AccountUpdate); | ||
| - | _logger.LogInformation(" | ||
| break; | break; | ||
| case ServerMessage.PayloadOneofCase.AccountPosition: | case ServerMessage.PayloadOneofCase.AccountPosition: | ||
| ProcessAccountPosition(serverMessage.AccountPosition); | ProcessAccountPosition(serverMessage.AccountPosition); | ||
| - | _logger.LogInformation(" | ||
| break; | break; | ||
| case ServerMessage.PayloadOneofCase.AccountSnapshot: | case ServerMessage.PayloadOneofCase.AccountSnapshot: | ||
| ProcessAccountSnapshot(serverMessage.AccountSnapshot); | ProcessAccountSnapshot(serverMessage.AccountSnapshot); | ||
| - | _logger.LogInformation(" | ||
| break; | break; | ||
| case ServerMessage.PayloadOneofCase.OrderUpdateMulti: | case ServerMessage.PayloadOneofCase.OrderUpdateMulti: | ||
| ProcessOrderUpdateMulti(serverMessage.OrderUpdateMulti); | ProcessOrderUpdateMulti(serverMessage.OrderUpdateMulti); | ||
| - | _logger.LogInformation(" | ||
| break; | break; | ||
| case ServerMessage.PayloadOneofCase.MarketDetails: | case ServerMessage.PayloadOneofCase.MarketDetails: | ||
| ProcessMarketDetails(serverMessage.MarketDetails); | ProcessMarketDetails(serverMessage.MarketDetails); | ||
| - | _logger.LogInformation(" | ||
| break; | break; | ||
| Line 96: | Line 83: | ||
| + | ===== Account Snapshot ===== | ||
| + | The **AccountSnapshot** message is a **batch message** that contains the latest state of an account including: | ||
| + | |||
| + | * Account balances | ||
| + | * Open positions | ||
| + | * Working orders | ||
| + | |||
| + | <code c#> | ||
| + | private void ProcessAccountSnapshot(AccountSnapshot snapshotMessage) | ||
| + | { | ||
| + | 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: | ||
| + | | ||
| + | | ||
| + | } | ||
| + | |||
| + | } | ||
| + | </ | ||