> ## Documentation Index
> Fetch the complete documentation index at: https://docs.voxfi.com.br/llms.txt
> Use this file to discover all available pages before exploring further.

# User Channel

> Receiving updates about your own orders and transactions

## Overview

The `user` channel allows you to receive real-time updates about your own orders and transactions. This channel is useful for monitoring your order status, receiving execution notifications, and tracking your transactions.

## Authentication

The `user` channel **requires authentication** using your API key (`X-Api-Key`). The key must be provided in the `auth` field of the subscribe message.

## Subscribe

To subscribe to the user channel:

```json theme={null}
{
  "type": "subscribe",
  "channel": "user",
  "auth": "your-api-key-here"
}
```

### Requirements

* **`auth`** (required): Your API key (`X-Api-Key`)

<Warning>
  Keep your API key secure and never expose it in client code or public repositories.
</Warning>

## Received Messages

### User Update

Received when there are changes to your orders or transactions.

**Structure:**

```json theme={null}
{
  "msg_type": "order-info",
  "order_id": 123,
  "trade_type": "order.filled",
  "user_id": "string",
  "event_id": "string",
  "market_id": "string",
  "side": "BUY",
  "contract_type": "YES",
  "price": 40,
  "quantity": 10,
  "transaction_fee": 10
}
```

### Fields

* **`trade_type`**: What happened to the order (`order.filled`, `order.partially_filled`, `order.placed`, `order.cancelled`);
* **`order_id`**: The affected order ID;
* **`user_id`**: Your user ID;
* **`event_id`**: Related event ID;
* **`market_id`**: Related market ID;
* **`side`**: Order side (`BUY` or `SELL`);
* **`contract_type`**: Contract type (`YES` or `NO`);
* **`price`**: Transaction price in ticks;
* **`quantity`**: Number of contracts;
* **`transaction_fee`**: Transaction fee in cents.

## Usage Example

<CodeGroup>
  ```javascript JavaScript theme={null}
  const ws = new WebSocket('wss://data-ws-dev.voxfi.com.br');
  const API_KEY = 'your-api-key-here';

  ws.onopen = () => {
    // Subscribe to user channel
    ws.send(JSON.stringify({
      type: 'subscribe',
      channel: 'user',
      auth: API_KEY
    }));
  };

  ws.onmessage = (event) => {
    const data = JSON.parse(event.data);
    
    if (data.user_id) {
      console.log('User update received:', data);
      
      // Process update
      if (data.side === 'BUY') {
        console.log(`Buy executed: ${data.quantity} ${data.contract_type} contracts at ${data.price} ticks`);
      } else {
        console.log(`Sell executed: ${data.quantity} ${data.contract_type} contracts at ${data.price} ticks`);
      }
    }
  };
  ```

  ```python Python theme={null}
  import asyncio
  import websockets
  import json

  API_KEY = 'your-api-key-here'

  async def subscribe_user():
      uri = "wss://data-ws-dev.voxfi.com.br"
      
      async with websockets.connect(uri) as websocket:
          # Subscribe to user channel
          subscribe_msg = {
              "type": "subscribe",
              "channel": "user",
              "auth": API_KEY
          }
          await websocket.send(json.dumps(subscribe_msg))
          
          # Receive messages
          async for message in websocket:
              data = json.loads(message)
              
              if "user_id" in data:
                  print("User update received:", data)
                  
                  if data.get("side") == "BUY":
                      print(f"Buy executed: {data['quantity']} {data['contract_type']} contracts at {data['price']} ticks")
                  else:
                      print(f"Sell executed: {data['quantity']} {data['contract_type']} contracts at {data['price']} ticks")

  asyncio.run(subscribe_user())
  ```
</CodeGroup>

## Unsubscribe

To unsubscribe from the user channel:

```json theme={null}
{
  "type": "unsubscribe",
  "channel": "user"
}
```

## Use Cases

* **Order Monitoring**: Receive instant notifications when your orders are executed;
* **Transaction Tracking**: Track all your transactions in real-time;
* **Portfolio Management**: Update your local portfolio as transactions occur;
* **Execution Alerts**: Implement alerts when specific orders are filled;
* **Performance Analysis**: Collect data about your transactions for later analysis.

## Best Practices

* **Security**: Never expose your API key in client code. Use environment variables or backend services to manage authentication;
* **Validation**: Always validate received messages before processing them;
* **Logging**: Log all received updates for auditing and debugging;
* **Error Handling**: Handle authentication errors properly and implement reconnection when necessary.
