This script allows you to automatically purchase or sell cryptocurrencies on Coinbase using market or limit orders. The script can be scheduled to run at regular intervals using a cronjob.
- A Coinbase account with API access enabled
- Node.js and npm installed on your Ubuntu machine
- Your Coinbase API key and secret
-
Clone the Repository
Clone this repository to your local machine:
git clone https://github.com/BriungRi/coinbase-recurring-buys.git cd coinbase-recurring-buys -
Install Dependencies
Install the required npm packages:
pnpm install
-
Configure API Credentials
Copy the
.env.examplefile to.envand fill in your Coinbase API credentials:API_KEY= API_SECRET=
-
Test the Script
Run the script manually to ensure it works:
For a market order (e.g., buy $1 of BTC-USD):
pnpm start market --amount 1 --product BTC-USD --side BUY
For a limit order (e.g., buy $1 of BTC-USD 1% below the best bid):
pnpm start limit --amount 1 --product BTC-USD --side BUY --percent 1
To test in the sandbox environment, add the
--dryflag:pnpm start market --amount 1 --product BTC-USD --side BUY --dry
-
Open the Crontab Editor
Open the crontab editor:
crontab -e
-
Schedule the Script
Add the following line to schedule the script to run every day at 2 AM:
0 2 * * * cd /path/to/your/repo && pnpm start market --amount 1 --product BTC-USD --side BUY
Replace
/path/to/your/repowith the actual path to your repository. You can get this by runningpwdin your repository directory.We recommend using crontab.guru to check and generate cron schedules.
-
Save and Exit
Save the file and exit the editor. The cronjob is now set up to run the script at the specified time.
-
Check Previous Runs
To check the status of previous runs, view the cron logs:
grep CRON /var/log/syslog
You can also check your Coinbase account history to verify successful transactions.
- Ensure your account has sufficient funds to cover the purchases
- Consider setting up recurring USDC buys as they typically don't incur fees
- Monitor your Coinbase account regularly to verify successful transactions