diff --git a/basicswap/static/js/amm_tables.js b/basicswap/static/js/amm_tables.js
index bac643f..d362532 100644
--- a/basicswap/static/js/amm_tables.js
+++ b/basicswap/static/js/amm_tables.js
@@ -418,6 +418,7 @@ const AmmTablesManager = (function() {
const amountToSend = amount * maxRate;
const activeBidsCount = activeBids[name] && Array.isArray(activeBids[name]) ?
activeBids[name].length : 0;
+ const useBalanceBidding = bid.use_balance_bidding !== undefined ? bid.use_balance_bidding : false;
tableHtml += `
@@ -451,6 +452,11 @@ const AmmTablesManager = (function() {
Max: ${maxConcurrent}
+ ${useBalanceBidding ? `
+
+ Balance Bidding
+
+ ` : ''}
@@ -514,10 +520,19 @@ const AmmTablesManager = (function() {
'part blind': 'PART',
'bitcoin': 'BTC',
'btc': 'BTC',
+ 'bitcoin cash': 'BCH',
+ 'bitcoincash': 'BCH',
+ 'bch': 'BCH',
+ 'decred': 'DCR',
+ 'dcr': 'DCR',
+ 'dogecoin': 'DOGE',
+ 'doge': 'DOGE',
'monero': 'XMR',
'xmr': 'XMR',
'litecoin': 'LTC',
'ltc': 'LTC',
+ 'namecoin': 'NMC',
+ 'nmc': 'NMC',
'wownero': 'WOW',
'wow': 'WOW',
'dash': 'DASH',
@@ -526,7 +541,11 @@ const AmmTablesManager = (function() {
'xzc': 'FIRO',
'zcoin': 'FIRO',
'BTC': 'BTC',
+ 'BCH': 'BCH',
+ 'DCR': 'DCR',
+ 'DOGE': 'DOGE',
'LTC': 'LTC',
+ 'NMC': 'NMC',
'XMR': 'XMR',
'PART': 'PART',
'WOW': 'WOW',
@@ -591,7 +610,7 @@ const AmmTablesManager = (function() {
async function fetchLatestPrices() {
try {
- const coins = 'BTC,LTC,XMR,PART,WOW,FIRO,DASH,PIVX';
+ const coins = 'BTC,BCH,DCR,DOGE,LTC,NMC,XMR,PART,WOW,FIRO,DASH,PIVX';
const response = await fetch('/json/coinprices', {
method: 'POST',
@@ -1188,6 +1207,11 @@ const AmmTablesManager = (function() {
if (minSwapAmount) {
newItem.min_swap_amount = parseFloat(minSwapAmount);
}
+
+ const useBalanceBidding = document.getElementById('add-bid-use-balance-bidding').checked;
+ if (useBalanceBidding) {
+ newItem.use_balance_bidding = true;
+ }
}
if (type === 'offer') {
@@ -1369,6 +1393,7 @@ const AmmTablesManager = (function() {
document.getElementById('edit-bid-address').value = item.address || 'auto';
document.getElementById('edit-bid-min-swap-amount').value = item.min_swap_amount || '';
document.getElementById('edit-bid-offers-to-bid-on').value = item.offers_to_bid_on || 'all';
+ document.getElementById('edit-bid-use-balance-bidding').checked = item.use_balance_bidding || false;
}
}
@@ -1630,6 +1655,13 @@ const AmmTablesManager = (function() {
if (minSwapAmount) {
updatedItem.min_swap_amount = parseFloat(minSwapAmount);
}
+
+ const useBalanceBidding = document.getElementById('edit-bid-use-balance-bidding').checked;
+ if (useBalanceBidding) {
+ updatedItem.use_balance_bidding = true;
+ } else {
+ delete updatedItem.use_balance_bidding;
+ }
}
if (type === 'offer' && Array.isArray(config.offers)) {
diff --git a/basicswap/templates/amm.html b/basicswap/templates/amm.html
index f77d602..4cc3398 100644
--- a/basicswap/templates/amm.html
+++ b/basicswap/templates/amm.html
@@ -37,21 +37,21 @@
-
@@ -1312,6 +1313,15 @@
+
+
+
+
+
+
+
+
+ Use Balance Bidding: Calculate bid amount as (wallet_balance - offer_min_amount) instead of using template amount.
@@ -1586,6 +1596,15 @@
+
+
+
+
+
+
+
+
+ Use Balance Bidding: Calculate bid amount as (wallet_balance - offer_min_amount) instead of using template amount.
diff --git a/basicswap/ui/page_amm.py b/basicswap/ui/page_amm.py
index 468be2c..4ff4be4 100644
--- a/basicswap/ui/page_amm.py
+++ b/basicswap/ui/page_amm.py
@@ -1138,6 +1138,9 @@ def page_amm(self, _, post_string):
except ValueError:
pass
+ if form_data.get("bid_use_balance_bidding", [""])[0]:
+ new_bid["use_balance_bidding"] = True
+
if "bids" not in current_config:
current_config["bids"] = []
@@ -1243,6 +1246,7 @@ def page_amm(self, _, post_string):
# "max_coin_from_balance": 100.0, # Won't send bids if wallet amount would be above this
"address": "auto", # Address bid is sent from (auto = generate new address per bid)
"min_swap_amount": 0.001, # Minimum swap amount
+ # "use_balance_bidding": False, # Calculate bid amount as (wallet_balance - offer_min_amount) instead of using template amount
}
]
diff --git a/scripts/createoffers.py b/scripts/createoffers.py
index bcab6a2..5cd729e 100755
--- a/scripts/createoffers.py
+++ b/scripts/createoffers.py
@@ -61,6 +61,7 @@ Create offers
"amount_variable": Can send bids below the set "amount" where possible if true.
"max_coin_from_balance": Won't send bids if wallet amount of "coin_from" would be above.
"address": Address offer is sent from, default will generate a new address per bid.
+ "use_balance_bidding": If true, calculates bid amount as (wallet_balance - offer_min_amount) instead of using template amount.
},
...
]
@@ -1426,7 +1427,55 @@ def process_bids(args, config, script_state) -> None:
offer_id = offer["offer_id"]
offer_amount = float(offer["amount_from"])
offer_rate = float(offer["rate"])
- bid_amount = bid_template["amount"]
+
+ # Check if we should use balance-based bidding
+ use_balance_bidding = bid_template.get("use_balance_bidding", False)
+
+ if use_balance_bidding:
+ # Calculate bid amount based on available balance minus minimum amount
+ # This follows the same pattern as offers: balance - min_amount
+ try:
+ # Get wallet balance for the coin we're bidding with (coin_from in the offer)
+ wallet_from = read_json_api_wallet(
+ "wallets/{}".format(coin_from_data["ticker"])
+ )
+
+ wallet_balance = float(wallet_from.get("balance", 0)) + float(
+ wallet_from.get("unconfirmed", 0)
+ )
+
+ # Get minimum amount from the offer
+ offer_min_amount = float(offer.get("amount_bid_min", 0.001))
+
+ # Calculate available amount: balance - min_amount
+ available_amount = wallet_balance - offer_min_amount
+
+ if available_amount > 0:
+ bid_amount = available_amount
+ if args.debug:
+ print(
+ f"Using balance-based bidding: {bid_amount} (balance: {wallet_balance} - min: {offer_min_amount})"
+ )
+ else:
+ # Fallback to template amount if calculation fails
+ bid_amount = bid_template["amount"]
+ if args.debug:
+ print(
+ f"Insufficient balance for balance-based bid, using template amount: {bid_amount}"
+ )
+
+ except Exception as balance_error:
+ # Fallback to template amount if balance calculation fails
+ bid_amount = bid_template["amount"]
+ if args.debug:
+ print(
+ f"Error calculating balance-based bid amount: {balance_error}, using template amount: {bid_amount}"
+ )
+ else:
+ # Use traditional template amount
+ bid_amount = bid_template["amount"]
+ if args.debug:
+ print(f"Using template bid amount: {bid_amount}")
except (KeyError, TypeError, ValueError) as e:
if args.debug:
print(f"Error processing offer data: {e}, offer: {offer}")