This Azure Function is designed to automate Dollar-Cost Averaging (DCA) for Bitcoin purchases through the Kraken cryptocurrency exchange. It checks the current price of Bitcoin against a predefined threshold and places an order if the price is below this threshold.
The KrakenBitcoinDcaFunction is triggered by a timer and performs the following actions:
- Fetches the current Bitcoin price in a specified fiat currency (e.g., EUR) from Kraken's public API.
- Compares the fetched price against a predefined price threshold.
- If the current price is below the threshold, it places a market order to buy a specified amount of Bitcoin using Kraken's private API.
- Logs the outcome of the operation, including success or error messages.
To run this function locally, you will need to install Azurite and the Azure Functions Core Tools.
- Install Azurite, a lightweight Azure Storage emulator, by running:
npm install -g azurite
- Install the Azure Functions Core Tools to run and deploy your functions:
npm install -g azure-functions-core-tools@3 --unsafe-perm true
- Start Azurite with the following command:
azurite --silent --location . --debug azurite-debug.log
- Start the Azure Function locally using:
func start --verbose
Before running the function, rename local.settings.template.json
to local.settings.json
and configure the following settings:
TIMER_SCHEDULE
: Cron expression defining when the function triggers (e.g., "0 8 6 * * *" to run at 06:08 every day).KRAKEN_API_KEY
: Your Kraken API key for authentication.KRAKEN_PRIVATE_KEY
: Your Kraken private key for signing requests.BITCOIN_AMOUNT
: The amount of Bitcoin to purchase.PRICE_THRESHOLD
: The price threshold in your payment currency. Orders will only be placed if the current price is below this threshold.PAYMENT_CURRENCY
: The fiat currency used for the payment (e.g., EUR).
Instead of running the function locally, you can also deploy it to Azure to automate your Bitcoin purchases. Follow the Azure Functions deployment guide for instructions on deploying to Azure.