# How to set up trade websocket

`wss://wssex.waxpeer.com`

## Breaking changes due to Steam API update

Now in order to go online and sell items safely you need to implement the following logic:

1. Make sure that you have enabled the collection of user data on the website under the "Sell items" tab (by default it is enabled).
2. Going online now requires a valid Steam access token because the API key functionality has been limited. You need to send it once an hour or immediately after an refresh (the token is active only 24 hours after refreshing in Steam), otherwise it will expire and all your items will be disabled from sale, and active trades will be considered stalled and may be canceled
3. We categorically recommend not to make a mobile confirmation for a created trade until you send its trade id using the callback method.
4. Online may be delayed until the access token is verified or a valid token is received. Therefore, please note that in the trade socket there is a new user_change event, in which can_p2p indicates whether you are online or not when it is changed by p2p controller.
5. If you do not want to use npm package, but will be implementing your own trade socket connection, make sure you specify the source parameter on the authentification event (auth) without which the account will not be able to get online (example: "source": "myAwesomeProject").

## How to set up trade websocket

1. Connect to websocket via any websocket library. Such as WS, Socket.IO client for Node.js
2. Send a ping command once per 25 seconds to keep the connection alive
3. Send your authentication object command to let our system recognize you
4. Be ready to react to the following object name events:
   - send-trade (create trade)
   - cancelTrade (cancel trade)
   - accept_withdraw (accept incoming trade)
5. Don’t forget to confirm trade on mobile

We recommend sending the trade only once

After send-trade, POST /v1/steam-trade before mobile confirm. Do not confirm if that POST fails.

## Authentification

You can now go online and sell from limited Steam accounts (Except Rust game). One from STEAM_API, WAX_API, ACCESS_TOKEN is required!

```json
{
  "source": "myAwesomeProject",
  "name": "auth",
  "steamid": "76561199059254XXX",
  "apiKey": "54###A171A5C7B08CA287A###228C029",
  "waxApi": "####124b4bd3847e33331f0e49194b9c798f613d5e732d17c4f5823f7f9c6a##",
  "accessToken": "eyAidHlwIjogIkpXVCIsICJhbGciOiAiRWREU0EiIH0.eyAiaXfsd23123123.2B9wKjf2323-S3i3ctdCg",
  "tradeurl": "https://steamcommunity.com/tradeoffer/new/?partner=1234567890&token=asd1-5zF"
}
```

## Ping

Send a ping command once per 25 seconds to keep the connection alive

```json
{ "name": "ping" }
```

## Pong

Event notifying that a ping command has been received

```json
{ "name": "pong", "data": { "msg": "1" } }
```

## Online change event

Indicates whether you are online or not when it is changed by p2p controller

```json
{ "name": "user_change", "data": { "can_p2p": true } }
```

## Create trade

Event for trade creation with all necessary data. name is always “send-trade”.

## Cancel trade

This event is mandatory. We reserve the right to cancel a trade on our side if you do not react to this event for a long time.

After a recent update STEAM no longer supports trade cancellation via API, so please use https://steamcommunity.com/tradeoffer/TRADE_ID/cancel with cookies.

## Accept withdraw

Event notifying that a ping command has been received (accept_withdraw).
