trade

package
v3.0.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 14, 2023 License: BSD-3-Clause Imports: 5 Imported by: 0

Documentation

Overview

Allows automation of Steam Trading.

Usage

Like go-steam, this package is event-based. Call Poll() until the trade has ended, that is until the TradeEndedEvent is emitted.

// After receiving the steam.TradeSessionStartEvent
t := trade.New(sessionIdCookie, steamLoginCookie, steamLoginSecure, event.Other)
for {
	eventList, err := t.Poll()
	if err != nil {
		// error handling here
		continue
	}
	for _, event := range eventList {
		switch e := event.(type) {
			case *trade.ChatEvent:
				// respond to any chat message
				t.Chat("Trading is awesome!")
			case *trade.TradeEndedEvent:
				return
			// other event handlers here
		}
	}
}

You can either log into steamcommunity.com and use the values of the `sessionId` and `steamLogin` cookies, or use go-steam and after logging in with client.Web.LogOn() and receiving the WebLoggedOnEvent use the `SessionId` and `SteamLogin` fields of steam.Web for the respective cookies.

It is important that there is no delay between the Poll() calls greater than the timeout of the Steam client (currently five seconds before the trade partner sees a warning) or the trade will be closed automatically by Steam.

Notes

All method calls to Steam APIs are blocking. This packages' and its subpackages' types are not thread-safe and no calls to any method of the same trade instance may be done concurrently except when otherwise noted.

Index

Constants

View Source
const (
	TradeEndReason_Complete  TradeEndReason = 1
	TradeEndReason_Cancelled                = 2
	TradeEndReason_Timeout                  = 3
	TradeEndReason_Failed                   = 4
)

Variables

This section is empty.

Functions

This section is empty.

Types

type ChatEvent

type ChatEvent struct {
	Message string
}

type Currency

type Currency struct {
	AppId      uint32
	ContextId  uint64
	CurrencyId uint64
}

type Item

type Item struct {
	AppId     uint32
	ContextId uint64
	AssetId   uint64
}

type ItemAddedEvent

type ItemAddedEvent struct {
	Item *Item
}

type ItemRemovedEvent

type ItemRemovedEvent struct {
	Item *Item
}

type ReadyEvent

type ReadyEvent struct{}

type SetCurrencyEvent

type SetCurrencyEvent struct {
	Currency  *Currency
	OldAmount uint64
	NewAmount uint64
}

type Slot

type Slot uint

type Trade

type Trade struct {
	ThemId steamid.SteamId

	MeReady, ThemReady bool
	// contains filtered or unexported fields
}

func New

func New(sessionId, steamLogin, steamLoginSecure string, other steamid.SteamId) *Trade

func (*Trade) AddItem

func (t *Trade) AddItem(slot Slot, item *Item) error

func (*Trade) Cancel

func (t *Trade) Cancel() error

func (*Trade) Chat

func (t *Trade) Chat(message string) error

func (*Trade) Confirm

func (t *Trade) Confirm() error

This may only be called after a successful `SetReady(true)`.

func (*Trade) Events

func (t *Trade) Events() []interface{}

Returns all queued events and removes them from the queue without performing a HTTP request, like Poll() would.

func (*Trade) GetMain

func (t *Trade) GetMain() (*tradeapi.Main, error)

func (*Trade) GetOwnInventory

func (t *Trade) GetOwnInventory(contextId uint64, appId uint32) (*inventory.Inventory, error)

func (*Trade) GetTheirInventory

func (t *Trade) GetTheirInventory(contextId uint64, appId uint32) (*inventory.Inventory, error)

func (*Trade) Poll

func (t *Trade) Poll() ([]interface{}, error)

Returns the next batch of events to process. These can be queued from calls to methods like `AddItem` or, if there are no queued events, from a new HTTP request to Steam's API (blocking!). If the latter is the case, this method may also sleep before the request to conform to the polling interval of the official Steam client.

func (*Trade) RemoveItem

func (t *Trade) RemoveItem(slot Slot, item *Item) error

func (*Trade) SetCurrency

func (t *Trade) SetCurrency(amount uint, currency *Currency) error

func (*Trade) SetReady

func (t *Trade) SetReady(ready bool) error

func (*Trade) Version

func (t *Trade) Version() uint

type TradeEndReason

type TradeEndReason uint

type TradeEndedEvent

type TradeEndedEvent struct {
	Reason TradeEndReason
}

type UnreadyEvent

type UnreadyEvent struct{}

Directories

Path Synopsis
Wrapper around the HTTP trading API for type safety 'n' stuff.
Wrapper around the HTTP trading API for type safety 'n' stuff.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL