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.
- RESTful API: Provides structured endpoints for retrieving and managing listings and user data.
- High Performance: Optimized to process over 10,000 listings per minute with minimal latency.
- Secure API Access: Supports optional authentication via authorization tokens.
- Scalable & Dockerized: Easily deploy the application using Docker and Docker Compose.
Ensure you have the following installed:
- Docker and Docker Compose
Clone the repository and navigate to the project directory:
git clone https://github.com/dixon2004/backpack.tf-listings.git
cd backpack.tf-listings
-
Rename
template.env
to.env
in the root directory. -
Open
.env
and set the following environment variables:AUTH_TOKEN = "your_auth_token_here" BPTF_TOKEN = "your_backpacktf_token_here" # Multiple tokens can be separated by commas SAVE_USER_DATA = False STEAM_API_KEY = "your_steam_api_key_here"
AUTH_TOKEN
: Optionally specify an authorization token for API access. If left empty, authentication is disabled, allowing unrestricted access.BPTF_TOKEN
: Your Backpack.tf API token, obtainable from here.SAVE_USER_DATA
: Set toTrue
to enable saving user data in the database (Default is False).STEAM_API_KEY
: Your Steam API key, obtainable from here.
-
Build and Start the Service:
docker-compose up --build -d
This will build the necessary Docker image and start the application as a background service on port 8000.
-
Stopping the Service:
To stop and remove the running containers, execute:
docker-compose down
-
Restarting the Service:
If you need to restart the service after making changes to the environment variables or code:
docker-compose down && docker-compose up --build -d
-
Checking Logs:
To monitor the service logs in real-time:
docker-compose logs -f
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
AUTH_TOKEN
is set in the environment variables. - 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
AUTH_TOKEN
is set in the environment variables. - 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
AUTH_TOKEN
is set in the environment variables. - 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.