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:11] 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 59: Line 52:
         case ServerMessage.PayloadOneofCase.AccountDetails:         case ServerMessage.PayloadOneofCase.AccountDetails:
             ProcessAccountDetails(serverMessage.AccountDetails);             ProcessAccountDetails(serverMessage.AccountDetails);
-            _logger.LogInformation("Received account details: {AccountId}", serverMessage.AccountDetails.AccountId); 
             break;             break;
  
         case ServerMessage.PayloadOneofCase.AccountUpdate:         case ServerMessage.PayloadOneofCase.AccountUpdate:
             ProcessAccountUpdate(serverMessage.AccountUpdate);             ProcessAccountUpdate(serverMessage.AccountUpdate);
-            _logger.LogInformation("Received account update: {AccountId}", serverMessage.AccountUpdate.AccountId); 
             break;             break;
  
         case ServerMessage.PayloadOneofCase.AccountPosition:         case ServerMessage.PayloadOneofCase.AccountPosition:
             ProcessAccountPosition(serverMessage.AccountPosition);             ProcessAccountPosition(serverMessage.AccountPosition);
-            _logger.LogInformation("Received account position: {AccountId}, Market: {MarketId}", serverMessage.AccountPosition.AccountId, serverMessage.AccountPosition.MarketId); 
             break;             break;
  
         case ServerMessage.PayloadOneofCase.AccountSnapshot:         case ServerMessage.PayloadOneofCase.AccountSnapshot:
             ProcessAccountSnapshot(serverMessage.AccountSnapshot);             ProcessAccountSnapshot(serverMessage.AccountSnapshot);
-            _logger.LogInformation("Received account snapshot: {AccountId}", serverMessage.AccountSnapshot.AccountId); 
             break;             break;
  
         case ServerMessage.PayloadOneofCase.OrderUpdateMulti:         case ServerMessage.PayloadOneofCase.OrderUpdateMulti:
             ProcessOrderUpdateMulti(serverMessage.OrderUpdateMulti);             ProcessOrderUpdateMulti(serverMessage.OrderUpdateMulti);
-            _logger.LogInformation("Received order update multi: {AccountId}", serverMessage.OrderUpdateMulti.AccountId); 
             break;             break;
  
         case ServerMessage.PayloadOneofCase.MarketDetails:         case ServerMessage.PayloadOneofCase.MarketDetails:
             ProcessMarketDetails(serverMessage.MarketDetails);             ProcessMarketDetails(serverMessage.MarketDetails);
-            _logger.LogInformation("Received market details: {MarketId}", serverMessage.MarketDetails.MarketId); 
             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:
 +                 _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.1741993892.txt.gz
  • Last modified: 2025/03/14 23:11
  • by chad