Skip to content
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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ FIX/sessions
__pycache__/
*.pyc
*.pyo
FIX/example.cfg
FIX/example.cfg
t_*
52 changes: 52 additions & 0 deletions REST/prime_cancel_entity_futures_sweep.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# Copyright 2025-present Coinbase Global, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import argparse
import base64
import hashlib
import hmac
import json
import os
import time
from urllib.parse import urlparse

import requests

API_KEY = os.environ.get('ACCESS_KEY')
SECRET_KEY = os.environ.get('SIGNING_KEY')
PASSPHRASE = os.environ.get('PASSPHRASE')

parser = argparse.ArgumentParser(description='Cancel pending futures sweep for an entity')
parser.add_argument('--entity-id', type=str, required=True, help='Entity ID')

args = parser.parse_args()

uri = f'https://api.prime.coinbase.com/v1/entities/{args.entity_id}/futures/sweeps'

url_path = urlparse(uri).path
timestamp = str(int(time.time()))
message = timestamp + 'DELETE' + url_path
signature_b64 = base64.b64encode(hmac.digest(SECRET_KEY.encode(), message.encode(), hashlib.sha256))

headers = {
'X-CB-ACCESS-SIGNATURE': signature_b64,
'X-CB-ACCESS-TIMESTAMP': timestamp,
'X-CB-ACCESS-KEY': API_KEY,
'X-CB-ACCESS-PASSPHRASE': PASSPHRASE,
'Accept': 'application/json'
}

response = requests.delete(uri, headers=headers)
parsed_response = json.loads(response.text)
print(json.dumps(parsed_response, indent=3))
11 changes: 10 additions & 1 deletion REST/prime_cancel_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,17 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import base64
import hashlib
import hmac
import json
import os
import sys
import time
import uuid
from urllib.parse import urlparse
import json, hmac, hashlib, time, uuid, os, base64, requests, sys

import requests

API_KEY = os.environ.get('ACCESS_KEY')
SECRET_KEY = os.environ.get('SIGNING_KEY')
Expand Down
67 changes: 67 additions & 0 deletions REST/prime_claim_wallet_staking_rewards.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# Copyright 2025-present Coinbase Global, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import argparse
import base64
import hashlib
import hmac
import json
import os
import time
import uuid
from urllib.parse import urlparse

import requests

API_KEY = os.environ.get('ACCESS_KEY')
SECRET_KEY = os.environ.get('SIGNING_KEY')
PASSPHRASE = os.environ.get('PASSPHRASE')
PORTFOLIO_ID = os.environ.get('PORTFOLIO_ID')

parser = argparse.ArgumentParser(description='Claim wallet staking rewards (alpha)')
parser.add_argument('--wallet-id', type=str, required=True, help='Wallet ID')
parser.add_argument('--amount', type=str, help='Amount to claim (ETH only, defaults to maximum available)')

args = parser.parse_args()

uri = f'https://api.prime.coinbase.com/v1/portfolios/{PORTFOLIO_ID}/wallets/{args.wallet_id}/staking/claim_rewards'

url_path = urlparse(uri).path
timestamp = str(int(time.time()))

payload = {
'idempotency_key': str(uuid.uuid4())
}

if args.amount:
payload['inputs'] = {
'amount': args.amount
}

payload_json = json.dumps(payload)
message = timestamp + 'POST' + url_path + payload_json
signature_b64 = base64.b64encode(hmac.digest(SECRET_KEY.encode(), message.encode(), hashlib.sha256))

headers = {
'X-CB-ACCESS-SIGNATURE': signature_b64,
'X-CB-ACCESS-TIMESTAMP': timestamp,
'X-CB-ACCESS-KEY': API_KEY,
'X-CB-ACCESS-PASSPHRASE': PASSPHRASE,
'Accept': 'application/json',
'Content-Type': 'application/json'
}

response = requests.post(uri, headers=headers, data=payload_json)
parsed_response = json.loads(response.text)
print(json.dumps(parsed_response, indent=3))
10 changes: 9 additions & 1 deletion REST/prime_create_address_book_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,16 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import base64
import hashlib
import hmac
import json
import os
import time
import uuid
from urllib.parse import urlparse
import json, hmac, hashlib, time, uuid, os, base64, requests

import requests

API_KEY = os.environ.get('ACCESS_KEY')
SECRET_KEY = os.environ.get('SIGNING_KEY')
Expand Down
16 changes: 13 additions & 3 deletions REST/prime_create_allocations.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,20 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import json, hmac, hashlib, time, uuid, os, base64, requests, argparse, sys
import argparse
import base64
import hashlib
import hmac
import json
import os
import sys
import time
import uuid
from urllib.parse import urlparse

# Must be entity or organization API key
import requests


API_KEY = os.environ.get('ACCESS_KEY')
SECRET_KEY = os.environ.get('SIGNING_KEY')
PASSPHRASE = os.environ.get('PASSPHRASE')
Expand Down Expand Up @@ -45,7 +55,7 @@
allocation_legs = []
for dest_portfolio_id in args.destination_portfolio_ids:
allocation_legs.append({
'allocation_leg_id': allocation_leg_id,
'allocation_leg_id': str(allocation_leg_id),
'destination_portfolio_id': dest_portfolio_id,
'amount': str(amount)
})
Expand Down
48 changes: 29 additions & 19 deletions REST/prime_create_conversion.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,35 +12,44 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import argparse
import base64
import hashlib
import hmac
import json
import os
import time
import uuid
from urllib.parse import urlparse
import json, hmac, hashlib, time, uuid, os, base64, requests

import requests

API_KEY = os.environ.get('ACCESS_KEY')
SECRET_KEY = os.environ.get('SIGNING_KEY')
PASSPHRASE = os.environ.get('PASSPHRASE')
PORTFOLIO_ID = os.environ.get('PORTFOLIO_ID')

wallet_id = 'WALLET_UUID'
# Parse command line arguments
parser = argparse.ArgumentParser(description='Create a conversion between USD, USDC, and PYUSD')
parser.add_argument('--wallet-id', type=str, required=True, help='Source wallet ID')
parser.add_argument('--amount', type=str, required=True, help='Amount to convert')
parser.add_argument('--destination', type=str, required=True, help='Destination wallet ID')
parser.add_argument('--source-symbol', type=str, required=True, choices=['USD', 'USDC', 'PYUSD'], help='Source symbol (USD, USDC, or PYUSD)')
parser.add_argument('--destination-symbol', type=str, required=True, choices=['USD', 'USDC', 'PYUSD'], help='Destination symbol (USD, USDC, or PYUSD)')

uri = f'https://api.prime.coinbase.com/v1/portfolios/{PORTFOLIO_ID}/wallets/{wallet_id}/conversion'
args = parser.parse_args()

timestamp = str(int(time.time()))
uri = f'https://api.prime.coinbase.com/v1/portfolios/{PORTFOLIO_ID}/wallets/{args.wallet_id}/conversion'

# only supports conversions between USDC and USD
amount = '1'
destination = 'DESTINATION_WALLET_UUID'
idempotency_key = uuid.uuid4()
source_symbol = 'USD'
destination_symbol = 'USDC'
timestamp = str(int(time.time()))
idempotency_key = str(uuid.uuid4())

payload = {
'portfolio_id': PORTFOLIO_ID,
'wallet_id': wallet_id,
'amount': amount,
'destination': destination,
'idempotency_key': str(idempotency_key),
'source_symbol': source_symbol,
'destination_symbol': destination_symbol
'amount': args.amount,
'destination': args.destination,
'idempotency_key': idempotency_key,
'source_symbol': args.source_symbol,
'destination_symbol': args.destination_symbol
}

url_path = urlparse(uri).path
Expand All @@ -52,9 +61,10 @@
'X-CB-ACCESS-TIMESTAMP': timestamp,
'X-CB-ACCESS-KEY': API_KEY,
'X-CB-ACCESS-PASSPHRASE': PASSPHRASE,
'Accept': 'application/json'
'Accept': 'application/json',
'Content-Type': 'application/json'
}

response = requests.post(uri, json=payload, headers=headers)
response = requests.post(uri, headers=headers, data=json.dumps(payload))
parsed_response = json.loads(response.text)
print(json.dumps(parsed_response, indent=3))
63 changes: 63 additions & 0 deletions REST/prime_create_locate.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# Copyright 2025-present Coinbase Global, Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import argparse
import base64
import hashlib
import hmac
import json
import os
import time
from urllib.parse import urlparse

import requests

API_KEY = os.environ.get('ACCESS_KEY')
SECRET_KEY = os.environ.get('SIGNING_KEY')
PASSPHRASE = os.environ.get('PASSPHRASE')
PORTFOLIO_ID = os.environ.get('PORTFOLIO_ID')

# Parse command line arguments
parser = argparse.ArgumentParser(description='Create a new locate')
parser.add_argument('--symbol', type=str, required=True, help='Asset symbol (e.g., BTC, ETH)')
parser.add_argument('--amount', type=str, required=True, help='Amount to locate')
parser.add_argument('--locate-date', type=str, required=True)

args = parser.parse_args()

uri = f'https://api.prime.coinbase.com/v1/portfolios/{PORTFOLIO_ID}/locates'
timestamp = str(int(time.time()))

payload = {
'portfolio_id': PORTFOLIO_ID,
'symbol': args.symbol,
'amount': args.amount,
'locate_date': args.locate_date
}

url_path = urlparse(uri).path
message = timestamp + 'POST' + url_path + json.dumps(payload)
signature_b64 = base64.b64encode(hmac.digest(SECRET_KEY.encode(), message.encode(), hashlib.sha256))

headers = {
'X-CB-ACCESS-SIGNATURE': signature_b64,
'X-CB-ACCESS-TIMESTAMP': timestamp,
'X-CB-ACCESS-KEY': API_KEY,
'X-CB-ACCESS-PASSPHRASE': PASSPHRASE,
'Accept': 'application/json'
}

response = requests.post(uri, json=payload, headers=headers)
parsed_response = json.loads(response.text)
print(json.dumps(parsed_response, indent=3))
Loading