Created
January 24, 2025 14:01
-
-
Save devbyray/61d7ea96c1a67938814299031837b717 to your computer and use it in GitHub Desktop.
Bitvavo get balance via REST API
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const crypto = require('crypto'); | |
const fetch = require('node-fetch') | |
// Replace with your actual API key and secret | |
const API_KEY = 'YOUR_KEY'; | |
const API_SECRET = 'YOUR_SECRET'; | |
// Define the endpoint and method | |
const endpoint = 'https://api.bitvavo.com/v2/balance'; | |
const method = 'GET'; | |
// Generate the current timestamp in milliseconds | |
const timestamp = Date.now(); | |
// Define the window in milliseconds | |
const accessWindow = 30000; | |
// Construct the signature payload | |
const signaturePayload = timestamp + method + '/v2/balance'; | |
// Create the HMAC SHA256 signature | |
const signature = crypto | |
.createHmac('sha256', API_SECRET) | |
.update(signaturePayload) | |
.digest('hex'); | |
// Create the headers | |
const headers = { | |
'bitvavo-access-key': API_KEY, | |
'bitvavo-access-timestamp': timestamp, | |
'bitvavo-access-signature': signature, | |
'bitvavo-access-window': accessWindow.toString(), | |
'accept': 'application/json', | |
}; | |
async function callBitvavo() { | |
const response = await fetch(endpoint, { | |
method: method, | |
headers: headers, | |
}); | |
if (!response.ok) { | |
throw new Error( | |
`HTTP Error ${response.status}: ${await response.text()}` | |
); | |
} | |
const data = await response.json(); | |
return data | |
} | |
const data = await callBitvavo() | |
// Make the request using fetch | |
return { data } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment