Blog
WebSocketsTrading systemsTypeScriptNode.jsJavaScript

Using proxy with Siebly SDKs

Configure Siebly proxies crypto trading api Node.js to bypass IP rate limits and geo-blocks. Learn to inject proxy agents for stable Binance & Bybit SDKs.

Siebly.io8 min readMarkdown

Overview

A trading bot is only as reliable as its networking layer. IP-based rate limits and regional API restrictions show up quickly when you run Node.js integrations at scale. Proxies let you route traffic through a different IP without rewriting your signing logic.

This guide shows how to wire HTTP and SOCKS proxies into Siebly.io SDK constructors. The pattern is the same across the major packages: pass axios networking options for REST, and pass a proxy agent through wsOptions for WebSockets.

SDKs covered here:

Key Takeaways

  • REST clients take proxy settings in the second constructor argument (AxiosRequestConfig), not inside your API key options.
  • WebSocket clients take a proxy agent via wsOptions.agent. Binance (private streams), KuCoin, and Kraken also need requestOptions for internal REST (listen keys / tokens).
  • Axios native proxy config works for many providers. If it does not, use https-proxy-agent or socks-proxy-agent.
  • Request signing happens locally in the SDK. The proxy only forwards the finished request.
  • SDKs do not rotate proxies for you. Handle that in your app or at the proxy provider.
  • Load credentials from environment variables or a secret manager. Never hardcode them.

Why proxies matter

Rate limiting and IP reputation

Exchanges like Binance and Bybit track request volume per IP. Go over the limit and you get HTTP 429 responses. Keep pushing and the IP can end up blocked entirely.

A proxy pool spreads REST polling across multiple IPs. That helps with public market data workloads where one server IP cannot carry the full request load.

Regional restrictions

Some endpoints only work from certain regions. That affects okx-api, @siebly/kraken-api, gateio-api, and kucoin-api depending on which market or region you target. A proxy in the right location lets your app reach those gateways without moving your main compute.

Signing is not affected

Exchanges like OKX and Kraken require accurate timestamps in signed requests. Extra proxy latency can trigger recv window errors if you are close to the limit.

The SDK signs the request before it hits the network. The proxy does not rewrite auth headers. If you see timestamp errors after adding a proxy, increase the recv window. The Bybit SDK documents this directly in its proxy examples (recv_window defaults to 5000 ms).

Before touching private endpoints, call a public method like a ticker or server time check to confirm routing works.

Install dependencies

npm install https-proxy-agent socks-proxy-agent

Most Siebly SDKs use axios under the hood. These agent libraries plug into axios and into the ws package used by WebSocket clients.

REST API proxy setup

REST clients follow the same constructor shape across the SDKs:

new SomeRestClient(restOptions, networkOptions);

  • restOptions: API keys, testnet flags, recv window, and other SDK settings.
  • networkOptions: axios config, including proxy settings.

Option 1: axios native proxy config

This pattern comes from the bybit-api proxy example and matches what the SDK test suites use:

import { RestClientV5 } from "bybit-api";

const client = new RestClientV5( { key: process.env.BYBIT_API_KEY, secret: process.env.BYBIT_API_SECRET, testnet: true, // Extra latency from a proxy can cause recv window errors // recv_window: 10000, }, { proxy: { protocol: "http", host: process.env.PROXY_HOST!, port: Number(process.env.PROXY_PORT), auth: { username: process.env.PROXY_USER!, password: process.env.PROXY_PASS!, }, }, }, );

The same second-argument pattern works for:

PackageCommon REST client
binanceMainClient, USDMClient, CoinMClient
bybit-apiRestClientV5
okx-apiRestClient
@siebly/kraken-apiSpotClient, DerivativesClient
bitget-apiRestClientV2
bitmart-apiRestClient
gateio-apiRestClient
kucoin-apiSpotClient, FuturesClient
coinbase-apiCBAdvancedTradeClient, CBExchangeClient, etc.

Binance example:

import { MainClient } from "binance";

const client = new MainClient( { testnet: true }, { proxy: { protocol: "http", host: process.env.PROXY_HOST!, port: Number(process.env.PROXY_PORT), auth: { username: process.env.PROXY_USER!, password: process.env.PROXY_PASS!, }, }, }, );

const serverTime = await client.getServerTime();

Kraken example:

import { SpotClient } from "@siebly/kraken-api";

const client = new SpotClient( { apiKey: process.env.KRAKEN_API_KEY, apiSecret: process.env.KRAKEN_API_SECRET, }, { proxy: { protocol: "http", host: process.env.PROXY_HOST!, port: Number(process.env.PROXY_PORT), auth: { username: process.env.PROXY_USER!, password: process.env.PROXY_PASS!, }, }, }, );

Coinbase example:

import { CBAdvancedTradeClient } from "coinbase-api";

const client = new CBAdvancedTradeClient( {}, { proxy: { protocol: "http", host: process.env.PROXY_HOST!, port: Number(process.env.PROXY_PORT), auth: { username: process.env.PROXY_USER!, password: process.env.PROXY_PASS!, }, }, }, );

Option 2: HttpsProxyAgent

Some proxy providers do not work with axios proxy config. Use https-proxy-agent instead, as shown in bybit-api rest-v5-proxies2.ts:

import { HttpsProxyAgent } from "https-proxy-agent"; import { RestClientV5 } from "bybit-api";

const client = new RestClientV5( { key: process.env.BYBIT_API_KEY, secret: process.env.BYBIT_API_SECRET, testnet: true, }, { httpAgent: proxyAgent, httpsAgent: proxyAgent, }, );

WebSocket proxy setup

WebSocket clients accept a proxy through wsOptions.agent.

SOCKS5 example (Binance)

From the binance ws-proxy-socks example:

import { WebsocketClient } from "binance"; import { SocksProxyAgent } from "socks-proxy-agent";

const agent = new SocksProxyAgent(process.env.SOCKS_PROXY_URL!);

const wsClient = new WebsocketClient({ beautify: true, wsOptions: { agent, }, });

wsClient.on("open", (data) => { console.log("connected:", data.wsKey); });

wsClient.subscribeAll24hrTickers("usdm");

When you need requestOptions as well

Most WebSocket clients only need wsOptions.agent. Some also make internal REST calls (listen keys, WS auth tokens). For those, set both:

  • wsOptions.agent for the socket connection
  • requestOptions for axios-backed REST calls inside the client
PackageWS proxy knobs
bybit-api, okx-api, bitget-api, bitmart-api, gateio-api, coinbase-apiwsOptions.agent only
kucoin-api, @siebly/kraken-apiwsOptions.agent + requestOptions (token fetch)
binancewsOptions.agent; add requestOptions for private user-data / listen keys (WebsocketClient and WebsocketAPIClient)

Kraken / KuCoin example (token fetch over REST):

import { HttpsProxyAgent } from "https-proxy-agent"; import { WebsocketClient } from "kucoin-api";

const wsClient = new WebsocketClient({ apiKey: process.env.KUCOIN_API_KEY, apiSecret: process.env.KUCOIN_API_SECRET, apiPassphrase: process.env.KUCOIN_API_PASSPHRASE, wsOptions: { agent: proxyAgent, }, requestOptions: { httpAgent: proxyAgent, httpsAgent: proxyAgent, }, });

Bybit needs only the socket agent:

import { HttpsProxyAgent } from "https-proxy-agent"; import { WebsocketClient } from "bybit-api";

const wsClient = new WebsocketClient({ key: process.env.BYBIT_API_KEY, secret: process.env.BYBIT_API_SECRET, wsOptions: { agent: proxyAgent, }, });

Binance private streams (listen keys) need the same split on WebsocketClient or WebsocketAPIClient. From the SDK test suite:

import { WebsocketAPIClient } from "binance";

const wsAPIClient = new WebsocketAPIClient({ api_key: process.env.BINANCE_API_KEY, api_secret: process.env.BINANCE_API_SECRET, wsOptions: { agent: proxyAgent, }, requestOptions: { proxy: { protocol: "http", host: process.env.PROXY_HOST!, port: Number(process.env.PROXY_PORT), auth: { username: process.env.PROXY_USER!, password: process.env.PROXY_PASS!, }, }, }, });

HTTP vs SOCKS5 for WebSockets

HTTP proxies work for REST and for many WebSocket setups. SOCKS5 is often a better fit for long-lived private streams because it tunnels raw TCP with less overhead.

For okx-api, bitget-api, bitmart-api, gateio-api, bybit-api, and coinbase-api, pass the agent through wsOptions.agent only.

Gate.io example:

import { WebsocketClient } from "gateio-api"; import { SocksProxyAgent } from "socks-proxy-agent";

const agent = new SocksProxyAgent(process.env.SOCKS_PROXY_URL!);

const ws = new WebsocketClient({ apiKey: process.env.GATE_API_KEY, apiSecret: process.env.GATE_API_SECRET, wsOptions: { agent }, });

Per-SDK examples

Binance (binance)

  • REST: new MainClient(restOptions, networkOptions)
  • WebSocket (public streams): wsOptions.agent
  • WebSocket private user-data / listen keys: wsOptions.agent + requestOptions
  • WebSocket API (order commands over WS): wsOptions + requestOptions
  • Test with testnet: true or demoTrading: true in restOptions

Bybit (bybit-api)

  • REST: new RestClientV5(restOptions, networkOptions)
  • Official proxy examples: examples/Rest/rest-v5-proxies.ts and rest-v5-proxies2.ts
  • WebSocket: wsOptions.agent only (requestOptions.agent is a legacy alias for the same WS agent)
  • Test with testnet: true on the v5 testnet

OKX (okx-api)

  • REST: new RestClient(restOptions, networkOptions)
  • WebSocket: wsOptions.agent
  • WebSocket API client: WebsocketAPIClient with the same agent pattern
  • Demo trading: demoTrading: true (not market: 'demo')

Kraken (@siebly/kraken-api)

  • REST: new SpotClient(restOptions, networkOptions) or DerivativesClient
  • WebSocket: wsOptions.agent + requestOptions for axios REST token fetches
  • Testnet: testnet: true (derivatives demo environment)

Bitget (bitget-api)

  • REST: new RestClientV2(restOptions, networkOptions)
  • WebSocket: wsOptions.agent on WebsocketClientV2
  • WS API commands (order placement over WS) need a stable tunnel; SOCKS5 is a solid default

BitMart (bitmart-api)

  • REST: new RestClient(restOptions, networkOptions)
  • WebSocket: wsOptions.agent

Gate.io (gateio-api)

  • REST: new RestClient(restOptions, networkOptions)
  • WebSocket: wsOptions.agent only
  • Sandbox: useTestnet: true

KuCoin (kucoin-api)

  • REST: new SpotClient(restOptions, networkOptions)
  • WebSocket: wsOptions.agent + requestOptions (bullet token over REST)
  • Regional routing: apiRegion: 'EU' | 'AU' in restOptions when needed

Coinbase (coinbase-api)

  • REST: second constructor arg on CBAdvancedTradeClient, CBExchangeClient, CBPrimeClient, etc.
  • WebSocket: wsOptions.agent on WebsocketClient
  • Sandbox: useSandbox: true where supported

Production notes

Treat the proxy as infrastructure you monitor, not a black box.

  • Health-check public endpoints before enabling private trading logic.
  • Rotate to a backup proxy if you see repeated 407 responses or persistent timeouts.
  • Halt order placement if proxy latency crosses a threshold you define.
  • Never grant withdrawal permissions on automation API keys.
  • Keep proxy and exchange credentials in environment variables or a secret manager.

For a broader view of how this fits into a full system, see the algorithmic trading system architecture guide.

Frequently Asked Questions

How do I use an HTTP proxy with the Bybit SDK?

Pass axios networking config as the second constructor argument. You can use the native proxy object or an HttpsProxyAgent via httpAgent/httpsAgent. See examples/Rest/rest-v5-proxies.ts in the bybit-api repo.

Does using a proxy affect request signing?

No. The SDK signs locally before the request leaves your process. The proxy only forwards the payload.

Can I use a SOCKS5 proxy for WebSocket streams?

Yes. Pass a SocksProxyAgent through wsOptions.agent. This works across Binance, Bybit, OKX, Kraken, Bitget, BitMart, Gate.io, KuCoin, and Coinbase WebSocket clients.

Will a proxy help me avoid Bybit or Binance rate limits?

It helps with IP-based limits by spreading traffic across multiple addresses. It does not bypass account-level limits tied to your API key.

What Node.js libraries should I use for proxy agents?

https-proxy-agent for HTTP/HTTPS proxies and socks-proxy-agent for SOCKS5. Both integrate with the axios config that Siebly SDKs accept.

Do Siebly SDKs rotate proxies automatically?

No. Build rotation in your application, or use a provider that rotates at the gateway.

Is it safe to pass proxy credentials in the SDK constructor?

Yes, as long as the values come from environment variables or a secret manager at runtime, not from source code.

How much latency does a proxy add?

Usually 5 to 50 ms depending on geography and protocol. For coinbase-api, pick a proxy region close to the exchange gateway you are hitting.

Article by Siebly.io

Related articles

Continue from here

Related Siebly resources

All articles

Subscribe on Substack

Complete the Substack form below to join our newsletter. Substack handles all subscriber data directly.