I failed to receive the balance update notifications for "binance.websockets.userData"

In the following example, I have two questions.

  1. I failed to receive the balance update notifications for “binance.websockets.userData” when someone transfer the ICP (amount: 0.00000001) to my account.
  2. For the following api, it will report error: binance.sapiRequest is not a function
    binance.sapiRequest(‘v1/pay/transactions’, { timestamp: Date.now(), limit: 1 }, (error, response)

TypeError: binance.sapiRequest is not a function
at getRecentTransactions (file:///D:/index.mjs:43:19)
at handler (file:///D:/index.mjs:30:20)

======================================================

import Binance from “node-binance-api”;

try{

const binance = new Binance().options({
    APIKEY: "api key of my account ",
    APISECRET: "secret key of my account "
});   

binance.websockets.userData(balance_update => {
    console.log("Balance Update: ", balance_update);
    transactions = getRecentTransactions(binance); 
}, execution_update => {
    console.log("Execution Update: ", execution_update);
});

}
catch(error) {
console.error("get error : "+ error)
}

async function getRecentTransactions(binance) {

await binance.sapiRequest('v1/pay/transactions', 
		{ timestamp: Date.now(), limit: 1 }, (error, response) => {
    if (error) return console.error(error);
    console.log("Recent Transaction: ", response);
    return response.data;
    // parseTransactionResponse(response);
});

}

From what I understand, you seem to be encountering two issues with your code.

These are balance update notifications and binance.sapiRequest.

Using the appropriate method provided by the library for this error binance.sapiRequest may resolve the issue.

My comment for the Balance Update Notifications error is, are you sure your WebSocket connection is properly established?

Shameless plug but this is one of the many reasons I eventually built my own SDK. Highly resilient user data connections - even if you lose your internet connection for several days, as soon as it’s back it’ll automatically reconnect and resubscribe to the user data stream. It’ll even push an event to let you know it just reconnected, which is when you would then call the REST APIs to rehydrate your own local state (fetch latest balances, orders, fills, etc). You’ll find it on npm, published simply as “binance”. Lots of examples on github: