Package: bnc
Binance CLIThis package provides a unified command-line interface to interact with Binance API (https://binance-docs.github.io/apidocs)ℹ️This is an unofficial package, and this project is not related or affiliated with Binance.🚨Use the package at your own risk. We highly recommend using the testnet version at the beginning.Jump to:Getting StartedRequirementsInstallationGenerate API Key and Secret KeyAdd CredentialsBasic CommandsCommand OutputJSON FormatYAML FormatQuery with JMESPathGetting startedWe have released a special version of the Binance CLI package for testing purposes. It is calledbnc_testnetand it contains the same functionality asbnc.Both versions can co-exist on the same computer because they are independent and use different folders for configuration.The complete documentation of the Binance CLI package will refer tobnc. When you want to use testnet version, you have to replacebncwithbnc_testnet.We highly recommend usingbnc_testnetat the beginning to gain experience using the Binance CLI package and then switch tobnc.Keep in mind that use a testnet version implies not using real money.RequirementsThe Binance CLI package works on Python versions:3.8.x and greaterInstallationInstallation of the Binance CLI and its dependencies use various packaging features provided bypipandsetuptools.
It's recommended to use:pip: 21.1setuptools: 56.0The safest way to install the Binance CLI is to usepipin avirtualenv:$python-mpipinstallbncTestnet$python-mpipinstallbnc_testnetor, if you are not installing in avirtualenv, to install globally:$sudopython-mpipinstallbncTestnet$sudopython-mpipinstallbnc_testnetor for your user:$python-mpipinstall--userbncTestnet$python-mpipinstall--userbnc_testnetIf you have the Binance CLI package installed and want to upgrade to the latest version, you can run:$python-mpipinstall--upgradebncTestnet$python-mpipinstall--upgradebnc_testnetNOTEAt this moment, we only usepipto install the Binance CLI package.
We are planning to add more options for the distribution and installation of the Binance CLI package.Generate API Key and Secret KeyYou should have an active Binance account to create a valid API key and secret key.You can follow this step-by-step guide provided by Binance:Create an API KeyFor testnet you can follow:Generate API key for TestnetAdd credentialsBefore using BNC CLI, you need to tell it about your credentials. You can do this in several ways:Configuration file(recommended)Environment variablesThe quickest way to get started is to run thebnc credentials addcommand:$bnccredentialsadd--api_key="YOUR_API_KEY"--secret="YOUR_SECRET_KEY"BinanceCLI'scredentialsaddedsuccessfully.When you add your credentials using the previous command, it will create an INI formatted file calledcredentialsunder~/.bncdirectory with the following structure:[api_credentials]
bnc_cli_api_key = <YOUR_API_KEY>
bnc_cli_secret_key = <YOUR_SECRET_KEY>To use environment variables, do the following:$exportBNC_CLI_API_KEY=<YOUR_API_KEY>
$exportBNC_CLI_SECRET_KEY=<YOUR_SECRET_KEY>The testnet version uses different environment variables:$exportBNC_TESTNET_CLI_API_KEY=<YOUR_API_KEY>
$exportBNC_TESTNET_CLI_SECRET_KEY=<YOUR_SECRET_KEY>Basic CommandsA BNC CLI command has the following structure:$bnc<command>[optionsandparameters]$bnc<command><group_commands><command>[optionsandparameters]To view help documentation, use one of the following:$bnc--help
$bnc<command>--help
$bnc<command><group_commands>--help
$bnc<command><group_commands><command>--helpTo get the version of the BNC CLI:$bnc--versionTo turn on verbose output:$bnc--verbose<command>
$bnc--verbose<group_commands><command>Command OutputThe default output for commands is currently JSON.YAMLformat is also available to format output. You can select either style with the--outputoption at the root commandbnc.ExampleJSON (Default)$bncspotaccount_info{"makerCommission":0,"takerCommission":0,"buyerCommission":0,"sellerCommission":0,"canTrade":true,"canWithdraw":false,"canDeposit":false,"updateTime":1616376905442,"accountType":"SPOT","balances":[{"asset":"BNB","free":"1000.00000000","locked":"0.00000000"},{"asset":"BTC","free":"0.98181601","locked":"0.00000000"}],"permissions":["SPOT"]}YAML$bnc--output=yamlspotaccount_infomakerCommission:0takerCommission:0buyerCommission:0sellerCommission:0canTrade:truecanWithdraw:falsecanDeposit:falseupdateTime:1616376905442accountType:SPOTbalances:-asset:BNBfree:'1000.00000000'locked:'0.00000000'-asset:BTCfree:'0.98181601'locked:'0.00000000'permissions:-SPOTJMESPath (--query)Some commands have an--queryoption that allows extracting and transforming elements from a JSON. It is very useful on occasions where you need to filter a very long response from Binance API. For more information on the expression language used for this option, you can read theJMESPath Tutorial