php command line script to DCA crypto from Coinbase Pro

Related tags

Command Line dca
Overview

dca.php

A simple php script designed to be run via the command line via a cron job.

This will connect to coinbase pro and buy the crypto coins specified in the config file and optionally transfer them to a crypto wallet or to a coinbase wallet.

This isa quick hacked together script that I did for myself, its not pretty but it works and does what I need it to do. I'm releasing it at the request of some people who want this functionality. If you want any changes just let me know and I will be happy to consider making them for you.

If you want to make a dontation please feel free to drop me some ALGO to AXXCIFO47GA5KUC7TMGWMH4T4SP2LVXEN6HU4KL7YJ7ILJLPH7QLI7BEGQ but don't feel obliged, I will just be happy if this helps you!

Installation Prerequisite

Tested on Ubuntu 20.04 using php version 7.4

Besides PHP you will also need to have composer installed.

Installation

You need to download the coinbase pro sdk from mocking-magician. The easiest way to do this is with composer as it will also install any required libraries.

git clone https://github.com/bensuffolk/dca
cd dca
composer update

Configuration

There are 2 files require for your configuration, the first dca.yaml contains the API authentication details for coinbase pro.

" secret: " " passphrase: " " ">
params:
  endpoint: "https://api.exchange.coinbase.com"
  key: "
     
      "
  secret: "
      
       "
  passphrase: "
       
        "

       
      
     

If you wish to use the transfer options to move your newly bought crypto to a wallet or to coinbase you will need to make sure the API details are on the Default Portfoilio.

To set up new API details go to https://pro.coinbase.com/profile/api and add a New API Key

You will then need to setup the config file dca.json to show which coins you wish to buy.

{
    "market": [
        "ALGO-GBP",
        "XTZ-GBP",
    ],
    "ALGO-GBP": {
        "buy-enabled": true,
        "buy-amount": 2,
        "transfer-to": "wallet",
        "transfer-address": "AXXCIFO47GA5KUC7TMGWMH4T4SP2LVXEN6HU4KL7YJ7ILJLPH7QLI7BEGQ",
        "transfer-max-fee": 0.002
    },
    "XTZ-GBP": {
        "buy-enabled": true,
        "buy-fund": 2.50,
        "transfer-to": "coinbase"
    }
}

The markets section is an array of all coin pairs you wish to buy. I have tested this with GBP, but I see no reason why it would not work with USD etc.

Then for every market pair you will need to section to define how much you wish to buy and what to do with it.

buy-enabled Must be set to true for any purchases to be made.

buy-fund Is how much you want to buy. You will need to specify either this or buy-amount.

buy-amount Is the number of coins you wish to buy. You will need to specify either this for buy-fund'. If buy-fund is specified then this option will be ignored.

transfer-to can either be wallet or coinbase. If you don't wish to transfer your purchased crypto anywhere then do not specify this option.

Note: this wil transfer all of the coin in the portfolio not just the amount recently purchased.

transfer-address Must be specified if trasfer-to is wallet. This is the crypto address to transfer your coin to. Make sure this is the right address for the specified coin. Once transfered there is no getting it back

`transfer-max-fee' Must be specified if trasfer-to is wallet. If the estimated transfer fee if greater than this amount, the trasnfer will not happen.

In the above example file you can see it will purached 2 ALGO and transfer them to a wallet, and £2.50 worth of XTZ and trasnfer it to a coinbase wallet.

Usage

php dca.php

Once run the latest buy will be recorded in the dca.json file, and it will not buy again within 18 hours of the last purchase.

Once you have tested it and are happy you may want to run this via cron

crontab -e

For instance to run it at 7am every day you would specify the following

0 7 * * * /usr/bin/php /home/ben/cbp/dca.php >> /home/ben/cbp/dca.log 2>&1
You might also like...
🍃 In short, it's like Tailwind CSS, but for the PHP command-line applications.
🍃 In short, it's like Tailwind CSS, but for the PHP command-line applications.

Termwind Termwind allows you to build unique and beautiful PHP command-line applications, using the Tailwind CSS API. In short, it's like Tailwind CSS

A PHP Command Line tool that makes it easy to compile, concat, and minify front-end Javascript and CSS/SCSS dependencies.

Front End Compiler A PHP Command Line tool that makes it easy to compile, concat, and minify front-end Javascript and CSS/SCSS dependencies. The minif

A PHP library for command-line argument processing

GetOpt.PHP GetOpt.PHP is a library for command-line argument processing. It supports PHP version 7.1 and above. Releases For an overview of the releas

BetterWPCLI - a small, zero-dependencies, PHP library that helps you build enterprise WordPress command-line applications.
BetterWPCLI - a small, zero-dependencies, PHP library that helps you build enterprise WordPress command-line applications.

BetterWPCLI - a small, zero-dependencies, PHP library that helps you build enterprise WordPress command-line applications.

Command-Line Interface tools

Aura.Cli Provides the equivalent of request ( Context ) and response ( Stdio ) objects for the command line interface, including Getopt support, and a

Another Command Line Argument Parser

Optparse — Another Command Line Argument Parser Install 1. Get composer. 2. Put this into your local composer.json: { "require": { "chh/optparse

👨🏻‍🚀 A command-line tool that gives you the Alpine Day 2021 schedule in your timezone. 🚀
👨🏻‍🚀 A command-line tool that gives you the Alpine Day 2021 schedule in your timezone. 🚀

Alpine Day Schedule a command-line tool that gives you the Alpine Day 2021 schedule in your timezone. 🚀 Quick start Requires PHP 7.4+ # First, instal

A command line code generator for Drupal.

Drupal Code Generator A command line code generator for Drupal. Installation Download the latest stable release of the code generator.

Laracon Schedule a command-line tool that gives you the Laracon Online schedule in your timezone.
Laracon Schedule a command-line tool that gives you the Laracon Online schedule in your timezone.

Laracon Schedule a command-line tool that gives you the Laracon Online schedule in your timezone. 🚀 Quick start Requires PHP 7.4+ # First, install: c

Comments
  • Can you show me how to do this?

    Can you show me how to do this?

    Hi, can you make a video of how to do this including importing the composer app from mocking magician and everything necessary to set this up. Also does this withdraw funds from coinbase pro if the transaction is pending since there is a 7 day hold on my funds from first purchase, does this obviate that or make it obsolete and send the funds anyway to another wallet (not coinbase)? Please let me know! I can reward you handsomely if you do so please write to [email protected] asap!! I can't wait to hear from you! Thanks

    opened by JohnM1975 0
Owner
Ben Suffolk
Ben Suffolk
PHP Interminal is a command-line tool that gives you access to PHP Internals discussions in your terminal.

PHP Interminal is a command-line tool that gives you access to PHP Internals discussions in your terminal. ??

Nuno Maduro 32 Dec 26, 2022
PHP CLI tool which allows publishing zipped MODX extra to modstore.pro marketplace

MODX Extra Publisher PHP CLI tool which allows publishing zipped MODX extra to modstore.pro marketplace. Installation global? local? To install packag

Ivan Klimchuk 3 Aug 6, 2021
Lovely PHP wrapper for using the command-line

ShellWrap What is it? It's a beautiful way to use powerful Linux/Unix tools in PHP. Easily and logically pipe commands together, capture errors as PHP

James Hall 745 Dec 30, 2022
A PHP library for command-line argument processing

GetOpt.PHP GetOpt.PHP is a library for command-line argument processing. It supports PHP version 5.4 and above. Releases For an overview of the releas

null 324 Dec 8, 2022
Patrol is an elegant command-line tool that keeps your PHP Project's dependencies in check.

Patrol is an elegant command-line tool that keeps your PHP Project's dependencies in check. Installation / Usage Requires PHP 8.0+ First, install Patr

Nuno Maduro 237 Nov 14, 2022
Twitter raffles in the command line, with PHP and minicli

Rafflebird Rafflebird is a highly experimental CLI application for giveaways / raffles on Twitter, built in PHP with Minicli. Disclaimer: The recent s

Erika Heidi 33 Nov 16, 2022
A PHP command line tool used to install shlink

Shlink installer A PHP command line tool used to install shlink. Installation Install this tool using composer.

null 8 Nov 3, 2022
Command-line control panel for Nginx Server to manage WordPress sites running on Nginx, PHP, MySQL, and Let's Encrypt

EasyEngine v4 EasyEngine makes it greatly easy to manage nginx, a fast web-server software that consumes little memory when handling increasing volume

EasyEngine 2k Jan 4, 2023
Generic PHP command line flags parse library

PHP Flag Generic PHP command line flags parse library Features Generic CLI options and arguments parser. Support set value data type(int,string,bool,a

PHP Toolkit 23 Nov 13, 2022
A simple command-line tool whose aim is to facilitate the continous delivery of PHP apps

Deployer Simple command-line tool that aims to facilitate the continous delivery of PHP apps, particularly Laravel apps. Imagine you want to update yo

Fernando Bevilacqua 4 Sep 8, 2021