Gathering detailed insights and metrics for wirnata15-binance_futures_sdk
Gathering detailed insights and metrics for wirnata15-binance_futures_sdk
This one is a node.js SDK for futures trading
npm install wirnata15-binance_futures_sdk
Typescript
Module System
Min. Node Version
Node Version
NPM Version
71.6
Supply Chain
98.1
Quality
81.5
Maintenance
100
Vulnerability
100
License
JavaScript (100%)
Verify real, reachable, and deliverable emails with instant MX records, SMTP checks, and disposable email detection.
Total Downloads
935
Last Day
1
Last Week
4
Last Month
12
Last Year
935
MIT License
20 Commits
1 Watchers
1 Branches
1 Contributors
Updated on Sep 23, 2024
Minified
Minified + Gzipped
Latest Version
0.2.1
Package Id
wirnata15-binance_futures_sdk@0.2.1
Unpacked Size
70.24 kB
Size
12.20 kB
File Count
17
NPM Version
9.8.1
Node Version
18.18.2
Published on
Sep 23, 2024
Cumulative downloads
Total Downloads
Last Day
0%
1
Compared to previous day
Last Week
0%
4
Compared to previous week
Last Month
-58.6%
12
Compared to previous month
Last Year
0%
935
Compared to previous year
This is a lightweight library that works as a connector to Binance public API. It’s designed to be simple, clean, and easy to use with minimal dependencies.
/api/*
/sapi/*
1npm i wirnata15-binance_futures_sdk
https://binance.github.io/binance-connector-node/
1const { Futures } = require("wirnata15-binance_futures_sdk"); 2 3const apiKey = ""; 4const apiSecret = ""; 5const client = new Futures(apiKey, apiSecret); 6 7// Get account information 8client.account().then((response) => client.logger.log(response.data)); 9 10// Place a new order 11client 12 .newOrder("BNBUSDT", "BUY", "LIMIT", { 13 price: "350", 14 quantity: 1, 15 timeInForce: "GTC", 16 }) 17 .then((response) => client.logger.log(response.data)) 18 .catch((error) => client.logger.error(error));
Please find examples
folder to check for more endpoints.
1const { Spot, PrivateKeyAlgo } = require("@binance/connector"); 2 3const apiKey = ""; 4const apiSecret = ""; // has no effect when RSA private key is provided 5 6// load private key 7const privateKey = fs.readFileSync("/Users/john/ssl/private_key_encrypted.pem"); 8const privateKeyPassphrase = "password"; 9const privateKeyAlgo = PrivateKeyAlgo.RSA; // for RSA key 10const privateKeyAlgo = PrivateKeyAlgo.ED25519; // for Ed25519 key 11 12const client = new Spot(apiKey, apiSecret, { 13 privateKey, 14 privateKeyPassphrase, // only used for encrypted key 15 privateKeyAlgo, 16}); 17 18// Get account information 19client.account().then((response) => client.logger.log(response.data));
While /sapi/*
endpoints don't have testnet environment yet, /api/*
endpoints can be tested in
Spot Testnet. You can use it by changing the base URL:
1// provide the testnet base url 2const client = new Spot(apiKey, apiSecret, { 3 baseURL: "https://testnet.binance.vision", 4});
If base_url
is not provided, it defaults to api.binance.com
.
It's recommended to pass in the base_url
parameter, even in production as Binance provides alternative URLs in case of performance issues:
https://api1.binance.com
https://api2.binance.com
https://api3.binance.com
Optional parameters are encapsulated to a single object as the last function parameter.
1const { Futures } = require("wirnata15-binance_futures_sdk"); 2 3const apiKey = ""; 4const apiSecret = ""; 5const client = new Spot(apiKey, apiSecret); 6 7client 8 .account({ recvWindow: 2000 }) 9 .then((response) => client.logger.log(response.data));
It's easy to set timeout in milliseconds in request. If the request take longer than timeout, the request will be aborted. If it's not set, there will be no timeout.
1const { Futures } = require("wirnata15-binance_futures_sdk"); 2 3const apiKey = ""; 4const apiSecret = ""; 5const client = new Spot(apiKey, apiSecret, { timeout: 1000 }); 6 7client 8 .account() 9 .then((response) => client.logger.log(response.data)) 10 .catch((error) => client.logger.error(error.message));
The axios
package is used as the http client in this library. A proxy settings is passed into axios
directly, the details can be found at here:
1const { Spot } = require("@binance/connector"); 2 3const apiKey = ""; 4const apiSecret = ""; 5const client = new Spot(apiKey, apiSecret, { 6 proxy: { 7 protocol: "https", 8 host: "127.0.0.1", 9 port: 9000, 10 auth: { 11 username: "proxy_user", 12 password: "password", 13 }, 14 }, 15});
You may have a HTTP proxy, that can bring the problem that you need to make a HTTPS connection through the HTTP proxy. You can do that by build a HTTPS-over-HTTP tunnel by npm package tunnel, and then pass the turnnel agent to httpsAgent
in axios
.
1const tunnel = require("tunnel"); 2 3const agent = tunnel.httpsOverHttp({ 4 proxy: { 5 host: "127.0.0.1", 6 port: 3128, 7 }, 8}); 9 10const client = new Spot(null, null, { 11 baseURL: "https://api.binance.com", 12 httpsAgent: agent, 13}); 14 15client 16 .time() 17 .then((response) => client.logger.log(response.data)) 18 .catch((error) => client.logger.error(error));
This comment provides more details.
The Binance API server provides weight usages in the headers of each response. This information can be fetched from headers
property. x-mbx-used-weight
and x-mbx-used-weight-1m
show the total weight consumed within 1 minute.
// client initialization is skipped
client.exchangeInfo().then(response => client.logger.log(response.headers['x-mbx-used-weight-1m']))
1const Spot = require("@binance/connector"); 2const fs = require("fs"); 3const { Console } = require("console"); 4 5// make sure the logs/ folder is created beforehand 6const output = fs.createWriteStream("./logs/stdout.log"); 7const errorOutput = fs.createWriteStream("./logs/stderr.log"); 8 9const logger = new Console({ stdout: output, stderr: errorOutput }); 10const client = new Spot("", "", { logger: logger }); 11 12client.exchangeInfo().then((response) => client.logger.log(response.data)); 13// check the output file
The default logger defined in the package is Node.js Console class. Its output is sent to process.stdout
and process.stderr
, same as the global console.
There are 2 types of error that may be returned from the API server and the user has to handle it properly:
Client error
4XX
, it's an issue from client side.Response Metadata
section for more details.-1102
Unknown order sent.
// client initialization is skipped
client.exchangeInfo({ symbol: 'invalidSymbol' })
.then(response => client.logger.log(response.data))
.catch(err => {
client.logger.error(err.response.headers) // full response header
client.logger.error(err.response.status) // HTTP status code 400
client.logger.error(err.response.data) // includes both error code and message
client.logger.error(err.response.config) // includes request's config
})
Server error
5XX
, it's an issue from server side.1npm install 2 3npm run test 4
Futures and Vanilla Options APIs are not supported:
/fapi/*
/dapi/*
/vapi/*
MIT
No vulnerabilities found.
No security vulnerabilities found.