Jump to content
McKay Development

Recommended Posts

Posted (edited)
manager.on("sentOfferChanged", (offer, oldstate) => {
  let oldState = TradeOfferManager.ETradeOfferState[oldstate];
  let currentState = TradeOfferManager.ETradeOfferState[offer.state];
  //console.log(offer.partner.getSteamID64());
  console.log(
    green,
    `Sent offer state changed from ${oldState} to ${currentState}`
  )};

Output:

Sent offer state changed from CreatedNeedsConfirmation to InvalidItems
Sent offer state changed from CreatedNeedsConfirmation to InvalidItems
Sent offer state changed from CreatedNeedsConfirmation to Accepted

So basically, I sent 2 trades from my BOT Account to 2 different accounts. The problem is both the trades changed their current State to InvalidItems when one of the offers was accepted and then later on that trade was confirmed. Why did both the trades emit InvalidItems? I am not able to replicate this issue again. Is this common? and is there any way to avoid this? Thanks

 

Edited by sludgefudge
Posted

Steam is Steam and Steam sucks. It happens sometimes and you should probably either delay a little while before marking a trade as definitively closed, or otherwise allow for reopening trades in whatever system or database you're using if the offer should become Accepted.

Posted (edited)
On 1/23/2022 at 9:14 AM, Dr. McKay said:

Steam is Steam and Steam sucks. It happens sometimes and you should probably either delay a little while before marking a trade as definitively closed, or otherwise allow for reopening trades in whatever system or database you're using if the offer should become Accepted.

What would be the best way to confirm a trade has 100% completed if there is no margin for error? 

Edited by sludgefudge
Posted

I've never seen a trade offer go from Accepted to some other state and actually mean that the trade didn't go through. Once it goes to Accepted you're pretty safe to say that it's completed.

It used to be possible for trades to go to InvalidItems after Accepted, but the trade had still gone through. I don't think that's possible anymore though.

Posted (edited)
On 1/28/2022 at 4:57 PM, Dr. McKay said:

I should mention, if you want to be absolutely sure that a trade completed (and hasn't been rolled back), you should take the tradeID property from the trade offer and plug it into GetTradeStatus. The values for the status property are documented here in ETradeStatus.

Or just use getExchangeDetails.

    let buyOffertf2 = 0;
    for (let i = 0; i < offer.itemsToReceive.length; i++) {
      if (
        offer.itemsToReceive[i]["market_hash_name"] ===
        "Mann Co. Supply Crate Key"
      ) {
        buyOffertf2++;
      } else {
        client.chat.sendFriendMessage(
          offer.partner,
          `I have to cancel your trade offer because it has unsupported items (${offer.itemsToReceive[i]["market_hash_name"]}). I currently only accept 'Mann Co. Supply Crate Key'`
        );
        offer.cancel((err) => {
          if (err != null) {
            console.log(
              red,
              `${time} Error in cancelling invalid item trade offer. Offer id: ${offer.id}`
            );
          }
        });
        break;
      }
    }

if (buyOffertf2 === offer.itemsToReceive.length) {
      mongo.users.findOne(
        { steamid: offer.partner.getSteamID64() },
        (err, data) => {
          if (err) {
            console.log(red, `${time} MongoDB buy offer user find error`);
          } else {
            if (data == null) {
              client.chat.sendFriendMessage(
                offer.partner,
                `You have not yet added me and I cannot accept your offer. Please add me before a trade. I have cancelled your offer.`
              );
            } else {
              client.chat.sendFriendTyping(offer.partner);
              client.chat.sendFriendMessage(
                offer.partner,
                `Please wait while I process your order`
              );
              offer.accept((err, status) => {
                client.chat.sendFriendTyping(offer.partner);
                client.chat.sendFriendMessage(
                  offer.partner,
                  `I have accepted your offer. Steam usually transfers items during this time. Please be patient while the trade is complete.`
                );

                if (err) {
                  client.chat.sendFriendTyping(offer.partner);
                  client.chat.sendFriendMessage(
                    offer.partner,
                    `There was an error while accepting your offer`
                  );
                } else {
                  switch (status) {
                    case "accepted":
                      offer.getExchangeDetails(
                        (
                          err,
                          status,
                          tradeInitTime,
                          receivedItems,
                          sentItems
                        ) => {
                          if (err) {
                            console.log(
                              red,
                              `${time} Trade has failed. Status: ${status}`
                            );
                          } else if (status === 3) {
                            let acceptOfferTf2Qty = 0;
                            for (let i = 0; i < receivedItems.length; i++) {
                              if (
                                receivedItems[i]["market_hash_name"] ===
                                "Mann Co. Supply Crate Key"
                              ) {
                                acceptOfferTf2Qty++;
                              }
                            }
                            if (acceptOfferTf2Qty === buyOffertf2) {
                              let buyOfferTf2CostUSD =
                                pricing.buy * acceptOfferTf2Qty;
                              let buyOfferTf2CostBTC =
                                getBTC(buyOfferTf2CostUSD);

                              mongo.users.findOne(
                                { steamid: offer.partner.getSteamID64() },
                                (err, data) => {
                                  if (err) {
                                    console.log(
                                      red,
                                      `${time} Error finding user in MongoDB`
                                    );
                                  } else {
                                    const updatedBTC = parseFloat(
                                      bigDecimal.add(
                                        data["btcbalance"],
                                        buyOfferTf2CostBTC
                                      )
                                    );
                                    mongo.users.findOneAndUpdate(
                                      {
                                        steamid: offer.partner.getSteamID64(),
                                      },
                                      { btcbalance: updatedBTC },
                                      { new: true },
                                      (err, data) => {
                                        if (err) {
                                          console.log(
                                            red,
                                            `${time} Error in writing btc balance to mongoDB.`
                                          );
                                        } else {
                                          client.chat.sendFriendMessage(
                                            offer.partner,
                                            `I have added ${buyOfferTf2CostBTC} BTC ($${buyOfferTf2CostUSD}) to your bitcoin balance at the current bitcoin price of $${usdbtc}. Your updated bitcoin balance is ${data["btcbalance"]}\n\nPlease use the 'withdraw' command to withdraw your bitcoin balance.\n\nThank you for trading with me. If you enjoyed my service please comment a +rep on my profile. `
                                          );
                                        }
                                      }
                                    );
                                  }
                                }
                              );
                            }
                          } else {
                            console.log(
                              red,
                              `${time} Status is not Confirmed. Balance has not been added. Status: ${status}`
                            );
                          }
                        }
                      );
                  }
                }
              });
            }
          }
        }
      );
    }

Sorry for this huge code with only small parts of your modules. But if you can confirm if the way in which I've handled this trade can there be a chance for error? Thank you for your help 

Edited by sludgefudge

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...