Engineering July 6, 2021 2 min read

Coinbase transactions with Python and Pandas

Coinbase transactions with Python and Pandas

Coinbase provides an API to interact with the platform, check the documentation at https://developers.coinbase.com/api/v2. Even though the available options go from transactions to purchases, here we’ll only be looking into transactions.

The main goal is to retrieve all the available transactions from every available wallet, and convert that information into a Pandas DataFrame. This will ease the data accessibility and manipulation for future analysis.

Create an API Key

API Key is meant for personal use. For building applications for Coinbase users you should use OAuth2.

If you haven’t yet created an API Key, log in to your Coinbase account and navigate to settings to find the API tab.

Since we’re only focusing on the transactions, only the wallet:accounts:read and wallet:transactions:read are necessary. Once the new API Key has been created, save the newly generated API KEY and API SECRET in a file.

Authentication

Coinbase API authentication will be performed by taking advantage of the AuthBase class available in the requests Python package.

[Code snippet — Medium embed: code snippet]

When attaching the authentication handler to a request, the __call__ method performs automatically what it has been configured to do during the request setup.

Coinbase Transactions

Transactions are related to an account, which means that to retrieve all transactions from a cryptocurrency, we need to access that cryptocurrency account.

Another important point is that when querying Coinbase accounts, it lists all available accounts in the platform even if they were never used. Since the parameters id and balance.currency are equal for the unused accounts, we’ll use them to filter out the information we are looking for.

[Code snippet — Medium embed: code snippet]

If this is not exactly what your looking for, you can always try one of the available libraries at https://developers.coinbase.com/docs/wallet/client-libraries. But be cautious, these have not been security tested by Coinbase, nor are they official.

At Runtime Revolution, we take our craft seriously and always go the extra mile to deliver a reliable, maintainable, and testable product. Do you have a project to move forward or a product you’d like to launch? We would love to help you!