Making a simple Raspberry Pi Bitcoin/Ethereum trading bot

I recently got my Raspberry Pi Zero Wifi and I tell you this thing is a game changer. I have used RasPis before but since this device has a much smaller footprint, uses less energy, is cheaper and has wifi on board, it’s perfect for low profile or IoT projects.

The idea is simple: The Raspberry Pi Zero uses the Coinbase API to check the prices periodically and buys and sells Bitcoin, whenever it makes sense. You should be able to give it a budget and see what it can do with it.

  • I want you to buy 50€ worth of Bitcoin and sell when the 50€ became 52€
  • I want you to buy 100€ worth of Bitcoin when the Bitcoin price hits 1000€/BTC and sell when the 100€ are worth 150€
  • Buy low, sell high
  • Automatically buy bitcoin after the next bubble pops

For control reasons I want to be informed whenever BTC/ETH were sold or bought. For this I use a simple webhook for my favorite (and selfhosted) chat platform rocket.chat. But it also works with a webhook from Slack!

  1. A Raspberry Pi or just Linux box
  2. A Coinbase account with some funds in the EUR/USD Wallet
  3. PHP 5 or higher
  4. PHP Composer to install the libraries
  5. If you want reporting you’ll need a rocket.chat or Slack webhook
  1. Download the repo by using the command git clone https://github.com/chrisiaut/phptrader.git or download as ZIP file
  2. Go into the php trader directory cd phptrader
  3. Install the required composer files composer install
  4. Rename example.config.inc.php to config.inc.php
  1. Go to https://www.coinbase.com/settings/api
  2. Click on «+ New API Key»
  3. You will then see the API key creation dialogue. Choose the Bitcoin/Ethereum and EUR/USD Wallet
  4. Select all permissions
  5. Confirm
  6. When you see the API key and secret, enter them in the config.inc.php file of the PHPTrader bot under COINBASE_KEY and COINBASE_SECRET.
  1. On your chat instance go to Administration -> Integrations
  2. Click on «New Integration», then «Incoming WebHook»
  3. Set it to enabled, choose a post channel or user
  4. Click «Save Changes»
  5. You will see now a «Webhook URL», copy it and put it in the ROCKETCHAT_WEBHOOK field in config.inc.php

Using the following commands, the bot will create a transacitons.json file where the amount in EUR, BTC, start price and sell price will be saved so we can track them over restarts.

  • php trader.php buy [amount in EUR] [sell when price increases by EUR]
  • php trader.php sell [amount in EUR] [sell when this BTC/ETH price is reached]
  • php trader.php order [amount in EUR] [sell when price increases by EUR] [buy at BTC/ETH price]
  • Buy 10 EUR in BTC/ETH and sell when they’re worth 12 EUR: php trader.php buy 10 2

  • Add sell order. Sell 100 EUR/USD when BTC/ETH price reaches 2000: php trader.php sell 100 2000

  • Add buy order for 100 EUR when 1 BTC/ETH is worth 1000 EUR and sell when the 100 EUR are worth 110 EUR: php trader.php order 100 10 1000

After setup you can start the watchdog: The heart of the bot is an infinite loop that checks periodically (every 10 seconds) for price changes. You can start it yourself by using the command php trader.php watchdog or use the start.sh script which will put the process in background and log to /var/log/phptrader.log

There are no ads on this (https enforced) blog. Please help me to keep it that way
1ChrisHMgr4DvEVXzAv1vamkviZNLPS7yx
0x1337C2F18e54d72d696005d030B8eF168a4C0d95