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:
- Scheduled Task: A cron job or scheduled script runs daily at a specific time (e.g., midnight UTC).
- Authentication: The script uses the secure Bearer Token to authenticate with the xRocket API.
- API Call: It sends a
GETrequest to the/api/v1/accounts/funding/balancesendpoint. - Data Processing: The script receives the JSON response containing the available and locked balance for all assets.
- Synchronization: It parses the data and updates the corresponding entries in the external accounting database.
- 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.