Skip to content

binance/binance-cli

Repository files navigation

Binance CLI

Latest Release npm Downloads

A simple CLI that interacts with the Binance API

binance-cli demo

Installation

# Install from npm
npm install -g @binance/binance-cli

Usage

Help

Use --help to consult all the available commands

binance-cli --help

--help is supported for each product and each command.

binance-cli demo

Authentication

Using Environment variable

# Display help command
binance-cli -h

# Set the API key and secret as global variables
export BINANCE_API_KEY=<the_api_key>
export BINANCE_SECRET_KEY=<the_api_secret> # Can be secret key, path to private key or content of private key

# Set the environment (prod by default, valid options: prod, demo and testnet)
export BINANCE_API_ENV=testnet

# It is possible to have a custom base URL
export BINANCE_SPOT_BASE_PATH=https://testnet.binance.vision
export BINANCE_FUTURES_USDS_BASE_PATH=https://testnet.binancefuture.com

Using profile (non-interactive)

Create a new profile
binance-cli profile create --name new-name --api-key <the_api_key> --api-secret <the_api_secret> --env prod
Change the active profile
binance-cli profile change --name new-name

View the current active profile

binance-cli profile view

Specify profile

It is also possible to specify the profile for a single command.

binance-cli spot get-account --profile my_profile

Using profile (interactive)

Create a new profile
binance-cli profile create -i # binance-cli will prompt the questions to create a new profile
Change the active profile
binance-cli profile change -i # select the profile to activate
View the current active profile
binance-cli profile view

Commands

Available commands

Parameters

CLI Argument
binance-cli spot klines --symbol "BNBUSDT" --interval "1s"
Using pipe
echo '{"symbol": "BNBUSDT", "interval": "1s"}' | binance-cli spot klines

Using interactive mode

binance-cli spot klines -i

Completion

In order to add completion, the following steps can be followed:

For Bash:

Append the output to the .bashrc file:

binance-cli completion >> ~/.bashrc
For Zsh:

Append the output to the .zshrc file:

binance-cli completion >> ~/.zshrc

After updating the file, the terminal needs to be restarted or activate the completion with source ~/.bashrc (or .zshrc).

Custom request

Custom request can also be sent using binance-cli, any parameter can be added to the command and will be sent in the request.

binance-cli request GET https://api.binance.com/api/v3/trades --symbol BNBUSDT --limit 5

Signed endpoints are also supported.

binance-cli request GET https://testnet.binance.vision/api/v3/account --signed

LICENSE

MIT

Contributors