Skip to content

Commit 71c1208

Browse files
committed
Refactored to support SELL; breaking changes to input args
1 parent 6607621 commit 71c1208

File tree

4 files changed

+238
-143
lines changed

4 files changed

+238
-143
lines changed

README.md

Lines changed: 89 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
# gdax_bot
2-
A basic GDAX buying bot that completes trades from fiat (government-backed currency: USD, EUR, GBP) to a target crypto asset (BTC, ETH, LTC, BCH).
2+
A basic Coinbase Pro buying bot that completes trades in any of their available market pairings
33

44
Relies on [gdax-python](https://github.com/danpaquin/gdax-python). Props to [danpaquin](https://github.com/danpaquin) and thanks!
55

66
## Trading Philosophy
7-
### GDAX overview; Trading with no fees
8-
GDAX is the more professional cryptocurrency exchange that underlies Coinbase. If you have a Coinbase account, you have a GDAX account ([create a Coinbase account](https://www.coinbase.com/join/59384a753bfa9c00d764ac76)). All trades on Coinbase include a commission fee. But some trades on GDAX are free--specifically if you set your buy or sell price as a limit order. You are the "maker" of an offer and you await a "taker" to accept. The "takers" pay the fees, the "maker" pays none. The tradeoff is that limit orders may or may not be fulfilled; if you're selling X crypto at $Y value and no one likes your price, your sell order won't go anywhere.
7+
### Coinbase Pro overview
8+
Coinbase Pro is the more professional cryptocurrency exchange that underlies Coinbase. If you have a Coinbase account, you have a Coinbase Pro account ([create a Coinbase account](https://www.coinbase.com/join/59384a753bfa9c00d764ac76)). All trades on Coinbase include expensive tiered flat fees ($0.99+/tx) or 1.49%, plus a 0.5% spread on the market price (or up to 2% spread on crypto-to-crypto trades). Ouch.
9+
10+
But some trades on Coinbase Pro can be made at a greatly reduced rate (0.5%) or even free, depending on your transaction tier over the last 30 days. You just have to submit your buy or sell as a limit order. You are the "maker" of an offer and you await a "taker" to accept. The "takers" pay the fees, the "maker" pays a reduced fee (depending on your transaction tier). The tradeoff is that limit orders may or may not be fulfilled; if you're selling X crypto at $Y value and no one likes your price, your sell order won't go anywhere.
911

1012
### Basic investing strategy: Dollar Cost Averaging
1113
You have to be extremely lucky or extremely good to time the market perfectly. Rather than trying to achieve the perfect timing for when to execute a purchase just set up your investment on a regular schedule. Buy X amount every Y days. Sometimes the market will be up, sometimes down. But over time your cache will more closely reflect the average market price with volatile peaks and valleys averaged out.
@@ -15,12 +17,12 @@ This approach is common for retirement accounts; you invest a fixed amount into
1517
### Micro Dollar Cost Averaging for cryptos
1618
While I believe strongly in dollar cost averaging, the crypto world is so volatile that making a single, regular buy once a month is still leaving too much to chance. The market can swing 30%, 50%, even 100%+ in a single day. I'd rather invest $20 every day for a month than agonize over deciding on just the right time to do a single $600 buy.
1719

18-
And because we can do buy orders on GDAX with no fees (so long as they're submitted as limit orders), there's no penalty for splitting an order down to smaller intervals.
20+
And because we can do buy orders on Coinbase Pro with no fees (so long as they're submitted as limit orders), there's no penalty for splitting an order down to smaller intervals.
1921

2022
### How far can you push micro dollar cost averaging?
21-
GDAX sets different minimum order sizes for each crypto.
23+
Coinbase Pro sets different minimum order sizes for each crypto.
2224

23-
[Current minimums](https://blog.gdax.com/market-structure-update-2650072c6e3b) as of 2018-01-11 are:
25+
[Current minimums](https://blog.Coinbase Pro.com/market-structure-update-2650072c6e3b) as of 2018-01-11 are:
2426
```
2527
BTC: 0.001
2628
ETH: 0.01
@@ -43,10 +45,10 @@ If the crypto price keeps increasing, eventually your schedule will run up again
4345

4446
## Technical Details
4547
### Basic approach
46-
gdax_bot pulls the current market price, subtracts a small spread to generate a valid buy price, then submits the buy as a limit order.
48+
gdax_bot pulls the current bid and ask prices, averages the two to set our order's price, then submits it as a limit order.
4749

48-
### Making a valid limit buy
49-
Buy orders will be rejected if they are at or above the lowest sell order (think: too far right on the order book) (see: https://stackoverflow.com/a/47447663). When the price is plummeting this is likely to happen. In this case gdax_bot will pause for a minute and then grab the latest price and re-place the order. It will currently attempt this 100 times before it gives up.
50+
### Making a valid limit order
51+
Buy orders will be rejected if they are at or above the lowest sell order (think: too far right on the order book) (see: https://stackoverflow.com/a/47447663) and vice-versa for sells. When the price is plummeting this is likely to happen. In this case gdax_bot will pause for a minute and then grab the latest price and re-place the order. It will currently attempt this 100 times before it gives up.
5052

5153
_*Longer pauses are probably advantageous--if the price is crashing, you don't want to be rushing in._
5254

@@ -63,11 +65,11 @@ There's plenty of info elsewhere for the hows and whys.
6365
pip install -r requirements.txt
6466
```
6567

66-
#### Create GDAX API key
67-
Try this out on GDAX's sandbox first. The sandbox is a test environment that is not connected to your actual fiat or crypto balances.
68+
#### Create Coinbase Pro API key
69+
Try this out on Coinbase Pro's sandbox first. The sandbox is a test environment that is not connected to your actual fiat or crypto balances.
6870

69-
Log into your Coinbase/GDAX account in their test sandbox:
70-
https://public.sandbox.gdax.com
71+
Log into your Coinbase/Coinbase Pro account in their test sandbox:
72+
https://public.sandbox.pro.coinbase.com/
7173

7274
Find and follow existing guides for creating an API key. Only grant the "Trade" permission. Note the passphrase, the new API key, and API key's secret.
7375

@@ -89,11 +91,11 @@ _TODO: Add support to read these values from environment vars_
8991

9092

9193
#### Try a basic test run
92-
Run against the GDAX sandbox by including the ```-sandbox``` flag. Remember that the sandbox is just test data. The sandbox only supports BTC trading.
94+
Run against the Coinbase Pro sandbox by including the ```-sandbox``` flag. Remember that the sandbox is just test data. The sandbox only supports BTC trading.
9395

94-
Activate your virtualenv and try a basic $100 USD BTC buy:
96+
Activate your virtualenv and try a basic buy of $100 USD worth of BTC:
9597
```
96-
python gdax_bot.py -crypto BTC -fiat_amount 100.00 -sandbox -c ../settings-local.conf
98+
python gdax_bot.py BTC-USD BUY 100 USD -sandbox -c ../settings-local.conf
9799
```
98100

99101
Check the sandbox UI and you'll see your limit order listed. Unfortunately your order probably won't fill unless there's other activity in the sandbox.
@@ -103,24 +105,30 @@ Check the sandbox UI and you'll see your limit order listed. Unfortunately your
103105
Run ```python gdax_bot.py -h``` for usage information:
104106

105107
```
106-
usage: gdax_bot.py [-h] [-crypto CRYPTO] [-fiat FIAT_TYPE] -fiat_amount
107-
FIAT_AMOUNT [-price_spread PRICE_SPREAD] [-sandbox]
108-
[-warn_after WARN_AFTER] [-j] [-c CONFIG_FILE]
108+
usage: gdax_bot.py [-h] [-sandbox] [-warn_after WARN_AFTER] [-j]
109+
[-c CONFIG_FILE]
110+
market_name {BUY,SELL} amount amount_currency
111+
112+
This is a basic Coinbase Pro DCA buying/selling bot.
109113
110-
This is a basic GDAX zero-fee buying bot
114+
ex:
115+
BTC-USD BUY 14 USD (buy $14 worth of BTC)
116+
BTC-USD BUY 0.00125 BTC (buy 0.00125 BTC)
117+
ETH-BTC SELL 0.00125 BTC (sell 0.00125 BTC worth of ETH)
118+
ETH-BTC SELL 0.1 ETH (sell 0.1 ETH)
119+
120+
121+
positional arguments:
122+
market_name (e.g. BTC-USD, ETH-BTC, etc)
123+
{BUY,SELL}
124+
amount The quantity to buy or sell in the amount_currency
125+
amount_currency The currency the amount is denominated in
111126
112127
optional arguments:
113128
-h, --help show this help message and exit
114-
-crypto CRYPTO Target cryptocurrency
115-
-fiat FIAT_TYPE Fiat currency type to fund buy order (e.g. USD)
116-
-fiat_amount FIAT_AMOUNT
117-
Buy order size in fiat
118-
-price_spread PRICE_SPREAD
119-
Amount below current market rate to set buy price
120-
-sandbox Run against GDAX sandbox
129+
-sandbox Run against sandbox, skips user confirmation prompt
121130
-warn_after WARN_AFTER
122-
Seconds to wait before sending an alert that an order
123-
isn't done
131+
secs to wait before sending an alert that an order isn't done
124132
-j, --job Suppresses user confirmation prompt
125133
-c CONFIG_FILE, --config CONFIG_FILE
126134
Override default config file location
@@ -132,22 +140,20 @@ This is meant to be run as a crontab to make regular purchases on a set schedule
132140

133141
$50 USD of ETH every Monday at 17:23:
134142
```
135-
23 17 * * 1 /your/virtualenv/path/bin/python -u /your/gdax_bot/path/src/gdax_bot.py -j -crypto ETH -fiat_amount 50.00 -c /your/settings/path/your_settings_file.conf >> /your/cron/log/path/cron.log
143+
23 17 * * 1 /your/virtualenv/path/bin/python -u /your/gdax_bot/path/src/gdax_bot.py -j ETH-USD BUY 50.00 USD -c /your/settings/path/your_settings_file.conf >> /your/cron/log/path/cron.log
136144
```
137145
*The ```-u``` option makes python output ```stdout``` and ```stderr``` unbuffered so that you can watch the progress in real time by running ```tail -f cron.log```.*
138146

139147
€75 EUR of BTC every other day at 14:00:
140148
```
141-
00 14 */2 * * /your/virtualenv/path/bin/python -u /your/gdax_bot/path/src/gdax_bot.py -j -crypto BTC -fiat EUR -fiat_amount 75.00 -c /your/settings/path/your_settings_file.conf >> /your/cron/log/path/cron.log
149+
00 14 */2 * * /your/virtualenv/path/bin/python -u /your/gdax_bot/path/src/gdax_bot.py -j BTC-EUR BUY 75.00 EUR -c /your/settings/path/your_settings_file.conf >> /your/cron/log/path/cron.log
142150
```
143151

144152
£5 GBP of LTC every day on every third hour at the 38th minute (i.e. 00:38, 03:38, 06:38, 09:38, 12:38, 15:38, 18:38, 21:38):
145153
```
146-
38 */3 * * * /your/virtualenv/path/bin/python -u /your/gdax_bot/path/src/gdax_bot.py -j -crypto LTC -fiat GBP -fiat_amount 5.00 -c /your/settings/path/your_settings_file.conf >> /your/cron/log/path/cron.log
154+
38 */3 * * * /your/virtualenv/path/bin/python -u /your/gdax_bot/path/src/gdax_bot.py -j LTC-GBP BUY 5.00 GBP -c /your/settings/path/your_settings_file.conf >> /your/cron/log/path/cron.log
147155
```
148156

149-
Your Coinbase/GDAX account must obviously have enough USD in it to cover the buy order/series of buy orders.
150-
151157

152158
### Unfilled orders will happen
153159
The volatility may quickly carry the market away from you. Here we see a bunch of unfilled orders that are well below the current market price of $887.86:
@@ -169,6 +175,55 @@ View the current crontab:
169175
crontab -l
170176
```
171177

178+
#### Raspberry Pi notes
179+
Download and flash Raspbian to an SD card using Balena Etcher. You can use a "headless" version (Raspbian Lite) with no monitor, no keyboard, no mouse with the following steps.
180+
181+
Remove and re-insert the SD card into the computer.
182+
183+
Enable ssh:
184+
```
185+
touch /Volumes/boot/ssh
186+
```
187+
188+
Preload wifi credentials. Begin editing a new file called:
189+
```
190+
nano /Volumes/boot/wpa_supplicant.conf
191+
```
192+
193+
and customize for your network:
194+
```
195+
country=US
196+
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
197+
update_config=1
198+
network={
199+
ssid="your wifi network name"
200+
psk="your wifi password"
201+
key_mgmt=WPA-PSK
202+
}
203+
```
204+
205+
Insert the SD card into the Raspberry Pi and power up. After about a minute try to ssh into it:
206+
```
207+
208+
209+
# default password is: raspberry
210+
```
211+
212+
Once you're in change the default password:
213+
```
214+
passwd
215+
```
216+
217+
Permanently enable ssh access (seems to revert to closing it off otherwise):
218+
```
219+
sudo systemctl enable ssh
220+
```
221+
222+
Install automatic updates:
223+
```
224+
sudo apt-get install unattended-upgrades apt-listchanges
225+
```
226+
172227

173228
## Disclaimer
174229
_I built this to execute my own micro dollar cost-averaging crypto buys. Use and modify it at your own risk. This is also not investment advice. I am not an investment advisor. You should do your own research and invest in the way that best suits your needs and risk profile. Good luck and HODL strong._

0 commit comments

Comments
 (0)