A basic Coinbase Pro buying bot that completes market trades in any of their available market pairings.
Relies on gdax-python. Thank you danpaquin
Forked from gdax_bot. Thank you kdmukai
Say hi on twitter: @brennerspear
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.
Log into your Coinbase/Coinbase Pro account in their test sandbox: https://public.sandbox.pro.coinbase.com/
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. Write these down.
While 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).
- click "Create Function"
- enter a function name
- Runtime: Python 3.8
- click "Create Function"
- click "Upload from" --> .zip file
- upload the zip in this repo:
my-lambda-deployment-package.zip
- Click "Configuration"
- Click "Environment variables"
- Click "edit" on the right
- add the following 7 key-value pairs you got from Coinbase Pro earlier:
ENV = SANDBOX
CBPRO_PASSPHRASE_SANDBOX = xxx
CBPRO_API_KEY_SANDBOX = xxx
CBPRO_SECRET_KEY_SANDBOX = xxx
CBPRO_PASSPHRASE = xxx
CBPRO_API_KEY = xxx
CBPRO_SECRET_KEY = xxx
click save
(We're setting the environment as SANDBOX
for now so we can do a test run first)
We also need to change the timeout of the lambda function
Within "Configuration", go to:
- Click "General Configuration"
- Click "edit" on the right
- Edit timeout to 0 min 10 sec
- Click "Save"
Click "Test" Add an example event with the following JSON data (The sandbox only has BTC-USD)
{
"market_name": "BTC-USD",
"order_side": "BUY",
"amount": "10",
"amount_currency": "USD"
}
Click "Test"
It should give a successful run, and show the output in the dropdown
Go back to Configuration --> Environment variables --> edit
Change ENV
to PRODUCTION
Save and go back to test. Run another test. This time it will actually be buying btc from your real account!
- Search in the top search bar for "EventBridge" where you'll create a rule
- name your rule (I named one of mine "buy-eth-every-hour)
- select "Schedule"
- Fixed rate every x minutes/hours/days
- Target: Lambda function
- Function: your function's name
- Configure input
- select "Constant (JSON text)"
- copy and paste the JSON data that fits what you want to buy. Example:
{
"market_name": "SOL-USD",
"order_side": "BUY",
"amount": "10",
"amount_currency": "USD"
}
Click "Add target"
Click "Create"
Congratulations! Your bot is running!
You can create multiple rules if you want to buy multiple different assets.
Use and modify it at your own risk. This is not investment advice. I am not an investment advisor.
The requirments.txt file probably doesn't match exactly what's in the .zip.
lambda_function.py
might have some imports it doesn't need.
You could get rid of the loops and sleeper since you don't actually need a response to execute the trade, but then you won't have any logs.
If you're going to edit the code and upload, this tutorial was helpful. Zipping the dependency files + lambda_function.py
together can be a bit finicky.
TODO:
The environment variables should probably be encrypted in transit. The code needed to decrypt them when they arrive needs to be added.