This package will no longer work due to CoinbasePro migrating to their new API. As of early 2023 use something like this: https://www.npmjs.com/package/coinbase-advanced-node
This is a NodeJS server I built that is set to automatically purchase $5 worth of bitcoin every N hours, indefinitely. It uses the Coinbase Pro NodeJS API. You can change how much to buy, how often to buy, and how much to re fund your account when it runs low. Once your funds run low the app will use your first instant buy funding source to deposit more funds into your account so that it can cover the purchase. Please note that minimum amount per buy is $5, and the minimum deposit amount is $10
-
login to your coinbase pro account on your desktop and create an api key (settings > api > new key). Just select all 3 of the permissions. Make sure to whitelist your ipV4 IP address of your computer save the passphrase and key that it gives you, you will need them later
-
clone this project on your computer
-
create a .env file in the root directory of this project and put the below in there:
SECRET=your_coinbasePro_api_secret
KEY=your_coinbasePro_api_key
PASSPHRASE=your_coinbasePro_api_passphrase
BUY_FREQUENCY_HOURS=2
DOLLAR_AMOUNT_TO_BUY_PER_PURCHASE=5 <---minimum is $5
DEPOSIT_AMOUNT=50 <---minimum is $10
PRODUCT_ID=BTC-USD <--- buys bitcoin using USD
- open a terminal on your computer, navigate to the directory, and run the following commands:
npm i
npm run start
if you want to stop the DCA process, just close the server: (Ctrl + C).
When you're ready to start it again, run npm run start
again.
ps. I added a new function that lets you calcualte total dollars spent and total bitcoin purchased since a given date. I like to use it every few weeks so I can keep up with my cost basis. By default this function is commented out, if you want to run it just comment out the startDCAProcess function and uncomment the calculatePurchasesSince function.