Binance JavaScript SDK example: rest-spot-private-autoinvest.ts

Binance REST spot private autoinvest 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/Rest/Spot/rest-spot-private-autoinvest.ts

What this example covers

  • Binance REST API JavaScript example.
  • Uses the Siebly Binance SDK package binance instead of hand-written HTTP request plumbing.
  • Source path: Binance/Rest/Spot/rest-spot-private-autoinvest.ts.
  • Imports SDK symbols including MainClient.
  • Calls SDK methods such as submitAutoInvestOneTimeTransaction(), submitAutoInvestmentPlan().

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.
  • Open the repository source when you need the latest committed version: GitHub source file.
import { MainClient } from 'binance'; const key = process.env.API_KEY_COM || 'APIKEY';const secret = process.env.API_SECRET_COM || 'APISECRET'; const client = new MainClient({  api_key: key,  api_secret: secret,  beautifyResponses: true,}); (async () => {  try {    const oneTimeTransactionResult =      await client.submitAutoInvestOneTimeTransaction({        sourceType: 'MAIN_SITE',        subscriptionAmount: 100,        sourceAsset: 'USDT',        details: [          {            targetAsset: 'BTC',            percentage: 60,          },          {            targetAsset: 'ETH',            percentage: 40,          },        ],      });     console.log('oneTimeTransactionResult', oneTimeTransactionResult);     const autoInvestPlanResult = await client.submitAutoInvestmentPlan({      UID: '54545454',      sourceType: 'MAIN_SITE',      subscriptionAmount: 100,      sourceAsset: 'USDT',      planType: 'SINGLE',      flexibleAllowedToUse: true,      subscriptionCycle: 'DAILY',      subscriptionStartTime: 5,      details: [        {          targetAsset: 'BTC',          percentage: 100,        },      ],    });     console.log('autoInvestPlanResult', autoInvestPlanResult);  } catch (e) {    console.error('request failed: ', e);  }})(); 

Subscribe on Substack

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