Skip to main content

Synchronizing balances

Goal: Automate the daily synchronization of current xRocket account balances into a separate database or accounting system.

Key xRocket API Features Used:

  • Private Wallet Endpoint: GET /api/v1/accounts/funding/balances
  • Authentication: Bearer Token
danger

Your Bearer Token grants full access to your account. Never hard-code it in source files or commit it to version control. Use environment variables or a secrets manager to store it securely.

Workflow:

  1. Scheduled Task: A cron job or scheduled script runs daily at a specific time (e.g., midnight UTC).
  2. Authentication: The script uses the secure Bearer Token to authenticate with the xRocket API.
  3. API Call: It sends a GET request to the /api/v1/accounts/funding/balances endpoint.
  4. Data Processing: The script receives the JSON response containing the available and locked balance for all assets.
  5. Synchronization: It parses the data and updates the corresponding entries in the external accounting database.
  6. Reporting: Generates a summary log file confirming that all balances were successfully synchronized.
tip

For near-real-time balance tracking, consider subscribing to the balances WebSocket channel instead of polling with a cron job. This gives you instant updates whenever a balance changes.