Backpack.tf Listings is a FastAPI application designed for seamless interaction with Backpack.tf, a platform that provides real-time listings data for virtual items in Team Fortress 2. This project utilizes websocket connections to receive live updates from Backpack.tf and employs its API to fetch and store listings data in a MongoDB database. Users can easily access this data through a RESTful API, making it a vital resource for traders and developers within the Team Fortress 2 community.
- Real-time Data Updates: Establishes websocket connections to receive live updates on item listings in Team Fortress 2.
- RESTful API: Offers well-defined endpoints for fetching and managing listings and user data.
- High Performance: Capable of processing over 10,000 listings in under a minute, ensuring efficient data handling.
- User Authentication: Supports optional authorization tokens for secure API access.
Ensure you have the following installed:
- Python 3.8 or higher.
Clone the repository and navigate to the project directory:
git clone https://github.com/dixon2004/backpack.tf-listings.git
cd backpack.tf-listings
Create and activate a virtual environment to manage dependencies:
-
Linux/macOS:
python3 -m venv venv source venv/bin/activate
-
Windows:
python -m venv venv .\venv\Scripts\activate
Install the necessary Python packages using:
pip install -r requirements.txt
Set the following environment variables before running the application:
DATABASE_URL
: MongoDB connection string (e.g.,mongodb://localhost:27017
).BPTF_TOKEN
: Your Backpack.tf API token, obtainable from here.STEAM_API_KEY
: Your Steam API key, obtainable from here.AUTH_TOKEN
: Optionally specify an authorization token for API access. If left empty, no token will be required.SAVE_USER_DATA
: Set totrue
to enable saving user data in the database (default is false).SERVER_PORT
: Define the port number for the API (default is 8000).
Start the application by executing:
python src/main.py
PM2 is a process manager that simplifies application management, including automatic restarts and log handling.
Install PM2 globally via npm:
npm install pm2 -g
Run the application as a background service using PM2:
pm2 start src/main.py --name backpack-tf-listings --interpreter python3
For details on setting up log rotation with PM2, refer to the PM2 Logrotate Documentation.
Ensure PM2 restarts automatically on boot:
pm2 startup
pm2 save
Monitor the application’s status and logs with:
pm2 status
pm2 logs
The Backpack.tf Listings application provides a RESTful API with the following endpoints:
- Endpoint:
GET /listings
- Query Parameters:
sku
: The SKU of the item for which to fetch listings.
- Authorization: A valid authorization token is required if specified in the
options.json
file. - Response: Returns listings data in JSON format.
Example Request:
curl -H "Authorization: YOUR_AUTH_TOKEN" "http://localhost:8000/listings?sku=YOUR_SKU"
- Endpoint:
DELETE /listings/{sku}
- Query Parameters:
sku
: The SKU of the item for which to delete all listings.
- Authorization: A valid authorization token is required if specified in the
options.json
file. - Response: Returns a success message in JSON format.
Example Request:
curl -X DELETE -H "Authorization: YOUR_AUTH_TOKEN" "http://localhost:8000/listings/YOUR_SKU"
- Endpoint:
GET /user
- Query Parameters:
steamid
: The Steam ID of the user to retrieve.
- Authorization: A valid authorization token is required if specified in the
options.json
file. - Response: Returns user data in JSON format.
Example Request:
curl -H "Authorization: YOUR_AUTH_TOKEN" "http://localhost:8000/user?steamid=STEAM_ID"
The Backpack.tf Listings application supports a websocket connection that allows clients to receive real-time updates on item listings for Team Fortress 2.
- Endpoint:
ws://localhost:8000/ws
- Authorization: No authorization token is required to connect to the websocket.
When updates are received via the websocket, the data is structured as follows:
[
{
"sku": "item_sku",
"name": "item_name"
}
]
This format provides the SKU and name of the item that has been updated, enabling clients to react to market changes in real time.
This project is licensed under the MIT License. See the LICENSE file for more details.