Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Read keys from file #110

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
cdp_api_key.json
myenv/
*.DS_Store
.idea
*.pyc
Expand All @@ -18,4 +20,4 @@ tests/__pycache__/
test.py
promptlib/
*.log
!requirements.txt
!requirements.txt
23 changes: 12 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,28 @@ This is the unofficial Python client for the Coinbase Advanced Trade API. It all

## Setup

1. Install the package using pip:
1. Install the required packages using pip:
```bash
pip install coinbase-advancedtrade-python
pip install -r requirements.txt
```

2. Obtain your API key and secret from the Coinbase Developer Platform. The new API key format looks like this:
```
API Key: organizations/{org_id}/apiKeys/{key_id}
API Secret: -----BEGIN EC PRIVATE KEY-----\n...\n-----END EC PRIVATE KEY-----\n
2. Obtain your API key and secret from the Coinbase Developer Platform.

Download the api key in Coinbase. Move `cdp_api_key.json` into project folder. Python code will read keys from this file. You may rename `cdp_api_key.json` to something like strategy1.json to seperate different keys/logic.
```

## Authentication

Here's an example of how to authenticate using the new method:

```python
```
from coinbase_advanced_trader.enhanced_rest_client import EnhancedRESTClient
from include import load_api_credentials

api_key = "organizations/{org_id}/apiKeys/{key_id}"
api_secret = "-----BEGIN EC PRIVATE KEY-----\n...\n-----END EC PRIVATE KEY-----\n"
# Load API credentials
api_key, api_secret = load_api_credentials() # Default case opens cdp_api_key.json
#api_key, api_secret = load_api_credentials( 'foo.json' ) # Optional case opens a file name given, different keys to open different CB portfolios

# use loaded keys
client = EnhancedRESTClient(api_key=api_key, api_secret=api_secret)
```

Expand Down Expand Up @@ -211,4 +212,4 @@ GitHub: https://github.com/rhettre/coinbase-advancedtrade-python

## Disclaimer

This project is not affiliated with, maintained, or endorsed by Coinbase. Use this software at your own risk. Trading cryptocurrencies carries a risk of financial loss. The developers of this software are not responsible for any financial losses or damages incurred while using this software. Nothing in this software should be seen as an inducement to trade with a particular strategy or as financial advice.
This project is not affiliated with, maintained, or endorsed by Coinbase. Use this software at your own risk. Trading cryptocurrencies carries a risk of financial loss. The developers of this software are not responsible for any financial losses or damages incurred while using this software. Nothing in this software should be seen as an inducement to trade with a particular strategy or as financial advice.
12 changes: 12 additions & 0 deletions include.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import json

def load_api_credentials(json_file_path='cdp_api_key.json'):
# Read the JSON file
with open(json_file_path, 'r') as file:
data = json.load(file)

# Extract the API key and secret
api_key = data['name']
api_secret = data['privateKey']

return api_key, api_secret
9 changes: 9 additions & 0 deletions use_include.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
from include import load_api_credentials

# Load API credentials
api_key, api_secret = load_api_credentials()

# Print to verify
print(f"API Key: {api_key}")
print(f"API Secret: {api_secret}")