Withdraw from master account

Hi,

If I want to deposit funds into the master account, will the same function be used to return the chain and addresses?

const client = new Spot(apiKey, apiSecret);
client
.depositAddress(“SOL”)
.then((response) => client.logger.log(response.data))
.catch((error) => client.logger.error(error));

Also, which API should I use to withdraw from the master account to my external account (MetaMask)?

Hi @Umaid_Khalid,

Regarding your first question, yes, you can use the same function depositAddress() to retrieve the deposit address for your master account. This function returns the deposit address and available network chains for the specified asset.

For withdrawing funds from your master account to an external account like MetaMask, you should use the Withdraw API provided by Binance. The endpoint for this is:

POST /sapi/v1/capital/withdraw/apply

You’ll need to provide:

  • coin: The asset you want to withdraw
  • address: Your external wallet address (MetaMask in your case).
  • amount: The amount you want to withdraw.
const client = new Spot(apiKey, apiSecret);

client.withdraw({
    coin: "SOL",
    address: "your-metamask-wallet-address",
    amount: "1.5"
})
.then(response => console.log(response.data))
.catch(error => console.error(error));

Important Notes:

  1. Ensure that your API key has withdraw permissions enabled.
  2. Withdrawals may require whitelisting depending on your Binance security settings.
  3. Check the Binance fee structure for network withdrawal fees.

You can also have a deeper look on the Withdraw API Documentation

Let me know if you need further clarification!

1 Like

Thanks for your answer.

I also need help in conversion since the Binance API doesn’t provide a direct convert API.
For example, if I want to convert SOL to XRP, so currently I am using the spot market API. Is there any other way to do this? Because if there is no direct trading pair, I have to first convert SOL to USDT and then USDT to XRP, which incurs extra fees.

You’re right that Binance doesn’t provide a direct Convert API in the NodeJS connector, but Binance does have a dedicated Convert Trade API that allows you to swap assets directly without needing to go through an intermediate trading pair.

Use Binance Convert API

  • Endpoint: POST /sapi/v1/convert/getQuote (for a price quote)
  • Endpoint: POST /sapi/v1/convert/acceptQuote (to execute the conversion)

This method avoids trading fees and allows direct conversion when supported.

Steps to Convert SOL → XRP

  1. Get a conversion quote

    • Use /sapi/v1/convert/getQuote to check if SOL → XRP is supported.
    • It returns a quote ID and conversion rate.
  2. Accept the quote

    • Use /sapi/v1/convert/acceptQuote to execute the swap.
const axios = require('axios');

const apiKey = 'your-api-key';
const apiSecret = 'your-api-secret';
const baseURL = 'https://api.binance.com';

// Function to get a conversion quote
async function getConvertQuote(fromAsset, toAsset, amount) {
    const response = await axios.post(`${baseURL}/sapi/v1/convert/getQuote`, {
        fromAsset,
        toAsset,
        fromAmount: amount
    }, {
        headers: { 'X-MBX-APIKEY': apiKey }
    });

    return response.data;
}

// Function to accept the quote and execute the trade
async function acceptConvertTrade(quoteId) {
    const response = await axios.post(`${baseURL}/sapi/v1/convert/acceptQuote`, {
        quoteId
    }, {
        headers: { 'X-MBX-APIKEY': apiKey }
    });

    return response.data;
}

// Example Usage
(async () => {
    try {
        const quote = await getConvertQuote('SOL', 'XRP', '10');
        console.log('Quote:', quote);

        const tradeResult = await acceptConvertTrade(quote.quoteId);
        console.log('Trade Result:', tradeResult);
    } catch (error) {
        console.error('Error:', error.response?.data || error.message);
    }
})();

BTW, the requests above need to be signed first, so you’ll need to add a timestamp and a signature on both or you can always use the signRequest() function that NodeJS connector exposes to achieve both.

Let me know if you need more details!

1 Like