developers:websocket:accounts

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
developers:websocket:accounts [2025/03/14 23:12] chaddevelopers: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:
  
-<code> +<code c#>
-```csharp+
 private void HandleAccountMessage(ServerMessage serverMessage) private void HandleAccountMessage(ServerMessage serverMessage)
 { {
Line 90: 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:
 +                 _details = snapshotMessage.AccountDetails;
 +                 break;
 +
 +            case AccountSnapshotMessage.PayloadOneofCase.AccountUpdate:
 +                 _update = snapshotMessage.AccountUpdate;
 +                 break;
 +
 +            case AccountSnapshotMessage.PayloadOneofCase.AccountPosition:
 +                 {
 +                      var position = _positions.AddOrUpdate(
 +                           snapshotMessage.AccountPosition.MarketId,
 +                           // Add new Position if key doesn't exist
 +                           _ => new Position(this, snapshotMessage.AccountPosition, _loggerFactory.CreateLogger<Position>()),
 +                           // Update existing Position
 +                           (_, existingPosition) => existingPosition);
 +
 +                      if (position != null)
 +                      {
 +                           position.UpdateWithMessage(snapshotMessage);
 +                           updatedPositions.Add(position);
 +                      }
 +
 +                      _logger.LogInformation("=> SNAPSHOT => AccountPosition: {AccountId} / {MarketID}", snapshotMessage.AccountPosition.AccountId, snapshotMessage.AccountPosition.MarketId);
 +                 }
 +                 break;
 +
 +            case AccountSnapshotMessage.PayloadOneofCase.OrderUpdateMulti:
 +                 var orderMultiUpdates = ProcessOrderUpdateMulti(snapshotMessage.OrderUpdateMulti);
 +                 updatedOrders.AddRange(orderMultiUpdates.Select(res => res.Order));
 +                 updatedTrades.AddRange(orderMultiUpdates.SelectMany(res => res.Trades));
 +                 break;
 +
 +            default:
 +                 _logger.LogInformation($" > Unhandled Snapshot Message: {snapshotMessage.PayloadCase}");
 +                 break;
 +     }
 +
 +}
 +</code>
  
  
  • developers/websocket/accounts.1741993960.txt.gz
  • Last modified: 2025/03/14 23:12
  • by chad