{"id":18853478,"url":"https://github.com/kdmukai/gdax_bot","last_synced_at":"2025-04-14T10:23:58.415Z","repository":{"id":40901075,"uuid":"120547813","full_name":"kdmukai/gdax_bot","owner":"kdmukai","description":"gdax_bot - Micro dollar cost averaging for crypto","archived":false,"fork":false,"pushed_at":"2023-11-22T21:49:35.000Z","size":141,"stargazers_count":60,"open_issues_count":6,"forks_count":26,"subscribers_count":11,"default_branch":"master","last_synced_at":"2025-03-27T23:41:46.791Z","etag":null,"topics":["bch","bitcoin","bitcoincash","bot","btc","crypto","crypto-trader","cryptocurrency","dollar-cost-averaging","eth","ethereum","gdax","litecoin","ltc","trading","trading-bot","trading-strategies"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kdmukai.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-02-07T01:46:00.000Z","updated_at":"2024-11-23T07:44:45.000Z","dependencies_parsed_at":"2024-11-08T03:44:34.797Z","dependency_job_id":"86d01507-14e4-44d9-b8a0-f25d4f59d964","html_url":"https://github.com/kdmukai/gdax_bot","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kdmukai%2Fgdax_bot","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kdmukai%2Fgdax_bot/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kdmukai%2Fgdax_bot/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kdmukai%2Fgdax_bot/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kdmukai","download_url":"https://codeload.github.com/kdmukai/gdax_bot/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248860687,"owners_count":21173484,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bch","bitcoin","bitcoincash","bot","btc","crypto","crypto-trader","cryptocurrency","dollar-cost-averaging","eth","ethereum","gdax","litecoin","ltc","trading","trading-bot","trading-strategies"],"created_at":"2024-11-08T03:44:29.382Z","updated_at":"2025-04-14T10:23:58.392Z","avatar_url":"https://github.com/kdmukai.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# gdax_bot\nA basic Coinbase Pro buying bot that completes trades in any of their available market pairings\n\nRelies on [gdax-python](https://github.com/danpaquin/gdax-python). Props to [danpaquin](https://github.com/danpaquin) and thanks!\n\n## Trading Philosophy\n### Coinbase Pro overview\nCoinbase 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.\n\nBut 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.\n\n### Basic investing strategy: Dollar Cost Averaging\nYou 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.\n\nThis approach is common for retirement accounts; you invest a fixed amount into your 401(k) every month and trust that the market trend will be overall up over time.\n\n### Micro Dollar Cost Averaging for cryptos\nWhile 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.\n\nAnd 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.\n\n### How far can you push micro dollar cost averaging?\nCoinbase Pro sets different minimum order sizes for each crypto. \n\n[Current minimums](https://blog.Coinbase Pro.com/market-structure-update-2650072c6e3b) as of 2018-01-11 are:\n```\nBTC: 0.001\nETH: 0.01\nLTC: 0.1\nBCH: 0.01\nXLM: 1.0\n```\n\nThis combined with the current market price gives us the minimum fiat transaction amount.\n\nFor example, let's say BTC is at $8,000 USD. So the smallest possible buy order is ```$8,000*0.001 = $8.00```. So if you were looking to invest $100 each month, you could do ```floor($100/$8) = 12``` equal-sized buy orders; you couldn't do 13 equal-sized orders because ```$100/13 = $7.69``` which would only be 0.00096 BTC. An order that small would be rejected by the API. Spreading out your $100 over 12 buys during the month is pretty good dollar cost averaging.\n\nIt gets even more fun if you have more money to invest. Let's say you have $900 and the minimum fiat transaction amount is less than $10. You can split your funds into 90 equal parts--that's three equal buy orders per day: $10 every eight hours. At this point your total average cost basis for your crypto should be just about identical to its average cost for the month.\n\nI'm a big believer in this strategy for smoothing out crypto's short-term volatility while continuing to place your bets on its long-term value.\n\n### Adjust as prices change\nIf the crypto price keeps increasing, eventually your schedule will run up against the minimum purchase order size; you can't buy $13.9 of LTC if the price is greater than $139 (LTC's minimum order size is 0.1). In that case you'll have to increase how much you buy in each order, but decrease the frequency of the orders.\n\n\n## Technical Details\n### Basic approach\ngdax_bot pulls the current bid and ask prices, averages the two to set our order's price, then submits it as a limit order.\n\n### Making a valid limit order\nBuy 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.\n\n_*Longer pauses are probably advantageous--if the price is crashing, you don't want to be rushing in._\n\n### Setup\n#### Create a Coinbase account\nUse my referral code and we'll both get $10 worth of BTC:  \nhttps://www.coinbase.com/join/59384a753bfa9c00d764ac76\n\n#### Create a virtualenv\nThere's plenty of info elsewhere for the hows and whys.\n\n#### Install requirements\n```\npip install -r requirements.txt\n```\n\n#### Create Coinbase Pro API key\nTry 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.\n\nLog into your Coinbase/Coinbase Pro account in their test sandbox:\nhttps://public.sandbox.pro.coinbase.com/\n\nFind 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.\n\nWhile you're in the sandbox UI, fund your fiat account by transferring from the absurd fake balance that sits in the linked Coinbase account (remember, this is all just fake test data; no real money or crypto goes through the sandbox).\n\n\n#### (Optional) Create an AWS Simple Notification System topic\nThis is out of scope for this document, but generate a set of AWS access keys and a new SNS topic to enable the bot to send email reports.\n\n_TODO: Make this optional_\n\n\n#### Customize settings\nUpdate ```settings.conf``` with your API key info in the \"sandbox\" section. I recommend saving your version as ```settings-local.conf``` as that is already in the ```.gitignore``` so you don't have to worry about committing your sensitive info to your forked repo.\n\nIf you have an AWS SNS topic, enter the access keys and SNS topic.\n\n_TODO: Add support to read these values from environment vars_\n\n\n#### Try a basic test run\nRun against the Coinbase Pro sandbox by including the ```-sandbox``` flag. Remember that the sandbox is just test data. The sandbox only supports BTC trading.\n\nActivate your virtualenv and try a basic buy of $100 USD worth of BTC:\n```\npython gdax_bot.py BTC-USD BUY 100 USD -sandbox -c ../settings-local.conf\n```\n\nCheck 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.\n\n\n### Usage\nRun ```python gdax_bot.py -h``` for usage information:\n\n```\nusage: gdax_bot.py [-h] [-sandbox] [-warn_after WARN_AFTER] [-j]\n                   [-c CONFIG_FILE]\n                   market_name {BUY,SELL} amount amount_currency\n\n        This is a basic Coinbase Pro DCA buying/selling bot.\n\n        ex:\n            BTC-USD BUY 14 USD          (buy $14 worth of BTC)\n            BTC-USD BUY 0.00125 BTC     (buy 0.00125 BTC)\n            ETH-BTC SELL 0.00125 BTC    (sell 0.00125 BTC worth of ETH)\n            ETH-BTC SELL 0.1 ETH        (sell 0.1 ETH)\n    \n\npositional arguments:\n  market_name           (e.g. BTC-USD, ETH-BTC, etc)\n  {BUY,SELL}\n  amount                The quantity to buy or sell in the amount_currency\n  amount_currency       The currency the amount is denominated in\n\noptional arguments:\n  -h, --help            show this help message and exit\n  -sandbox              Run against sandbox, skips user confirmation prompt\n  -warn_after WARN_AFTER\n                        secs to wait before sending an alert that an order isn't done\n  -j, --job             Suppresses user confirmation prompt\n  -c CONFIG_FILE, --config CONFIG_FILE\n                        Override default config file location\n```\n\n\n### Scheduling your recurring buys\nThis is meant to be run as a crontab to make regular purchases on a set schedule. Here are some example cron jobs:\n\n$50 USD of ETH every Monday at 17:23:\n```\n23 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 \u003e\u003e /your/cron/log/path/cron.log\n```\n*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```.*\n\n€75 EUR of BTC every other day at 14:00:\n```\n00 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 \u003e\u003e /your/cron/log/path/cron.log\n```\n\n£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):\n```\n38 */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 \u003e\u003e /your/cron/log/path/cron.log\n```\n\n\n### Unfilled orders will happen\nThe 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:\n![alt text](https://github.com/kdmukai/gdax_bot/blob/master/docs/img/gdax_unfilled_orders.png \"Unfilled gdax_bot orders\")\n\nThe gdax_bot will keep checking on the status of the order for up to an hour, after which it will report it as OPEN/UNFILLED. Hopefully the market will cool down again and return to your order's price, at which point it will fill (though gdax_bot will not send a notification). You can also manually cancel the order to free up the reserved fiat again. \n\nI would recommend patience and let the unfilled order ride for a few hours or days. With micro dollar cost averaging it doesn't really matter if you miss a few buy orders.\n\n\n#### Mac notes\nEdit the crontab:\n```\nenv EDITOR=nano crontab -e\n```\n\nView the current crontab:\n```\ncrontab -l\n```\n\n#### Raspberry Pi notes\nDownload 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.\n\nRemove and re-insert the SD card into the computer.\n\nEnable ssh:\n```\ntouch /Volumes/boot/ssh\n```\n\nPreload wifi credentials. Begin editing a new file called:\n```\nnano /Volumes/boot/wpa_supplicant.conf\n```\n\nand customize for your network:\n```\ncountry=US\nctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev\nupdate_config=1\nnetwork={\n   ssid=\"your wifi network name\"\n   psk=\"your wifi password\"\n   key_mgmt=WPA-PSK\n}\n```\n\nInsert the SD card into the Raspberry Pi and power up. After about a minute try to ssh into it:\n```\nssh pi@raspberrypi.local\n\n# default password is: raspberry\n```\n\nOnce you're in change the default password:\n```\npasswd\n```\n\nPermanently enable ssh access (seems to revert to closing it off otherwise):\n```\nsudo systemctl enable ssh\n```\n\nInstall automatic updates:\n```\nsudo apt-get install unattended-upgrades apt-listchanges\n```\n\n\n## Disclaimer\n_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._\n\n\n# Tips\nIf you found this useful, send me some digital love\n- ETH: 0xb581603e2C4eb9a9Ece4476685f0600CeB472241\n- BTC: 13u1YbpSzNsvVpPMyzaDAfzP2jRcZUwh96\n- LTC: LMtPGHCQ3as6AEC9ueX4tVQw7GvHegv3fA\n- DASH: XhCnytvKkV44Mn5WeajGfaifgY8vGtamW4\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkdmukai%2Fgdax_bot","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkdmukai%2Fgdax_bot","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkdmukai%2Fgdax_bot/lists"}