# steam-interaction

> ```ts const cookie = { steamRefresh_steam: '', steamLoginSecure: `76561199035699070%7C%7CeyAidHlwIjogIkpXVCIsICJhbGciOiAiRWREU0EiIH0.eyAiaXNzIjogInI6MERENl8yM0FCQ0U5Rl80QUEwMyIsICJzdWIiOiAiNzY1NjExOTkwMzU2OTkwNzAiLCA

Latest version **1.0.0** (published 2024-02-20) · ISC license · 0 weekly downloads

## Install

```sh
npm install steam-interaction
pnpm add steam-interaction
yarn add steam-interaction
bun add steam-interaction
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2024-02-20 |
| First published | 2024-02-20 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 29 |
| Unpacked size | 284.3 KB |
| Known vulnerabilities | 0 (+2 in 2 direct dependencies) |
| Install scripts | no |
| Maintainers | kyrylchenko |

## Links

- npm: https://www.npmjs.com/package/steam-interaction
- npm.io page: https://npm.io/package/steam-interaction

## Dependencies (29)

- [axios](https://npm.io/package/axios.md) ^1.5.0
- [cherio](https://npm.io/package/cherio.md) ^1.0.0-rc.2
- [cookie](https://npm.io/package/cookie.md) ^0.6.0
- [crypto](https://npm.io/package/crypto.md) ^1.0.1
- [cheerio](https://npm.io/package/cheerio.md) ^1.0.0-rc.12
- [guid-ts](https://npm.io/package/guid-ts.md) ^1.1.2
- [request](https://npm.io/package/request.md) ^2.88.2
- [steamid](https://npm.io/package/steamid.md) ^2.0.0
- [winston](https://npm.io/package/winston.md) ^3.11.0
- [polydata](https://npm.io/package/polydata.md) file:../../polyData
- [inversify](https://npm.io/package/inversify.md) ^6.0.1
- [node-forge](https://npm.io/package/node-forge.md) ^1.3.1
- [steam-totp](https://npm.io/package/steam-totp.md) ^2.1.2
- [steam-user](https://npm.io/package/steam-user.md) ^5.0.0
- [typescript](https://npm.io/package/typescript.md) ^5.1.6
- [@types/axios](https://npm.io/package/@types/axios.md) ^0.14.0
- [steam-session](https://npm.io/package/steam-session.md) ^1.4.1
- [@types/cheerio](https://npm.io/package/@types/cheerio.md) ^0.22.32
- [@types/request](https://npm.io/package/@types/request.md) ^2.48.8
- [node-bignumber](https://npm.io/package/node-bignumber.md) ^1.2.2
- [@types/node-rsa](https://npm.io/package/@types/node-rsa.md) ^1.1.4
- [@automapper/core](https://npm.io/package/@automapper/core.md) ^8.7.7
- [account-contract](https://npm.io/package/account-contract.md) file:../account-contract
- [chai-as-promised](https://npm.io/package/chai-as-promised.md) ^7.1.1
- [reflect-metadata](https://npm.io/package/reflect-metadata.md) ^0.1.13
- [@types/steam-user](https://npm.io/package/@types/steam-user.md) ^4.26.4
- [socks-proxy-agent](https://npm.io/package/socks-proxy-agent.md) ^8.0.2
- [@automapper/classes](https://npm.io/package/@automapper/classes.md) ^8.7.7
- [@types/steam-tradeoffer-manager](https://npm.io/package/@types/steam-tradeoffer-manager.md) ^2.10.4

## Recent versions

- 1.0.0 (latest) — 2024-02-20

## README

# Cookies Example

```ts
  const cookie = {
        steamRefresh_steam:         '',
        steamLoginSecure:           `76561199035699070%7C%7CeyAidHlwIjogIkpXVCIsICJhbGciOiAiRWREU0EiIH0.eyAiaXNzIjogInI6MERENl8yM0FCQ0U5Rl80QUEwMyIsICJzdWIiOiAiNzY1NjExOTkwMzU2OTkwNzAiLCAiYXVkIjogWyAid2ViIiBdLCAiZXhwIjogMTcwNDY3MDU1MiwgIm5iZiI6IDE2OTU5NDI4MjIsICJpYXQiOiAxNzA0NTgyODIyLCAianRpIjogIjBERDlfMjNBQkNFQTRfODNCNTkiLCAib2F0IjogMTcwNDU1NjE2MywgInJ0X2V4cCI6IDE3MjI5MzQyNjUsICJwZXIiOiAwLCAiaXBfc3ViamVjdCI6ICIxNjYuMS4yMzAuMjU0IiwgImlwX2NvbmZpcm1lciI6ICIxNjYuMS4yMzAuMjU0IiB9.qtwJQ35SmJrsJSh-CLeUcZdri0r_G_fyimag1Ho6attigdwreJndbpKFkNoyQzbeOjKXEFpPB5h7GUl8Eo5WCA`,
        sessionid:                  '22c0035bf55f53b4b01e4a1a',
        steamCountry:               '',
        steamDataId:                '',
        steamRememberLogin:         'True',
        Steam_Language:             'english',
        steamMachineAuth:           '',
        webTradeEligibility:        '%7B%22allowed%22%3A0%2C%22reason%22%3A16416%2C%22allowed_at_time%22%3A1697620832%2C%22steamguard_required_days%22%3A15%2C%22new_device_cooldown_days%22%3A0%2C%22expiration%22%3A1697016332%2C%22time_checked%22%3A1697016032%7D',
        timezoneOffset:             '10800,0'
    } as Cookie
```
# Credentials Example

```ts
  const accountCredentials = new AccountCredentials();
  accountCredentials.login = "Your steam login";
  accountCredentials.password = "Your steam password";
  accountCredentials.shared_secret = "Your steam shared secret";
  accountCredentials.identity_secret = "Your steam identity secret";
```


# Services


### Login Service

Login method

```ts
 

  const loginService: LoginService = new LoginService({
		timezone: "Your timezone (by default 7200,0)",
		steamLanguage: "Your steam language"
	},
		'Your proxy string (optional parameter)'
	);
  //This method return cookie, acceesToken, RefreshToken and steam sessionid
const res = await loginService.login(accountCredentials);  
```

### Web Login Service

Login via credentials method

```ts
 const credentials = new AccountCredentials();
  credentials.login = "Your steam login";
  credentials.password = "Your steam password";
  credentials.shared_secret = "Your steam shared secret";
  credentials.identity_secret = "Your steam identity secret";
const webLoginService: WebLoginService = new WebLoginService({
		timezone: "Your timezone (by default 7200,0)",
		steamLanguage: "Your steam language (by default 'english')"
	},
		'Your proxy string (optional parameter)'
  );

//This method return cookie, acceesToken, RefreshToken and steam sessionid
const loginResult = await webLoginService.logOnViaCredentials(credentials);

```
### BuyOrderService

Place buy order method

```ts
 
  const buyOrderService: BuyOrderService = new BuyOrderService(
		cookie, //Your Cookie object
		'Your steam sessionid',
		'Your proxy string (optional parameter)'
	);
  const order: Order = {
			currency: ECurrencyCode.RUB, //Enter your currency from ECurrencyCode enum
			appid: 'ID of the game to which the item belongs (such as 570)',
			market_hash_name: "Your market item name with spaces",
			price_total: 123, //Total of your order in format without comma (1,23 = 123)
			quantity: 1,  // Quantity of items
		};
  const res = await buyOrderService.placeBuyOrder(order);
```

Get Item Orders

```ts
const params = { nameId: "176321160", currency: ECurrencyCode.RUB, appId: 570, itemName: "Doll of the Dead" };
const res = await buyOrderService.getItemOrdersHistory(params);
```

Cancel Order 

```ts
const orderId = "6621500342";   //You can find this from getItemOrdersHistory or steam page
const res = await buyOrderService.cancelBuyOrder(orderId);
```

Get buy order status 

```ts
const orderId = "6621666187";  //You can find this from getItemOrdersHistory or steam page
const res = await buyOrderService.getBuyOrderStatus(orderId);
```


### ConfirmationService

Get all confirmations

```ts
const confirmationService: ConfirmationService = new ConfirmationService(
		cookie,
		{
			mobileOs: "android",    //Optional
			profileId64: '783758372894', //Your steam id 64
		},
		credentials.identity_secret,
		'Your proxy string (optional parameter)'
);
const confs: Confirmation[] = await confirmService.getConfirmations();

```

Respond to one confirmation

```ts
const res: boolean = await confirmService.respondToConfirmation(
				confs[0].id,                //Confirmation Id
				confs[0]?.nonce,            //One-time code to use confirmation 
				ConfirmationAction.Accept   //Accept or Decline
			);
```

Respond to all confirmation

```ts 
	 const res: boolean = await confirmService.respondToAllConfirmations(ConfirmationAction.Accept);
```

### CookieValidationService

```ts
 let cookieValidationService: CookieValidationService = new CookieValidationService(cookie, 'Your proxy string (optional parameter)');
await cookieValidationService.isCookieHaveValidSession()	//Check cookie valid session
```

### InventoryService

Get all inventory Test

```ts
let inventoryService: InventoryService = new InventoryService(cookie, 'Your proxy string (optional parameter)');
const params: GetInventoryParams = {
	appID: Apps.DOTA2,						// Game id (570 fro DOTA2)
	profileId64: "76561199035699070",		//Steam id 64 account you want to view inventory
};
const inventory: InventoryAssetItem[] = await inventoryService.getAllInventoryAssets(params.profileId64, params.appID);
```

### StoreService

```ts
const storeService: StoreService = new StoreService(cookie, 'Your steam sessionid', 'Your proxy string (optional parameter)');
const res = await storeService.redeemWalletCode("Your wallet code");
```

### TradeOfferService

Get All Trade offers (sended and received)

```ts
	const tradeOfferService: TradeOfferService = new TradeOfferService(
		{
			apiKey: 'Your steam API key',
			sessionId: 'Your steam sessionid',
		},
		cookie,
		'Your proxy string (optional parameter)'
	);
 const offers = await tradeOfferService.getOffers(EOfferFilter.All);
```

Get concrete offer information

```ts
	const offerID = "5489849179";	//You can get this info from getOffers method or watch from steam page
	const trade = await tradeOfferService.getOffer(offerID);
```

Create simple empty trade offer

```ts
const partnerSteamId64 = "76561199111873879"	//Your partner steam id 64		
const tradeUrlToken = "lyqEqgxg"				//You can find this token from partner trade url
const res = await tradeOfferService.createOffer(partnerSteamId64, tradeUrlToken);
```

Send new trade offer. This example shows how to create a new trade offer, 
add one item from your inventory and one item from your partner’s inventory to it, and send the offer

```ts
	const offer = await createSimpleTradeOffer(tradeOfferService);
	const response = await tradeOfferService.sendOffer(offer);

async function createSimpleTradeOffer(tradeOfferService: TradeOfferService): Promise<TradeOffer> {
	const partnerId = "76561199032664256";
	const tradeOffer = tradeOfferService.createOffer(partnerId, "lyqEqgxg");

	const myItem: InventoryAssetItem | null = await getFirstInventoryItem(TestConfig.steamId.getSteamID64());
	if (myItem) {
		tradeOffer.addMyItem(myItem);
	}

	const partnerItem: InventoryAssetItem | null = await getFirstInventoryItem(partnerId);
	if (partnerItem) {
		tradeOffer.addTheirItem(partnerItem);
	}

	tradeOffer.message = "This trade offer for you";
	return tradeOffer;
}
async function getFirstInventoryItem(profileId: string): Promise<InventoryAssetItem | null> {
	const inventoryService = new InventoryService(TestConfig.cookie, undefined);
	const inventoryParams: GetInventoryParams = {
		profileId64: profileId,
		appID: Apps.DOTA2,
		count: 1,
	};
	const inventory: GetInventoryResult | null = await inventoryService.getInventory(inventoryParams);
	if (!inventory?.assets) {
		return null;
	}
	return inventory?.assets[0];
}
```

Accept active trade offer

```ts
	const offers = await getOffers(tradeOfferService);
	//We finded one active trade offer from your steam account
	const activeOffer = offers?.receivedTradeOffers.find((x) => x.tradeOfferState == ETradeOfferState.Active);
	const res = await tradeOfferService.acceptOffer(activeOffer.tradeOfferId, activeOffer.partnerId64);
```

Decline trade offer 

```ts
const offers = await getOffers(tradeOfferService);
const activeOffer = offers?.sendedTradeOffers.find(
	(x) => x.tradeOfferState == ETradeOfferState.Active ||
	x.tradeOfferState == ETradeOfferState.CreatedNeedsConfirmation
);
const res: boolean = await tradeOfferService.cancelOffer(activeOffer.tradeOfferId);
```

### MarketService

Get price history example

```ts
const historyItem: PriceHistoryItem = {
	currency: ECurrencyCode.GBP,					
	appid: Apps.CSGO,
	itemName: "Antwerp 2022 Legends Sticker Capsule",
	encodedName: "",		//This parameter is optional, is your itemName but url encoded
};
const priceHistory = await marketService.getPriceHistory(historyItem);
```

Get Market history by page parameters

```ts
const historyPage: MarketHistoryPage = {
		page: 1,
		cntPerPage: 100,
	};
const marketHistory = await marketService.getMarketHistory(historyPage);
```

Get item info by game id and item name

```ts
const itemInfo = await marketService.getItemInfo(Apps.DOTA2, "Helm of Retribution");
```

Get my listings

```ts
  const params = {
			currentPage: 1,
			cntPerPage: 100,
			currency: ECurrencyCode.RUB,
		}
  const page = await marketService.getMyListings(params);
```

Get market listing by page

```ts
const params: ExtendedListingsPage = {
		marketItemName: "Mega-Kills: Cave Johnson",
		currency: ECurrencyCode.USD,
		cntPerPage: 100,	//Quantity elements on one page
		currentPage: 5,		//Current page number
		appId: 570,
	};
const page = await marketService.getMarketListings(params);
```

Sell item 

```ts
	const appId = Apps.DOTA2;
	const params: SellParams = {
		amount: 1,														//Quantity items
		contextid: ContextManager.getContextId(appId),					//Get information about your game id context (such as for 570 is context = 2)
		appid: appId,
		assetid: "28377029318",											//You can find assetid from getMarketListing method
		price: 100,														//price fro item without comma (100 = 1,00)
	};
	const res = await marketService.sell(params, '76561199032664256');	//Enter your steamId64
```

Buy item example

```ts

	const marketItemInfo: MarketItemInfo = {
		marketItemName: "Summer's Mirth",
		appId: 570
	}
	const listingId = "4376994758654887310";	//you can find this listing id from getMarketListing method or steam market item page
	const buyParams: BuyParams = {
		subtotal: 84,					//	price of the item itself
		fee: 12,						// 	steam commission for purchase
		total: 96,						// 	Your full price with fee+subtotal
		currency: ECurrencyCode.RUB,	//	Currency
		save_my_address: 0,				//	Is optional parameter for steam
		quantity: 1,
	};
	const res = await marketService.buy(buyParams,listingId,marketItemInfo);
```

Remove item example

```ts
	const listingId: string = "7231148125631140232";
	const res: boolean = await marketService.removeListing(listingid);
```

---
_Source: https://npm.io/package/steam-interaction · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
