📜  binance js - Javascript (1)

📅  最后修改于: 2023-12-03 15:13:39.399000             🧑  作者: Mango

Binance JS - Javascript

Binance JS is a Javascript library that allows you to interact with the Binance API. With this library, you can create trading bots, analyze historical data, place orders, and more.

Installation

You can install Binance JS using npm:

npm install binance-api-node
Usage

First, you need to create an instance of the client:

const Binance = require('binance-api-node').default;
const client = Binance({
  apiKey: 'YOUR_API_KEY',
  apiSecret: 'YOUR_API_SECRET',
});
Examples

Get current account balance

const balance = await client.accountInfo();
console.log(balance.balances);

Get historical candlestick data

const candles = await client.candles({
  symbol: 'BTCUSDT',
  interval: '1d',
  limit: 30,
});
console.log(candles);

Place market buy order

const order = await client.order({
  symbol: 'BTCUSDT',
  side: 'BUY',
  type: 'MARKET',
  quantity: 0.001,
});
console.log(order);

For more examples and documentation, please refer to the official Binance API documentation.

Conclusion

Binance JS is a powerful tool for building trading bots, analyzing data, and automating your trading strategies on the Binance Exchange. With its easy to use API and extensive documentation, you can quickly get started with your project.