I’d been wanting to have a simple CLI to hit the coinbase v2_api and v3_api so that I could use it in CRON. I got it working this week and thought I’d share since it served as a useful way to debug the API. Years ago I had postman
but in my region they are transitioning to membership based accounts, and I wasn’t comfortable syncing API keys to their backend.
So this is all pure-python (3.8) and uses the two published python libraries, coinbase-python
and coinbase-advanced-py
, which connect to the v2 and v3 APIs respectively. The V2 library also has an OAuth2 client that will actually work great on V3 URIs. It’s mainly what I use honestly.
I also was able to make an OAuth2 registration callback server in python, so there is no need to host a callback server for tokens eaither, or rely on a service. It’s all done locally, with no real “magic” code.
pyexch
EARLY PREVIEW RELEASE of a rudimentary python CLI based rest client for Coinbase
usage: pyexch [-h] [--method <get,post,>] [--url https://...]
[--params params.json] [--call get_accounts]
[--keystore ks.json] [--auth exch.auth]
Python Exchange CLI (pyexch)
optional arguments:
-h, --help show this help message and exit
--method <get,post,> rest http method (get<default>,post,put,delete)
--url https://... rest http url to perform actions upon
--params params.json json(5) filename holding rest parameters / data
--call get_accounts call method in the default client
--keystore ks.json json(5) filename where secrets are stored (backup!)
--auth exch.auth the auth method to use from keystore.
NOTE: Must name either "--call" or "--url", but not both, and "keystore.json"
is assumed if "--keystore" is not named
Future Plans
- Add AES encryption, or port samples to CryptoDomeX
- Add PUT and DELETE methods for Coinbase
- Add Kraken as a supported Exchange
- Add Binance as a supported Exchange (from USA ?!?)
- Mask input on private data so it’s is muted on screen
Install and Initial Setup
This utility allows you to use a Cryptocurrency Exchange’s REST API to perform basic tasks and retrieve current and historical account data. You will need to setup API / OAuth2 access keys in your account to use this utility. The utility supports both GPG and Trezor-CipherKeyValue encryption. You will need either a GPG key pair installed, or a Trezor attached. As a fallback you can store API keys in naked JSON, but that is obviously not recommended.
Install with Debug support
If you want to debug one of the client calls or step into a requests call, you can install from GIT sources. Then you can add breakpoints in source (breakpoint()
) to get more detailed information.
- Get source:
git clone https://github.com/brianddk/pyexch.git
- Switch directories:
cd pyexch
- Install develop mode via pip:
pip install -e .
- Verify install (cli-mode):
pyexch --help
- Optionally add
breakpoint()
into one of the*.py
files - Optionally step through code in the python debugger (
pdb
)