Binance Misc JavaScript SDK example: ws-proxy-socks.ts

Binance Misc websocket proxy socks JavaScript example for the Siebly Binance SDK, covering exchange REST API and WebSocket integration, setup, and production SDK docs.

We use environment variables in our examples for API keys. It is your responsibility to manage and secure your keys appropriately.

examples/Binance/WebSockets/Misc/ws-proxy-socks.ts

What this example covers

  • Binance WebSocket stream JavaScript example.
  • Uses the Siebly Binance SDK package binance instead of hand-written WebSocket plumbing.
  • Source path: Binance/WebSockets/Misc/ws-proxy-socks.ts.
  • Example category: Misc.
  • Imports SDK symbols including WebsocketClient.
  • Calls SDK methods such as on(), subscribeAll24hrTickers().

How to use this example

  • Start here for the specific request or stream pattern, then check the matching SDK guide for install, credentials, and operational notes.
  • For WebSocket examples, keep reconnect, resubscribe, heartbeat, and event-handler behavior explicit in your service.
  • Open the repository source when you need the latest committed version: GitHub source file.
/** * Minimal example for using a socks proxy with the ws client, extracted from https://github.com/tiagosiebler/binance/pull/319 */import { WebsocketClient } from 'binance';import { SocksProxyAgent } from 'socks-proxy-agent';// const { SocksProxyAgent } = require('socks-proxy-agent'); const agent = new SocksProxyAgent(process.env.http_proxy || '');const wsClient = new WebsocketClient({  beautify: true,  wsOptions: {    agent: agent,  },}); wsClient.on('formattedMessage', (data) => {  console.log('log formattedMessage: ', data);});wsClient.on('open', (data) => {  console.log('connection opened open:', data.wsKey, data.wsUrl);}); wsClient.on('response', (data) => {  console.log('log response: ', JSON.stringify(data, null, 2));});wsClient.on('reconnecting', (data) => {  console.log('ws automatically reconnecting.... ', data?.wsKey);});wsClient.on('reconnected', (data) => {  console.log('ws has reconnected ', data?.wsKey);}); wsClient.subscribeAll24hrTickers('usdm'); 

Subscribe on Substack

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