Skip to content

Instantly share code, notes, and snippets.

@itsfolf
Last active August 21, 2021 04:17
Show Gist options
  • Save itsfolf/6350e50a7db9fdc46a5751c43c713686 to your computer and use it in GitHub Desktop.
Save itsfolf/6350e50a7db9fdc46a5751c43c713686 to your computer and use it in GitHub Desktop.
Calculate steam market fees
// Steam market fee calculator:tm:
// The price you're selling at, in cents
var sellPrice = 100
// Handy toggles
var inMarketPage = !!g_rgWalletInfo;
var hasItemSelectred = !!g_ActiveInventory.selectedItem.description.market_fee;
// Steam values, may vary per region or game, defaults at the end.
var steamFeePercent = inMarketPage ? g_rgWalletInfo['wallet_fee_percent'] : 0.05
var steamFeeMinimum = inMarketPage ? g_rgWalletInfo['wallet_fee_minimum'] : 1
var steamFeeBase = inMarketPage ? g_rgWalletInfo['wallet_fee_base'] : 0
var publisherFeePercent = hasItemSelectred ? g_ActiveInventory.selectedItem.description.market_fee : 0.10
var calculateFees = (receivedAmount) => {
var steamFee = Math.floor(Math.max(receivedAmount * steamFeePercent, steamFeeMinimum) + steamFeeBase)
var publisherFee = Math.floor(publisherFeePercent > 0 ? Math.max(receivedAmount * publisherFeePercent, 1) : 0);
return {
steamFee,
publisherFee,
totalFees: steamFee + publisherFee,
amountToSellAt: receivedAmount + steamFee + publisherFee
}
}
var iterations = 0;
var estimateReceived = parseInt((sellPrice - steamFeeBase) / (steamFeePercent + publisherFeePercent + 1));
var fees = calculateFees(estimateReceived);
var everUndershot = false;
// Precision calculation due to Math.floor
while (fees.amountToSellAt != sellPrice && iterations < 10) {
if (fees.amountToSellAt > sellPrice) {
if (everUndershot) {
fees = calculateFees(estimateReceived - 1);
fees.steamFee += (amount - fees.amountSoldAt);
fees.totalFees += (amount - fees.amountSoldAt);
fees.amountSoldAt = amount;
break;
} else {
estimateReceived--;
}
} else {
everUndershot = true;
estimateReceived++;
}
fees = calculateFees(estimateReceived);
iterations++;
}
// Ignore how ugly this looks
console.log(`From ${(sellPrice / 100).toFixed(2)} you get ${((sellPrice - fees.totalFees) / 100).toFixed(2)}, to get ${(sellPrice / 100).toFixed(2)} sell at ${(calculateFees(sellPrice).amountToSellAt / 100).toFixed(2)}`)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment