@@ -1436,10 +1436,12 @@ export async function executeTradingTask(
14361436 logger . silly ( "executeTradingTask->notifyAll: " + reason )
14371437 } )
14381438
1439- // Check that you still have enough BNB in each wallet
1440- checkBNBThreshold ( ) . catch ( ( reason ) => {
1441- logger . silly ( "executeTradingTask->checkBNBThreshold: " + reason )
1442- } )
1439+ if ( tradeOpen . tradingType == TradingType . real ) {
1440+ // Check that you still have enough BNB in this wallet
1441+ checkBNBThreshold ( tradeOpen . wallet ! ) . catch ( ( reason ) => {
1442+ logger . silly ( "executeTradingTask->checkBNBThreshold: " + reason )
1443+ } )
1444+ }
14431445}
14441446
14451447// Notify NBT Hub that the trade has been executed
@@ -2363,43 +2365,38 @@ async function refreshMarkets() {
23632365// Loads the balances from Binance and checks whether you still have sufficient BNB funds to cover fees and interest
23642366// This also helps to pre-cache the balances ready for the next trade
23652367const BNBState : Dictionary < string > = { }
2366- async function checkBNBThreshold ( ) {
2368+ async function checkBNBThreshold ( wallet : WalletType ) {
23672369 if ( env ( ) . BNB_FREE_THRESHOLD >= 0 ) {
2368- for ( let wallet of Object . values ( WalletType ) ) {
2369- // Skip if margin trading is not in use
2370- if ( wallet == WalletType . MARGIN && ! env ( ) . IS_TRADE_MARGIN_ENABLED ) continue
2371-
2372- // Initialise dictionary, assuming it is ok to start with
2373- if ( ! ( wallet in Object . keys ( BNBState ) ) ) BNBState [ wallet ] = "ok"
2374-
2375- // Fetch the BNB balance for this wallet
2376- const balance = ( await fetchBalance ( wallet ) ) [ "BNB" ]
2377- logger . debug ( `${ balance . free } BNB free in ${ wallet } .` )
2378- if ( balance . free <= env ( ) . BNB_FREE_THRESHOLD ) {
2379- // Check if the low balance hasn't already been reported
2380- if ( BNBState [ wallet ] == "ok" || ( BNBState [ wallet ] == "low" && balance . free <= 0 ) ) {
2381- // Log the low balance warning or error for empty balance
2382- let notifyLevel = MessageType . WARN
2383- let logMessage = `Your ${ wallet } wallet only has ${ balance . free } BNB free. You may need to top it up.`
2384- if ( balance . free <= 0 ) {
2385- BNBState [ wallet ] = "empty"
2386- notifyLevel = MessageType . ERROR
2387- logMessage = `Your ${ wallet } wallet has no free BNB. You will need to top it up now.`
2388- logger . error ( logMessage )
2389- } else {
2390- BNBState [ wallet ] = "low"
2391- logger . warn ( logMessage )
2392- }
2393-
2394- // Send as a notification
2395- notifyAll ( { subject : notifyLevel , content : logMessage } ) . catch ( ( reason ) => {
2396- logger . silly ( "checkBNBThreshold->notifyAll: " + reason )
2397- } )
2370+ // Initialise dictionary, assuming it is ok to start with
2371+ if ( ! ( wallet in Object . keys ( BNBState ) ) ) BNBState [ wallet ] = "ok"
2372+
2373+ // Fetch the BNB balance for this wallet
2374+ const balance = ( await fetchBalance ( wallet ) ) [ "BNB" ]
2375+ logger . debug ( `${ balance . free } BNB free in ${ wallet } .` )
2376+ if ( balance . free <= env ( ) . BNB_FREE_THRESHOLD ) {
2377+ // Check if the low balance hasn't already been reported
2378+ if ( BNBState [ wallet ] == "ok" || ( BNBState [ wallet ] == "low" && balance . free <= 0 ) ) {
2379+ // Log the low balance warning or error for empty balance
2380+ let notifyLevel = MessageType . WARN
2381+ let logMessage = `Your ${ wallet } wallet only has ${ balance . free } BNB free. You may need to top it up.`
2382+ if ( balance . free <= 0 ) {
2383+ BNBState [ wallet ] = "empty"
2384+ notifyLevel = MessageType . ERROR
2385+ logMessage = `Your ${ wallet } wallet has no free BNB. You will need to top it up now.`
2386+ logger . error ( logMessage )
2387+ } else {
2388+ BNBState [ wallet ] = "low"
2389+ logger . warn ( logMessage )
23982390 }
2399- } else {
2400- // Reset once the balance has exceeded the threshold again
2401- BNBState [ wallet ] = "ok"
2391+
2392+ // Send as a notification
2393+ notifyAll ( { subject : notifyLevel , content : logMessage } ) . catch ( ( reason ) => {
2394+ logger . silly ( "checkBNBThreshold->notifyAll: " + reason )
2395+ } )
24022396 }
2397+ } else {
2398+ // Reset once the balance has exceeded the threshold again
2399+ BNBState [ wallet ] = "ok"
24032400 }
24042401 }
24052402}
0 commit comments