binance-connector-js

repository·master·Indexed 20 days ago

https://github.com/binance/binance-connector-js

An official collection of auto-generated TypeScript connectors for various Binance APIs, organized into modular, service-specific npm packages. It includes connectors such as @binance/algo, @binance/alpha, @binance/c2c, @binance/convert, and @binance/copy-trading. The library provides access to REST API endpoints and WebSocket streams for real-time data, requiring Node.js version 22.12.0 or later.

Tokens
220.2K
Snippets
549
Records
705
Agent score
70%

What's inside binance-connector-js

  1. Overview of the Binance USDS-M Futures Connector

    master

    The @binance/derivatives-trading-usds-futures library is a client for the Binance Derivatives Trading USDS-M Futures API. It provides programmatic access to Binance's derivative trading features through three primary interfaces:

    1. REST API: Access to /fapi/* endpoints for request-response operations.
    2. Websocket API: Real-time request-response communication.
    3. Websocket Streams: Real-time data streaming.

    The library includes test cases and examples to assist with onboarding.

  2. Overview of @binance/derivatives-trading-options

    master

    The @binance/derivatives-trading-options library is a client library for the Binance Derivatives Trading Options API. It allows developers to interact programmatically with Binance's Options API through two primary interfaces:

    1. REST API: Access to /eapi/* endpoints.
    2. Websocket Stream: Real-time data streaming.

    The library includes test cases and examples to assist with onboarding.

  3. Overview of the Binance JavaScript SPOT Connector

    master

    The @binance/spot library is a client library for the Binance SPOT API. It allows developers to interact programmatically with Binance's SPOT trading platform for retrieving market data, executing trades, and managing orders. The library is organized into three distinct interaction patterns:

    1. REST API: For standard request-response interactions.
    2. Websocket API: For real-time data streaming and request-response communication over WebSockets.
    3. Websocket Stream: For continuous real-time data streams.
  4. Overview of the COIN-M Futures Connector

    master

    The @binance/derivatives-trading-coin-futures library is a client for the Binance Derivatives Trading COIN-M Futures API. It provides programmatic access to Binance's derivative trading features through three primary interfaces:

    1. REST API: For standard request-response interactions using the /dapi/* endpoints.
    2. Websocket API: For real-time request-response communication over WebSockets.
    3. Websocket Stream: For real-time data streaming (market data, etc.) via WebSockets.
  5. Overview of @binance/common utilities

    master

    The @binance/common package is a utility library designed for Binance modular connectors. It provides reusable, optimized, and lightweight helpers for interacting with Binance REST and WebSocket APIs.

    Key features include:

    • Common Utility Functions: Helpers for API requests, timestamp management, and signature generation.
    • TypeScript Support: Fully compatible with TypeScript for strong type safety.
    • Tree-Shakeable: Optimized to allow developers to import only the specific utilities they need, reducing bundle size.
  6. Migrate from @binance/connector to @binance/c2c

    master

    The Binance Connector has transitioned from a monolithic package (@binance/connector) to a modularized structure. To use C2C features, you must migrate to the dedicated @binance/c2c library. This involves updating your installation, import paths, and client initialization logic.

    # 1. Uninstall the old monolithic package
    npm uninstall @binance/connector
    
    # 2. Install the new modular C2C package
    npm install @binance/c2c
  7. Configure a proxy for Simple Earn REST API

    master

    If you need to route your requests through a proxy server, you can provide a proxy object within the configuration object passed to the SimpleEarn constructor. The proxy object supports host, port, protocol, and optional authentication credentials.

    import { SimpleEarn, SimpleEarnRestAPI } from '@binance/simple-earn';
    
    const configurationRestAPI = {
        apiKey: 'your-api-key',
        apiSecret: 'your-api-secret',
        proxy: {
            host: '127.0.0.1',
            port: 8080,
            protocol: 'http', // or 'https'
            auth: {
                username: 'proxy-user',
                password: 'proxy-password',
            },
        },
    };
    
    const client = new SimpleEarn({ configurationRestAPI });
    
    client.restAPI
        .getSimpleEarnFlexibleProductList()
        .then((res) => res.data())
        .then((data: SimpleEarnRestAPI.GetSimpleEarnFlexibleProductListResponse) => console.log(data))
        .catch((err) => console.error(err));
  8. Configure compression for the Dual Investment REST API

    master

    When initializing the DualInvestment client, you can control whether the REST API requests use compression by setting the compression key in the configuration object.

    • Set compression: true to enable compression (default behavior for reducing payload size).
    • Set compression: false to disable compression.

    This configuration is passed within the object provided to the DualInvestment constructor.

    import { DualInvestment, DualInvestmentRestAPI } from '@binance/dual-investment';
    
    const configurationRestAPI = {
        apiKey: 'your-api-key',
        apiSecret: 'your-api-secret',
        compression: false, // Disable compression
    };
    
    const client = new DualInvestment({ configurationRestAPI });
    
    client.restAPI
        .getDualInvestmentPositions()
        .then((res) => res.data())
        .then((data: DualInvestmentRestAPI.GetDualInvestmentPositionsResponse) => console.log(data))
        .catch((err) => console.error(err));
  9. Configure retries for the Derivatives Trading Portfolio Margin client

    master

    When initializing the DerivativesTradingPortfolioMargin client, you can configure automatic retries for REST API calls to improve resilience against transient network errors.

    Use the retries key in the configuration object to specify the maximum number of retry attempts. Use the backoff key to define the delay (in milliseconds) between each retry attempt.

    import { DerivativesTradingPortfolioMargin } from '@binance/derivatives-trading-portfolio-margin';
    
    const configurationRestAPI = {
        apiKey: 'your-api-key',
        apiSecret: 'your-api-secret',
        retries: 5, // Retry up to 5 times
        backoff: 2000, // 2 seconds between retries
    };
    
    const client = new DerivativesTradingPortfolioMargin({ configurationRestAPI });
    
    client.restAPI
        .accountInformation()
        .then((res) => res.data())
        .then((data) => console.log(data))
        .catch((err) => console.error(err));
  10. Configure retries for Derivatives Trading Options REST API

    master

    When initializing the DerivativesTradingOptions client, you can configure automatic retry logic for REST API requests to handle transient network errors or rate limits.

    Use the retries property to specify the maximum number of retry attempts and the backoff property to define the delay (in milliseconds) between each attempt.

    import { DerivativesTradingOptions } from '@binance/derivatives-trading-options';
    
    const configurationRestAPI = {
        apiKey: 'your-api-key',
        apiSecret: 'your-api-secret',
        retries: 5, // Retry up to 5 times
        backoff: 2000, // 2 seconds between retries
    };
    
    const client = new DerivativesTradingOptions({ configurationRestAPI });
    
    client.restAPI
        .optionAccountInformation()
        .then((res) => res.data())
        .then((data) => console.log(data))
        .catch((err) => console.error(err));