Jump to content
McKay Development

Recommended Posts

Posted

Hello. I'm starting to use this project to automate some trading. I'm using this example: https://github.com/DoctorMcKay/node-steam-tradeoffer-manager/blob/master/examples/storehouse-steam.js

I added useAccessToken in the construct to retrieve CS2 trade offers. 15 days ago disabled and re-enabled my 2-factor authenticator to retrieve my shared_secret and identity_secret with the examples found in node-steamcommunity. I have my mobile authenticator back on my phone, btw. 

I'm able to log in and see my incoming offers with the trade offer manager and it works accepting 'gift' offers (empty on my side). However, when confirming the trade offers where I'm giving away an item, I get 'Invalid Authenticator'.

I noticed a few things, so maybe something went wrong along the way.

  • When I'm logging in, I need to copy-paste my Steam Guard Code to log in, even though I have the twoFactorCode option there.
  • The generated SteamTotp.getAuthCode(sharedSecret) is different from what I see in my authenticator. 

I tried playing with time offsets, either by adding 1, -1, or leaving it at 0. SteamTotp.getTimeOffset usually retrieves a 0. 

I'm on MacOS if that matters.

Posted
On 1/12/2025 at 9:26 AM, iulian said:
  • The generated SteamTotp.getAuthCode(sharedSecret) is different from what I see in my authenticator. 

Either your secret is wrong or your clock is wrong. If getTimeOffset returns 0, that means that your secret is wrong.

Posted

I figured that one out, I had to do some digging but it looks like shared secrets are generated when setting up the mobile authenticator. 

On a separate note, I'm using the script to accept gift offers, which works fine. But, after about 24 hours, it seems like the script is not responding or getting any new steam notifications. I have a feeling that the session isn't kept alive properly. I experienced something similar with SIH on Chrome when I was keeping a Steam tab open for long periods of time. Is there a way of solving this issue besides trying to re-login?

  • 3 weeks later...
Posted

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) => {
				//...
            })				
		}
	);
}

 

Posted

The callback to getOffers has three argument, not two. It's (err, sent, received)

Your code as written is only looking at sent offers, so it's expected you wouldn't see your received offers in there.

I also see some other issues in your code. Firstly, you're creating a new 30-second interval on checkTrades every time webSession is emitted, so after two webSession events you're calling checkTrades twice every 30 seconds, thrice after 3 emits, and so on. This is in addition to TradeOfferManager's internal 30 second polling that you've enabled via pollInterval: 30000.

I'd recommend that you eliminate your checkTrades function entirely and instead use the offerList event, which is designed for exactly what you're using checkTrades for now. It'll be emitted every time TradeOfferManager performs a poll, which is every 30 seconds as configured here.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...