I'm running a bot and the majority of trade offers are not going through. The bot logs in and handles expired sessions like this:
let client = new SteamUser();
let community = new SteamCommunity();
let manager = new TradeOfferManager({
community: community,
steam: client,
domain: "example.com",
language: "en",
pollInterval: 2000
});
let logOnOptions = {
"accountName": data.username,
"password": data.password,
"twoFactorCode": SteamTotp.getAuthCode(data.shared_secret)
};
client.logOn(logOnOptions);
client.on('loggedOn', function() {
console.log("Logged into Steam");
client.setPersona(SteamUser.EPersonaState.Online);
});
client.on('webSession', function(sessionID, cookies) {
manager.setCookies(cookies);
community.setCookies(cookies);
console.log("weblogon")
});
community.on("sessionExpired", function(err) {
console.log("## Session Expired");
client.webLogOn();
});
The bot gets new offers with
manager.on('newOffer', function(offer) {
, makes a simple request using https://www.npmjs.com/package/request and calls offer.getUserDetails. An offer is accepted like this:
offer.accept(accept(offer, 1));
These are the two functions that handle accepting and confirming trades:
function confirm(offer, count) {
return function(err) {
if (err) {
if (count < 20) {
console.log(err);
setTimeout(community.acceptConfirmationForObject, 10000, data.identity_secret, offer.id, confirm(offer, count + 1));
} else {
console.error("CONFIRM FUNCTION: ");
console.error(err);
}
}
}
}
function accept(offer, count) {
return function(err, status) {
if (err) {
if (count < 20) {
console.log(err);
setTimeout(offer.accept, 10000, accept(offer, count + 1));
} else {
console.error("ACCEPT FUNCTION: ");
console.error(err);
}
} else {
if (status === "pending") {
community.acceptConfirmationForObject(data.identity_secret, offer.id, confirm(offer, 1));
}
}
}
}
Whenever I run the code it works for a few hours accepting offers and confirming them. Then offer comes in and the sessionExpired and webSession events are emitted twice. Error: Cannot accept an unsent offer happens every time it tries to accept the offer. This from stdout (it also logs the timestamp):
16:31:23
Error: Not Logged In
at SteamCommunity._checkCommunityError (/home/user/bot/node_modules/steamcommunity/components/http.js:128:9)
at Request._callback (/home/user/bot/node_modules/steamcommunity/components/http.js:51:88)
at Request.self.callback (/home/user/bot/node_modules/request/request.js:185:22)
at emitTwo (events.js:126:13)
at Request.emit (events.js:214:7)
at Request.<anonymous> (/home/user/bot/node_modules/request/request.js:1161:10)
at emitOne (events.js:116:13)
at Request.emit (events.js:211:7)
at Gunzip.<anonymous> (/home/user/bot/node_modules/request/request.js:1083:12)
at Object.onceWrapper (events.js:313:30)
16:31:23
## Session Expired
16:31:23
## Session Expired
16:31:23
Error: Not Logged In
at SteamCommunity.manager._community.httpRequestPost (/home/user/bot/node_modules/steam-tradeoffer-manager/lib/classes/TradeOffer.js:483:25)
at Request._callback (/home/user/bot/node_modules/steamcommunity/components/http.js:67:15)
at Request.self.callback (/home/user/bot/node_modules/request/request.js:185:22)
at emitTwo (events.js:126:13)
at Request.emit (events.js:214:7)
at Request.<anonymous> (/home/user/bot/node_modules/request/request.js:1161:10)
at emitOne (events.js:116:13)
at Request.emit (events.js:211:7)
at IncomingMessage.<anonymous> (/home/user/bot/node_modules/request/request.js:1083:12)
at Object.onceWrapper (events.js:313:30)
16:31:23
weblogon
16:31:24
weblogon
16:31:33
Error: Cannot accept an unsent offer
at Timeout.TradeOffer.accept [as _onTimeout] (/home/user/bot/node_modules/steam-tradeoffer-manager/lib/classes/TradeOffer.js:451:23)
at ontimeout (timers.js:502:15)
at tryOnTimeout (timers.js:323:5)
at Timer.listOnTimeout (timers.js:290:5)
16:31:43
Error: Cannot accept an unsent offer
at Timeout.TradeOffer.accept [as _onTimeout] (/home/user/bot/node_modules/steam-tradeoffer-manager/lib/classes/TradeOffer.js:451:23)
at ontimeout (timers.js:502:15)
at tryOnTimeout (timers.js:323:5)
at Timer.listOnTimeout (timers.js:290:5)
... etc
What am I doing wrong?