In 2022, Coinbase, the largest US cryptocurrency exchange, announced that they would be sunsetting Coinbase Pro and transitioning users to their new platform, Coinbase Advanced Trader.
This change integrated the features of Coinbase Pro (formerly GDAX) natively into Coinbase.
In this blog post, I will share a Python script that automates deposits into and withdrawals out of your Coinbase account, which should help users who need to adapt to the new API structure.
The layer below will allow you to run all the deposit and withdrawal code in AWS (specifically we need the requests module), if you want to generate you own layer follow these instructions.
The first Python script below demonstrates how to make deposits into your Coinbase account.
This next Python script demonstrates how to make withdrawals from your Coinbase account
Finally, to make a connection with Coinbase and to customize your scripts you can use this config file
Setting Up Your API Connection
Replace the placeholder values for API_KEY, API_SECRET, ACCOUNT_ID, and PAYMENT_METHOD with your Coinbase API keys and account information.
You can generate API keys by going to Coinbase.com -> Profile Picture -> Settings -> API -> New API Key.
Running the Deposit Script
You'll need to run the script once, calling the list_payment_methods() function.
This should return 'id' fields that you can use to populate DEPOSIT_ID (you need the 'id' from the 'Cash (USD)' account) and PAYMENT_METHOD (in my case I used my Charles Schwab account, you would use whatever your prefered linked bank account is).
These fields can be populated in your config.json file.
Running the Withdrawal Script
Like the deposit script you'll need to run the withdrawal script once this time calling the list_accounts() function so you can populate WITHDRAWAL_ID (the internal Coinbase ID for the wallet you want to withdrawal from - this NEEDS to match the currency of the wallet you're trying to withdraw to or you could lose your funds - don't withdraw ETH to a BTC wallet address).
WITHDRAWAL_ID can also be updated in config.json.
What's Next + Thanks
I received the base for this deposits code from a viewer of the YouTube channel, "TS", who wanted to remain anonymous.
Thanks to Matt Negules from Coinbase for helping me find the correct documentation and for working on updates to make developer lives easier follow him on Twitter here
Hopefuly this solution was helpful to everyone migrating over from Coinbase Pro.
Feel free to modify and expand the script according to your needs, and if you encounter any issues or have questions, please don't hesitate to reach out at email@example.com or over on Twitter @rhettre - my DMs are open.