Skip to content

TradeOfferManager

Alexander Corn edited this page Dec 23, 2015 · 63 revisions

TradeOfferManager is the root object that node-steam-tradeoffer-manager exports. You'll need to instantiate it.

Example

// Steam integration is optional and is only used for instant polling
// === FOR node-steam 0.6.x ===
var Steam = require('steam');
var client = new Steam.SteamClient();
// === END FOR node-steam 0.6.x ===

// === FOR node-steam 1.0.x AND Steam.SteamUser ===
var Steam = require('steam');
var connection = new Steam.SteamClient();
var client = new Steam.SteamUser(connection);
// === END FOR node-steam 1.0.x AND Steam.SteamUser ===

// === FOR node-steam-user ===
var SteamUser = require('steam-user');
var client = new SteamUser();
// === END FOR node-steam-user ===

var TradeOfferManager = require('steam-tradeoffer-manager');
var manager = new TradeOfferManager({
    "steam": client,
    "domain": "doctormckay.com",
    "language": "en"
});

EResult

Some errors include an eresult property on their Error object. As of v1.1.0, you can compare this to TradeOfferManager.EResult (that's a static property available from the root export of the module, not from an instantiated manager). You can also call TradeOfferManager.EResult.getName(result) to get the English name for an EResult.

Constructor([options])

  • options - Optional. An object containing any or all of the following options:
    • steam - Optional. See Steam Integration below.
    • domain - Optional. Your domain name, if you have one. Used to register a Steam Web API key. Defaults to localhost.
    • language - Optional. Specify a language code if you want item descriptions. Must be a 2-character language code like en or es.
    • pollInterval - Optional. The time, in milliseconds, between polls. If -1, timed polling is disabled. Minimum 1000, default 30000 (30 seconds).
    • cancelTime - Optional. The time, in milliseconds, that a sent offer can remain Active until it's automatically canceled by the manager. This feature is disabled if omitted. Note that this check is performed on polling, so it will only work as expected if timed polling is enabled. Also note that because polling is on a timer, offers will be canceled between cancelTime and cancelTime + pollInterval milliseconds after being created, assuming Steam is up.
    • pendingCancelTime - Optional. The time, in milliseconds, that a sent offer can remain CreatedNeedsConfirmation until it's automatically canceled by the manager. This feature is disabled if omitted. All documentation for cancelTime applies.
    • cancelOfferCount - Optional. Once we have this many outgoing Active offers, the oldest will be automatically canceled.
    • cancelOfferCountMinAge - Optional. If you're using cancelOfferCount, then offers must be at least this many milliseconds old in order to qualify for automatic cancellation.

Steam Integration

node-steam-tradeoffer-manager can integrate with a Steam client instance. To do this, pass a supported Steam client to the constructor as the steam property. There are a few options here.

If provided, node-steam-tradeoffer-manager will be able to get trade offer feedback more quickly. The manager will automatically do a trade offer poll when it receives a notification from Steam of active incoming trade offers.

If using node-steam-user, the manager will also poll when Steam sends a notification of new items (for receivedOfferChanged or sentOfferChanged to be emitted more quickly when an offer is accepted).

Properties

pollInterval

v1.6.0 or later is required to use this property.

The interval, in milliseconds, at which the manager will poll Steam for trade offer info. You can change this at any time, although the change will only take effect after the next poll. This value is initially set in the constructor.

Set to -1 to disable timed polling. Minimum is 1000 ms.

cancelTime

v1.6.0 or later is required to use this property.

The time, in milliseconds, after which the manager will automatically cancel outgoing offers if they're not acted on. You can change this at any time. This value is initially set in the constructor.

Set to null to disable.

pendingCancelTime

v1.14.0 or later is required to use this property.

The time, in milliseconds, after which the manager will automatically cancel outgoing CreatedNeedsConfirmation offers if they're not acted on. You can change this at any time. This value is initially set in the constructor.

Set to null to disable.

cancelOfferCount

v1.16.0 or later is required to use this property.

Once we have this many outgoing Active offers, the oldest will be automatically canceled. You can change this at any time. This value is initially set in the constructor.

Set to null to disable.

cancelOfferCountMinAge

v1.16.0 or later is required to use this property.

If you're using cancelOfferCount, then offers must be at least this many milliseconds old in order to qualify for automatic cancellation. This value is initially set in the constructor.

Set to 0 to disable.

pollData

Set this to the most recent object received in the pollData event on startup to gracefully resume polling.

apiKey

A read-only property containing your account's API key once the callback of setCookies fires for the first time.

steamID

v1.6.0 or later is required to use this property.

A SteamID object containing the SteamID of the account we're logged in as. null until the first call to setCookies.

Methods

setCookies(cookies[, callback])

  • cookies - An array of cookies in name=value form. This is the format used by both node-steam and node-steamcommunity, so either module can be used to get cookies.
  • callback - Optional. Will be called once the API key is retrieved and the module is ready for use. The first argument will be null on success or an Error object on failure. You'll get an Access Denied error if your account is limited.

Sets node-steam-tradeoffer-manager's internal cookie buffer and retrieves your API key, registering one if needed. Therefore, usage of this module constitutes agreement to the Steam Web API terms.

shutdown()

v1.7.0 or later is required to use this method.

Stops polling, removes the Steam client reference, and clears cookies. Suitable for use if you want to log out of your bot's account but not terminate the process.

parentalUnlock(pin[, callback])

  • pin - Your 4-digit PIN code
  • callback - Optional. Called on completion with a single argument which is null on success or an Error object on failure. Error is Incorrect PIN if your PIN was wrong.

If your account has Family View enabled, you'll need to call this right after each setCookies call to unlock the session for trading. You don't need to wait for the setCookies callback to call this.

createOffer(partner)

  • partner - Either a SteamID object or something which can parse into one (STEAM_0:0:23071901, [U:1:46143802], 76561198006409530).

Creates a new empty TradeOffer and returns it to you.

getOffer(id, callback)

  • id - The ID of the trade offer, as a string or number
  • callback - You'll receive the TradeOffer object in this callback.
    • err - null on success, or an Error object on failure
    • offer - A TradeOffer object for the requested offer

Gets a TradeOffer object for a specific offer ID. As of v1.1.0, on failure, the err object may contain an eresult property.

getOffers(filter,[historicalCutoff,] callback)

  • filter - Required. A value from EOfferFilter
  • historicalCutoff - Optional. If filter is ActiveOnly and this is a Date object in the past, then offers which are either active or have a modification date after this date will be returned. Omit or pass null if filter is not ActiveOnly or if you only wish to get offers in Active state.
  • callback - Required.
    • err - null on success, or an Error object on failure
    • sent - An array of TradeOffer objects for offers sent by you matching the filter.
    • received - An array of TradeOffer objects for offers received by you matching the filter.

Retrieves a list of trade offers matching specific criteria. As of v1.1.0, on failure, the err object may contain an eresult property.

loadInventory(appid, contextid, tradableOnly, callback)

  • appid - The Steam App ID of the game for which you want to load your inventory
  • contextid - The ID of the context within the app that you're loading the inventory for
  • tradableOnly - true to only include tradable items, false to include all
  • callback - Invoked when data is ready
    • err - null on success, or an Error object on failure
    • inventory - An array of the user's inventory items, as EconItem objects
    • currencies - An array of the user's currency items, as EconItem objects

Retrieves the contents of your own inventory for a specific game and context.

getOfferToken(callback)

  • callback - Called when requested data is available.
    • err - An Error object on failure, null on success
    • token - Your account's trade offer token, as a string

Retrieves the token part of your account's trade URL.

getEscrowDuration(steamID[, token], callback)

  • steamID - The SteamID of the person whose escrow duration you want to know, as a SteamID object or a string which can parse into one
  • token - Optional. Required only if you are not friends with the user.
  • callback - Called when requested data is available.
    • err - An Error object on failure, null on success
    • daysTheirEscrow - If the other person will be losing items in a trade, then the trade will be held for up to this many days
    • daysYourEscrow - If you will be losing items in a trade, then the trade will be held for up to this many days

v1.12.0 or later is required to use this method

Loads the trade offer UI page and pulls the number of days for which a trade would be held from the JavaScript. If daysYourEscrow is 0, then a trade will not be held if only you are losing items. If daysTheirEscrow is 0, then a trade will not be held if only they are losing items. If both are 0, then anyone can lose items without the trade being held.

If you cannot trade with the other party, then the error message from Steam will be presented as an Error object in the err argument. Examples include trade bans, new-device cooldowns, and invalid offer tokens.

If you read carefully, you'd notice that this method can also be used to validate the authenticity of an offer token.

doPoll()

Immediately performs a poll. Can be used even if timed polling is disabled to poll on your own schedule. Don't worry about spamming this method, node-steam-tradeoffer-manager will automatically limit polls to at most one per second.

Events

newOffer

  • offer - A TradeOffer object for the newly-received offer

Emitted when polling detects a new trade offer sent to us. Only emitted if polling is enabled.

sentOfferChanged

Emitted when an offer we sent changes state. This might mean that it was accepted/declined by the other party, that we cancelled it, or that we confirmed a pending offer via email. Only emitted if polling is enabled.

sentOfferCanceled

  • offer - A TradeOffer object for the canceled offer
  • reason - A string containing the reason why it was canceled
    • cancelTime - The cancelTime timeout was reached
    • cancelOfferCount - The cancelOfferCount limit was reached

v1.0.0 or later is required to use this event. v1.16.0 or later is required to use the reason argument.

Emitted when the manager automatically cancels an offer due to either your cancelTime constructor option or your cancelOfferCount constructor option. sentOfferChanged will also be emitted on next poll.

sentPendingOfferCanceled

  • offer - A TradeOffer object for the canceled offer

v1.14.0 or later is required to use this event

Emitted when the manager automatically cancels an offer due to your pendingCancelTime constructor option. sentOfferChanged will also be emitted on next poll.

unknownOfferSent

  • offer - A TradeOffer object for the offer that was sent

v1.10.0 or later is required to use this event

Emitted when the manager finds a trade offer that was sent by us, but that wasn't sent via node-steam-tradeoffer-manager (i.e. it's not in the poll data, so this will emit for all sent offers on every startup if you don't restore poll data).

You could use this to cancel offers that error when you call send() but actually go through later, because of how awful Steam is.

receivedOfferChanged

Emitted when an offer we received changes state. This might mean that it was cancelled by the other party, or that we accepted/declined it. Only emitted if polling is enabled.

pollFailure

  • err - An Error object

v0.1.7 or later is required to use this event

Emitted when there's a problem polling the API. You can use this to alert users that Steam is currently down or acting up, if you wish.

pollSuccess

v1.8.5 or later is required to use this event

Emitted when a poll succeeds.

pollData

  • pollData - The new poll data

Emitted when new poll data is available. See the Polling page for more information.

Clone this wiki locally