Hi again. 15 days have passed and I can confirm trades using the trade manager. Thank you!
However, I noticed a bug, or maybe I'm doing something wrong. If I get a new offer when the script is working, I can immediately see it on the newer event, and I can immediately accept it. I can't accept the trade afterward if I don't act on this event. I've tried to use a setInterval and check manager.getOffers, but the detected offer is not on the list. Even if I directly call manager.getOffer(offerId), I get undefined. Even if I restart the script, I can't find the offer, which I can see on Steam's trade offer web page.
// just some sample code to reproduce the issue
let client = new SteamUser();
let manager = new TradeOfferManager({
steam: client, // Polling every 30 seconds is fine since we get notifications from Steam
language: "en", // We want English item descriptions
pollInterval: 30000,
useAccessToken: true,
});
let community = new SteamCommunity();
async function main() {
let logOnOptions = {
accountName,
password,
twoFactorCode: SteamTotp.getAuthCode(sharedSecret), // shared secret
};
if (FS.existsSync("polldata.json")) {
manager.pollData = JSON.parse(
FS.readFileSync("polldata.json").toString("utf8")
);
}
client.logOn(logOnOptions);
}
manager.on("pollData", function (pollData) {
FS.writeFileSync("polldata.json", JSON.stringify(pollData));
});
client.on("webSession", function (sessionID, cookies) {
manager.setCookies(cookies, function (err) {
if (err) {
console.log(err);
process.exit(1);
}
console.log("Cookies set");
});
community.setCookies(cookies);
setInterval(checkTrades, 1 * 30 * 1000);
});
manager.on("newOffer", function (offer) {
console.log(
"New offer #" +
offer.id +
" from " +
offer.partner.getSteam3RenderedID()
);
// i can accept the offer here if I wish
});
function checkTrades() {
console.log("Checking for trade offers...");
manager.getOffers(
TradeOfferManager.EOfferFilter.All,
null,
(err, offers) => {
if (err) {
console.error("Error fetching trade offers:", err);
return;
}
// offers doesn't include the offer id i saw in the newOffer event
// filtering getOffers with ActiveOnly results in an empty array
// manager.getOffer(offerId) is undefined
offers.forEach((offer) => {
//...
})
}
);
}