Skip to content

Use a proxy ​

Configure REST and WebSocket connections separately. These examples are for Node.js; browser applications cannot configure Node socket agents. Keep proxy URLs and passwords on the server, outside source control and logs.

A proxy changes your network route, not the selected exchange environment, account permissions or rate limits.

If a Coinbase API key uses an IP allowlist, allow the proxy's egress IP.

HTTP or HTTPS proxy for REST ​

Pass Axios configuration in the REST client's second constructor argument:

ts
import { CBAdvancedTradeClient } from 'coinbase-api';

export const client = new CBAdvancedTradeClient(
  {},
  {
    proxy: { protocol: 'http', host: '127.0.0.1', port: 8080 },
    timeout: 20000,
  },
);

Set protocol, host and port to your proxy, not the exchange. Use protocol: 'https' for a TLS connection to the proxy. For proxy authentication, add auth: { username, password } using values loaded from your environment or secret store.

In Node.js, Axios can also read HTTP_PROXY, HTTPS_PROXY and NO_PROXY when no explicit proxy is configured. Do not rely on those variables for WebSockets; configure their agent or constructor explicitly.

Proxy agents for REST and WebSockets ​

For an HTTP CONNECT proxy, install the agent in your project:

sh
npm install https-proxy-agent

Set PROXY_URL to a full HTTP or HTTPS proxy URL. If credentials are included in the URL, URL-encode the username and password components.

ts
import { HttpsProxyAgent } from 'https-proxy-agent';
import { CBAdvancedTradeClient, WebsocketClient } from 'coinbase-api';

const proxyUrl = process.env.PROXY_URL;
if (!proxyUrl) {
  throw new Error('Set PROXY_URL to your HTTP or HTTPS proxy URL.');
}

const agent = new HttpsProxyAgent(proxyUrl);
export const client = new CBAdvancedTradeClient(
  { keepAlive: false },
  { proxy: false, httpsAgent: agent, timeout: 20000 },
);
export const ws = new WebsocketClient({ wsOptions: { agent } });

proxy: false disables Axios proxy routing, including proxy environment variables, so the agent controls the REST route. Keep the SDK's keepAlive option false: enabling it replaces your custom agent with a standard HTTPS agent. Configure connection reuse on the custom agent itself if needed.

wsOptions.agent configures the Node.js WebSocket transport independently. The same setting is accepted by WebsocketAPIClient. Coinbase WebSocket authentication is performed through signing or the socket session; these clients do not have the separate REST token request options used by some other exchange SDKs.

SOCKS5 ​

Install socks-proxy-agent, replace the HttpsProxyAgent import with SocksProxyAgent, and construct the agent from your SOCKS proxy URL:

sh
npm install socks-proxy-agent
ts
import { SocksProxyAgent } from 'socks-proxy-agent';

const agent = new SocksProxyAgent('socks5h://127.0.0.1:1080');

socks5h:// resolves destination hostnames through the proxy. Keep proxy: false for REST and pass the agent as httpsAgent; Axios's proxy object does not support SOCKS.

Pass the SOCKS agent as both REST httpsAgent and wsOptions.agent, with REST proxy: false and SDK keepAlive: false.

Verify the route ​

Use a public getPublicProduct() request and an Advanced Trade ticker subscription with the configured clients. Confirm both connections in the proxy logs. Successful REST routing alone does not prove WebSocket routing.

  • A 407 response usually means proxy authentication is missing or rejected.
  • Connection timeouts can indicate the proxy cannot reach the exchange or does not allow CONNECT/WebSocket traffic.
  • Keep TLS certificate verification enabled. For an approved corporate proxy, use its trusted CA rather than disabling verification.
  • Extra latency can affect signed-request timing. Keep the machine clock synchronized and distinguish the HTTP timeout from the exchange's acceptance window.
  • Do not log whole request configurations, proxy URLs with credentials or signed request data.

See configuration, production usage and the Siebly proxy guide.

Built by Siebly. Open source SDKs for exchange APIs.