Closed rvS1337 closed 7 months ago
Hi @rvS1337, we've removed the deprecated endpoints in our latest release, although for the missing endpoints, since they're a lot, it'll take some time to integrate them and unfortunately we don't have that much bandwidth on our side to do it at the moment.
However, if it's of your interest, feel free to open a PR with those endpoints to accelerate the process.
Edit: 2024/01/27 - Add custom function to redeem flexible products
Hello,
I have developed an extension to the @binance/connector Node.js library. This extension adds new API call methods which are not currently available in the official package. The purpose of this enhancement is to provide additional functionality while maintaining compatibility with the existing features of the @binance/connector library.
Below, you will find the BinanceCustomSpot module, which includes methods for subscribing to ETH Staking V2 and to flexible products, as outlined in the Binance API documentation. This module is designed to be a temporary solution, anticipating the eventual inclusion of these methods in the official Binance connector package.
Feel free to explore the code, use it in your projects, and provide any feedback or contributions you see fit.
Best regards, A French Binance Angel.
/**
* BinanceCustomSpot Module
*
* This module extends the '@binance/connector' package by adding new API call methods
* which are currently not available in the official library. It is designed to be
* a temporary solution until these API calls are integrated into the official package.
*
* Usage:
*
* To use this module, import it and instantiate it with your Binance API key
* and secret. This instance will enable you to access both the newly introduced methods
* specific to this module and the standard methods available in the '@binance/connector' package.
*
* Example:
*
* const BinanceCustomSpot = require('./path/to/BinanceCustomSpot');
* const client = new BinanceCustomSpot(BINANCE_API_KEY, BINANCE_API_SECRET);
*
* client.subscribeFlexibleProduct(productId, amount, timestamp, options)
* .then(res => console.log(res))
* .catch(err => console.error(err));
*/
const { Spot } = require("@binance/connector");
class BinanceCustomSpot extends Spot {
constructor(apiKey, apiSecret) {
super(apiKey, apiSecret);
}
/**
* Subscribe ETH Staking V2 (TRADE)
*
* {@link https://binance-docs.github.io/apidocs/spot/en/#subscribe-eth-staking-v2-trade}
*
* @param {number} amount - Amount in ETH, limit 4 decimals. (Mandatory)
* @param {number} timestamp - The timestamp for the request. It's the time when the request is sent. (Mandatory)
* @param {object} [options] - Additional optional parameters for the request. (Optional)
* @param {number} [options.recvWindow] - The value cannot be greater than 60000. This parameter is used to specify the number of milliseconds after timestamp during which the request is valid. (Optional)
*
*/
subscribeEthStakingV2(amount, timestamp, options = {}) {
// NOTE: not sure if it is possible to use validateRequiredParameters without duplicating the code of the original library (to be checked)
//validateRequiredParameters({ amount, timestamp });
return this.signRequest(
"POST",
"/sapi/v2/eth-staking/eth/stake",
Object.assign(options, {
amount,
timestamp,
}),
);
}
/**
* Subscribe to a Flexible Product (TRADE)
*
* POST /sapi/v1/simple-earn/flexible/subscribe
*
* {@link https://binance-docs.github.io/apidocs/spot/en/#subscribe-flexible-product-trade}
*
* @param {string} productId - The product ID for subscription. (Mandatory)
* @param {number} amount - The amount for subscription. (Mandatory)
* @param {number} timestamp - The timestamp for the request. It's the time when the request is sent. (Mandatory)
* @param {object} [options] - Additional optional parameters for the request. (Optional)
* @param {boolean} [options.autoSubscribe] - true or false, default true. (Optional)
* @param {string} [options.sourceAccount] - Source account type: SPOT, FUND, ALL. Default is SPOT. (Optional)
* @param {number} [options.recvWindow] - The value cannot be greater than 60000. This parameter is used to specify the number of milliseconds after timestamp during which the request is valid. (Optional)
*
*/
subscribeFlexibleProduct(productId, amount, timestamp, options = {}) {
// NOTE: not sure if it is possible to use validateRequiredParameters without duplicating the code of the original library (to be checked)
//validateRequiredParameters({ productId, amount, timestamp });
return this.signRequest(
"POST",
"/sapi/v1/simple-earn/flexible/subscribe",
Object.assign(options, {
productId,
amount,
timestamp,
}),
);
}
/**
* Redeem a Flexible Product (TRADE)
*
* POST /sapi/v1/simple-earn/flexible/redeem
*
* {@link https://binance-docs.github.io/apidocs/spot/en/#redeem-flexible-product-trade}
*
* @param {string} productId - The product ID for redemption. (Mandatory)
* @param {number} timestamp - The timestamp for the request. It's the time when the request is sent. (Mandatory)
* @param {object} [options] - Additional optional parameters for the request. (Optional)
* @param {boolean} [options.redeemAll] - true or false, default to false. (Optional)
* @param {number} [options.amount] - The amount for redemption. Mandatory if redeemAll is false. (Optional)
* @param {string} [options.destAccount] - Destination account type: SPOT, FUND, ALL. Default is SPOT. (Optional)
* @param {number} [options.recvWindow] - The value cannot be greater than 60000. This parameter is used to specify the number of milliseconds after timestamp during which the request is valid. (Optional)
*
*/
redeemFlexibleProduct(productId, timestamp, options = {}) {
// NOTE: not sure if it is possible to use validateRequiredParameters without duplicating the code of the original library (to be checked)
//validateRequiredParameters({ productId, timestamp, ... (options.redeemAll ? {} : { amount: options.amount }) });
return this.signRequest(
"POST",
"/sapi/v1/simple-earn/flexible/redeem",
Object.assign(options, {
productId,
timestamp,
}),
);
}
}
module.exports = BinanceCustomSpot;
when simple earn ?
@aisling-2 fancy to have a look at #153? I'm happy to make any amends needed.
Hi @Danswar, we truly appreciate the PR. However, we're currently lacking some resources for maintaining the public repositories, so it will take some time for the review and release. Apologies!
When simple-earn ?
The simple earn has been added to the latest version, v3.3.0: https://github.com/binance/binance-connector-node/releases/tag/v3.3.0
sapi/v1/lending/daily/purchase is deprecated
The new endpoint for this is:
https://binance-docs.github.io/apidocs/spot/en/#subscribe-flexible-product-trade POST /sapi/v1/simple-earn/flexible/subscribe
Bonus: I didn't find the eth-staking function either, I suppose it is not implemented
Thank you for your work