coinbase-advanced-py icon indicating copy to clipboard operation
coinbase-advanced-py copied to clipboard

How can I connect to the Coinbase Sandbox API

Open nMaroulis opened this issue 9 months ago • 6 comments

How can I use the Rest Client to connect to Coinbase Sandbox API?

Thanks

nMaroulis avatar Mar 12 '25 17:03 nMaroulis

Thank you for reporting! If this is an SDK specific issue, we will look into it and get back to you soon. If this is an API related request, report it in our Advanced API Discord instead (use this invite link if it's your first time accessing the Discord).

github-actions[bot] avatar Mar 12 '25 17:03 github-actions[bot]

You do:

from coinbase.rest import RESTClient
from coinbase.websocket import WSClient,
http = RESTClient(
	api_key=key.api,
	api_secret=key.secret,
	timeout=5,
        base_url="api-sandbox.coinbase.com"
)
ws = WSClient(
	api_key=key.api,
	api_secret=key.secret,
	base_url="wss://ws-feed-public.sandbox.exchange.coinbase.com"
)

ghost avatar Mar 12 '25 20:03 ghost

Thanks for your answer @melukasz . I was unable to connect to the API. Maybe I'm confused about the sandbox API in general. I created an account here https://public-sandbox.exchange.coinbase.com/ and as a base_url I use the following https://api-public.sandbox.exchange.coinbase.com . I also found that I have to use an API key, Secret Key, Passphrase combination, but the coinbase.rest.RESTClient doesnt even have a passphrase argument.

nMaroulis avatar Mar 13 '25 00:03 nMaroulis

Thanks for your answer @melukasz . I was unable to connect to the API. Maybe I'm confused about the sandbox API in general. I created an account here https://public-sandbox.exchange.coinbase.com/ and as a base_url I use the following https://api-public.sandbox.exchange.coinbase.com . I also found that I have to use an API key, Secret Key, Passphrase combination, but the coinbase.rest.RESTClient doesnt even have a passphrase argument.

O wow, I didn't know something like this exists https://public-sandbox.exchange.coinbase.com/ Thanks a lot!

ghost avatar Mar 13 '25 08:03 ghost

Just FYI I saw that the cbpro library does the trick, but it's really outdated, so I ended up using the requests library and send custom HTTP requests.

nMaroulis avatar Mar 13 '25 12:03 nMaroulis

Och right, that sandbox is for buisness owners only :/

ghost avatar Mar 15 '25 13:03 ghost

For anyone looking to connect to the sandbox, you can monkeypatch the BASE_URL constant:

import os

import coinbase.constants

coinbase.constants.BASE_URL = "api-sandbox.coinbase.com"

from coinbase.rest import RESTClient

client = RESTClient(
    api_key=os.environ.get('COINBASE_KEY'),
    api_secret=os.environ.get('COINBASE_SECRET'),
)

accounts = client.get_accounts()
print(accounts)

Hope that helps

timborden avatar Nov 07 '25 12:11 timborden