trade

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 25, 2020 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

This section is empty.

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 EndEvent

type EndEvent struct {
	Reason EndReason
}

type EndReason

type EndReason uint
const (
	EndReasonComplete EndReason = iota + 1
	EndReasonCanceled
	EndReasonTimeout
	EndReasonFailed
)

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   bool
	ThemReady bool
	// contains filtered or unexported fields
}

func New

func New(sessionID, steamLogin, steamLoginSecure string, other steamid.SteamID) (*Trade, error)

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

Confirm 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() (*api.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)

Poll 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 UnreadyEvent

type UnreadyEvent struct{}

Directories

Path Synopsis
Package api implements a trading API client.
Package api implements a trading API client.
Implements methods to interact with the official Trade Offer API.
Implements methods to interact with the official Trade Offer API.

Jump to

Keyboard shortcuts

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