### Install steampy Library Source: https://github.com/bukson/steampy/blob/master/README.md This command installs the steampy library using pip, requiring Python 3.12 or later. ```bash pip install steampy ``` -------------------------------- ### Inspect Item in Game using SteamPy Source: https://github.com/bukson/steampy/blob/master/README.md Demonstrates how to construct a link to inspect a specific item within a game, such as CS:GO. This is useful for viewing item details, stickers, and wear in the game's inspect interface. The example shows how to generate the 'Inspect in Game...' link. ```python item_data = { 'market_hash_name': 'AK-47 | Redline (Field-Tested)', 'id': '7146788981', 'instanceid': '480085569', 'market_actions': [ { 'link': 'steam://rungame/730/76561202255233023/+csgo_econ_action_preview%20M%listingid%A%assetid%D316070896107169653', 'name': 'Inspect in Game...'} ] } # Accessing the inspect link inspect_link = item_data['market_actions'][0]['link'] print(f"Inspect Link: {inspect_link}") ``` -------------------------------- ### Fetch Trade Offers Summary Source: https://github.com/bukson/steampy/blob/master/README.md Retrieves a summary of trade offers. This method is typically called to get an overview of pending, accepted, or declined trade offers. ```python from steampy.client import SteamClient steam_client = SteamClient('MY_API_KEY') steam_client.login('MY_USERNAME', 'MY_PASSWORD', 'PATH_TO_STEAMGUARD_FILE') trade_offers_summary = steam_client.get_trade_offers_summary() ``` -------------------------------- ### Get Steam Inventory Items with Steampy Source: https://context7.com/bukson/steampy/llms.txt Retrieves inventory items for your account or a partner's account, with game-specific context and detailed item descriptions including market names, icons, and trading restrictions. Uses `get_my_inventory` and `get_partner_inventory` with `GameOptions`. Requires `steampy.client.SteamClient` and `steampy.utils.GameOptions`. ```python from steampy.client import SteamClient from steampy.utils import GameOptions with SteamClient('API_KEY', 'USERNAME', 'PASSWORD', 'STEAMGUARD_PATH') as client: # Get your CS:GO inventory my_inventory = client.get_my_inventory(GameOptions.CS, merge=True, count=5000) print(f"Found {len(my_inventory)} items in inventory") for item_id, item_data in my_inventory.items(): print(f"Item ID: {item_id}") print(f" Name: {item_data['market_name']}") print(f" Tradable: {item_data['tradable']}") print(f" Marketable: {item_data['marketable']}") # Get partner's inventory partner_steam_id = '76561198012345678' partner_inventory = client.get_partner_inventory(partner_steam_id, GameOptions.CS) print(f"Partner has {len(partner_inventory)} items") ``` -------------------------------- ### Get Trade Offers Summary Source: https://github.com/bukson/steampy/blob/master/README.md Retrieves a summary of trade offers (sent, received, accepted, declined, escalated). ```APIDOC ## Get Trade Offers Summary ### Description Fetches a summary of trade offers, including counts for sent, received, accepted, declined, and escalated offers. ### Method `get_trade_offers_summary() -> dict` ### Endpoint N/A (Internal API call) ### Parameters None ### Request Example ```python from steampy.client import SteamClient steam_client = SteamClient('MY_API_KEY') steam_client.login('MY_USERNAME', 'MY_PASSWORD', 'PATH_TO_STEAMGUARD_FILE') summary = steam_client.get_trade_offers_summary() print(summary) ``` ### Response #### Success Response (dict) - A dictionary containing the trade offers summary. #### Response Example ```json { "response": { "summary": { "trade_offers_sent": 10, "trade_offers_received": 5, "trade_offers_accepted": 8, "trade_offers_declined": 2, "trade_offers_escalated": 0 } } } ``` ``` -------------------------------- ### Get My Market Listings Source: https://github.com/bukson/steampy/blob/master/README.md Retrieves a list of all market listings currently posted by the user. Requires prior SteamClient login. ```APIDOC ## GET /market/listings ### Description Retrieves a list of the user's current market listings. ### Method GET ### Endpoint /market/listings ### Parameters No parameters required. ### Request Example ```python from steampy.client import SteamClient with SteamClient('MY_API_KEY', 'MY_USERNAME', 'MY_PASSWORD', 'PATH_TO_STEAMGUARD_FILE') as client: listings = client.market.get_my_market_listings() ``` ### Response #### Success Response (200) - **listings** (dict) - A dictionary containing the user's market listings. #### Response Example ```json { "listings": { ... } } ``` ``` -------------------------------- ### Get User Inventory Data Source: https://github.com/bukson/steampy/blob/master/README.md Retrieves the user's inventory for a specified game. Optionally merges item data with descriptions and allows specifying the maximum number of items to fetch. Requires `SteamClient.login` to be called first. The `merge` parameter controls the output format. ```python def get_my_inventory(game: GameOptions, merge: bool = True, count: int = 5000) -> dict: """ Using `SteamClient.login` method is required before usage If `merge` is set `True` then inventory items are merged from items data and items description into dict where items `id` is key and descriptions merged with data are value. `Count` parameter is default max number of items, that can be fetched. """ pass ``` -------------------------------- ### Get Specific Trade Offer Details with Steampy Source: https://context7.com/bukson/steampy/llms.txt Retrieves detailed information about a single trade offer by its ID, including all items involved and their complete descriptions. It uses the `get_trade_offer` method with `merge=True` to get merged item descriptions. Dependencies include the `steampy.client.SteamClient`. ```python from steampy.client import SteamClient with SteamClient('API_KEY', 'USERNAME', 'PASSWORD', 'STEAMGUARD_PATH') as client: trade_offer_id = '1234567890' # Get specific trade offer with merged item descriptions trade_offer = client.get_trade_offer(trade_offer_id, merge=True) offer_data = trade_offer['response']['offer'] state = offer_data['trade_offer_state'] items_to_receive = offer_data.get('items_to_receive', []) items_to_give = offer_data.get('items_to_give', []) print(f"Trade offer state: {state}") print(f"Items to receive: {len(items_to_receive)}") print(f"Items to give: {len(items_to_give)}") ``` -------------------------------- ### Get Trade Receipt Source: https://github.com/bukson/steampy/blob/master/README.md Retrieves the receipt for a completed trade, including item information. ```APIDOC ## Get Trade Receipt ### Description Retrieves the receipt for a completed trade, providing details about all items involved. Note that item IDs may change after a trade is completed, so it's recommended to obtain the receipt before relying on specific item IDs. ### Method `get_trade_receipt(trade_id: str) -> list` ### Endpoint N/A (Internal API call) ### Parameters - **trade_id** (str) - The unique identifier of the completed trade. This is found in the trade offer details under the `tradeid` key (not `tradeofferid`). ### Request Example ```python from steampy.client import SteamClient steam_client = SteamClient('MY_API_KEY') steam_client.login('MY_USERNAME', 'MY_PASSWORD', 'PATH_TO_STEAMGUARD_FILE') # Assuming you have the tradeid from a completed offer trade_id = '9876543210' # Example trade ID receipt = steam_client.get_trade_receipt(trade_id) print(receipt) ``` ### Response #### Success Response (list) - A list containing details of the items included in the trade receipt. #### Response Example (Illustrative) ```json [ { "assetid": "...", "classid": "...", "instanceid": "...", "amount": 1, "market_name": "AWP | Asiimov" } // ... other items ] ``` ``` -------------------------------- ### Get Escrow Duration for Trade Offer URL Source: https://github.com/bukson/steampy/blob/master/README.md Retrieves the escrow duration for a trade offer using its URL. This method is useful for checking how long a trade will be held in escrow before completion. It requires the `SteamClient.login` method to be called beforehand. ```python def get_escrow_duration(trade_offer_url: str) -> int: """ Using `SteamClient.login` method is required before usage Check the escrow duration for trade between you and partner(given partner trade offer url) """ pass ``` -------------------------------- ### Get User's Market Listings Source: https://github.com/bukson/steampy/blob/master/README.md Fetches all market listings currently posted by the user. This function requires the user to be logged in via SteamClient.login. ```python from steampy.client import SteamClient with SteamClient('MY_API_KEY', 'MY_USERNAME', 'MY_PASSWORD', 'PATH_TO_STEAMGUARD_FILE') as client: listings = client.market.get_my_market_listings() ``` -------------------------------- ### Get Market Listings with SteamPy Source: https://context7.com/bukson/steampy/llms.txt Retrieves all active market listings and buy orders associated with the authenticated account. This includes items currently listed for sale and active buy orders. It provides details on listing IDs, prices, creation times, and confirmation status for sell listings, and item names, quantities, and prices for buy orders. ```python from steampy.client import SteamClient with SteamClient('API_KEY', 'USERNAME', 'PASSWORD', 'STEAMGUARD_PATH') as client: listings = client.market.get_my_market_listings() sell_listings = listings.get('sell_listings', {}) buy_orders = listings.get('buy_orders', {}) print(f"Active sell listings: {len(sell_listings)}") for listing_id, listing in sell_listings.items(): print(f" Listing {listing_id}: {listing.get('buyer_pay')} - Created: {listing.get('created_on')}") if listing.get('need_confirmation'): print(" (Needs confirmation)") print(f"\nActive buy orders: {len(buy_orders)}") for order_id, order in buy_orders.items(): print(f" Order {order_id}: {order.get('item_name')} - Quantity: {order.get('quantity')} @ {order.get('price')}") ``` -------------------------------- ### Get Trade Offers Source: https://github.com/bukson/steampy/blob/master/README.md Fetches trade offers (sent and/or received) with various filtering options. ```APIDOC ## Get Trade Offers ### Description Fetches trade offers from Steam. Allows filtering by sent/received offers, merging item details, and setting retry attempts. ### Method `get_trade_offers(merge: bool = True, get_sent_offers: bool = True, get_received_offers: bool = True, use_webtoken: bool = False, max_retry: int = 5) -> dict` ### Endpoint N/A (Internal API call) ### Parameters - **merge** (bool, optional) - If True, merges item data with item descriptions. Defaults to True. - **get_sent_offers** (bool, optional) - Whether to fetch sent offers. Defaults to True. - **get_received_offers** (bool, optional) - Whether to fetch received offers. Defaults to True. - **use_webtoken** (bool, optional) - Whether to use a web token instead of an API key. Defaults to False. - **max_retry** (int, optional) - Maximum number of retries for the API call. Defaults to 5. ### Request Example ```python from steampy.client import SteamClient steam_client = SteamClient('MY_API_KEY') steam_client.login('MY_USERNAME', 'MY_PASSWORD', 'PATH_TO_STEAMGUARD_FILE') # Get received offers, merging details received_offers = steam_client.get_trade_offers(get_sent_offers=False) # Get sent offers without merging details sent_offers = steam_client.get_trade_offers(get_received_offers=False, merge=False) ``` ### Response #### Success Response (dict) - A dictionary containing the trade offers, structured based on the `merge` parameter and whether sent/received offers were requested. #### Response Example (Illustrative) ```json { "response": { "offers": [ { "tradeofferid": "1234567890", "accountid_other": 123456789, "message": "Hey, check out these items!", "trade_offer_state": 2, // Active "items_to_give": [...], "items_received": [...] } // ... other offers ] } } ``` ``` -------------------------------- ### Get Trade Receipt Source: https://github.com/bukson/steampy/blob/master/README.md Retrieves the receipt for a completed trade, including all item information. It's crucial to obtain this receipt *after* the trade is finalized, as item IDs might change. ```python from steampy.client import SteamClient steam_client = SteamClient('MY_API_KEY') steam_client.login('MY_USERNAME', 'MY_PASSWORD', 'PATH_TO_STEAMGUARD_FILE') trade_id = 'YOUR_TRADE_ID' trade_receipt = steam_client.get_trade_receipt(trade_id) ``` -------------------------------- ### Get Trade Receipt using SteamPy Source: https://context7.com/bukson/steampy/llms.txt Retrieves the receipt for a completed trade using its ID. This allows you to see the exact items traded and their final asset IDs. It requires the Steam client to be authenticated and the trade offer ID to first fetch the trade ID. The output lists the name and asset ID of each item in the receipt. ```python from steampy.client import SteamClient with SteamClient('API_KEY', 'USERNAME', 'PASSWORD', 'STEAMGUARD_PATH') as client: # Get trade offer to find trade_id offer = client.get_trade_offer('1234567890') trade_id = offer['response']['offer'].get('tradeid') if trade_id: receipt = client.get_trade_receipt(trade_id) print(f"Trade receipt contains {len(receipt)} items") for item in receipt: print(f"Item: {item.get('name')} - Asset ID: {item.get('id')}") ``` -------------------------------- ### Configure Proxy Settings (Python) Source: https://context7.com/bukson/steampy/llms.txt Shows how to configure HTTP and HTTPS proxy settings for the Steam client. Proxies can be set during initialization or after by calling `set_proxies`. This is useful for operating within restricted networks or enhancing privacy. ```python from steampy.client import SteamClient api_key = 'YOUR_STEAM_API_KEY' proxies = { "http": "http://username:password@proxy.example.com:8080", "https": "http://username:password@proxy.example.com:8080" } # Initialize with proxies steam_client = SteamClient(api_key, proxies=proxies) # Or set proxies after initialization steam_client = SteamClient(api_key) steam_client.set_proxies(proxies) steam_client.login('username', 'password', '/path/to/steamguard.txt') ``` -------------------------------- ### Get Steam Wallet Balance (Python) Source: https://context7.com/bukson/steampy/llms.txt Retrieves the user's Steam wallet balance, with options to get funds on hold and format the balance as a Decimal or in cents. This function requires user authentication via SteamClient. ```python from steampy.client import SteamClient from decimal import Decimal with SteamClient('API_KEY', 'USERNAME', 'PASSWORD', 'STEAMGUARD_PATH') as client: # Get balance as Decimal wallet_balance = client.get_wallet_balance(convert_to_decimal=True) assert type(wallet_balance) == Decimal print(f"Wallet balance: ${wallet_balance}") # Get balance on hold on_hold_balance = client.get_wallet_balance(convert_to_decimal=True, on_hold=True) print(f"On hold balance: ${on_hold_balance}") # Get balance as string without decimal point (in cents) balance_cents = client.get_wallet_balance(convert_to_decimal=False) print(f"Balance in cents: {balance_cents}") ``` -------------------------------- ### Context Manager Login Pattern (Python) Source: https://context7.com/bukson/steampy/llms.txt Demonstrates using Python's context manager (`with` statement) for automatic login and logout of the SteamClient. This ensures proper session cleanup even if errors occur. It's a convenient way to manage the client's lifecycle. ```python from steampy.client import SteamClient from steampy.game_options import GameOptions api_key = 'YOUR_STEAM_API_KEY' username = 'your_username' password = 'your_password' steamguard_file = '/path/to/Steamguard.txt' with SteamClient(api_key, username, password, steamguard_file) as client: # Automatically logged in offers = client.get_trade_offers() inventory = client.get_my_inventory(GameOptions.CS) wallet_balance = client.get_wallet_balance() # Automatically logged out when exiting the context ``` -------------------------------- ### Initialize and Login to Steam Client (Python) Source: https://context7.com/bukson/steampy/llms.txt Initializes a SteamClient with an API key and logs in using username, password, and an optional SteamGuard file. It also includes a check for session validity and a logout function. This method is suitable for direct credential-based authentication. ```python from steampy.client import SteamClient # Initialize with API key and login api_key = 'YOUR_STEAM_API_KEY' username = 'your_username' password = 'your_password' steamguard_file = '/path/to/Steamguard.txt' steam_client = SteamClient(api_key) steam_client.login(username, password, steamguard_file) # Check if session is alive if steam_client.is_session_alive(): print("Successfully logged in") else: print("Login failed") # Logout when done steam_client.logout() ``` -------------------------------- ### Initialize SteamClient with Proxy Support Source: https://github.com/bukson/steampy/blob/master/README.md Initializes the SteamClient with an API key and configures it to use specified HTTP and HTTPS proxies. This is useful for users who need to route their Steam requests through a proxy server. ```python from steampy.client import SteamClient proxies = { "http": "http://login:password@host:port", "https": "http://login:password@host:port" } steam_client = SteamClient('MY_API_KEY', proxies=proxies) ``` -------------------------------- ### Get Specific Trade Offer Source: https://github.com/bukson/steampy/blob/master/README.md Retrieves details for a single, specific trade offer by its ID. ```APIDOC ## Get Specific Trade Offer ### Description Fetches details for a single trade offer using its unique trade offer ID. ### Method `get_trade_offer(trade_offer_id: str, merge: bool = True, use_webtoken: bool = False) -> dict` ### Endpoint N/A (Internal API call) ### Parameters - **trade_offer_id** (str) - The unique identifier of the trade offer. - **merge** (bool, optional) - If True, merges item data with item descriptions. Defaults to True. - **use_webtoken** (bool, optional) - Whether to use a web token instead of an API key. Defaults to False. ### Request Example ```python from steampy.client import SteamClient steam_client = SteamClient('MY_API_KEY') steam_client.login('MY_USERNAME', 'MY_PASSWORD', 'PATH_TO_STEAMGUARD_FILE') trade_offer_id = '1234567890' offer_details = steam_client.get_trade_offer(trade_offer_id) print(offer_details) ``` ### Response #### Success Response (dict) - A dictionary containing the details of the specified trade offer. #### Response Example (Illustrative) ```json { "response": { "offer": { "tradeofferid": "1234567890", "accountid_other": 123456789, "message": "Hello there!", "trade_offer_state": 2, "items_to_give": [...], "items_received": [...] } } } ``` ``` -------------------------------- ### Make Trade Offer with URL Source: https://github.com/bukson/steampy/blob/master/README.md Creates a trade offer using a partner's trade offer URL. ```APIDOC ## Make Trade Offer with URL ### Description Creates a trade offer using a provided trade offer URL from the partner. This method is useful when you have a direct link to a trade offer. ### Method `make_offer_with_url(items_from_me: List[Asset], items_from_them: List[Asset], trade_offer_url: str, message: str = '', case_sensitive: bool = True) -> dict` ### Endpoint N/A (Internal API call) ### Parameters - **items_from_me** (List[Asset]) - A list of `Asset` objects representing items the current user is offering. - **items_from_them** (List[Asset]) - A list of `Asset` objects representing items the current user wants from the partner. - **trade_offer_url** (str) - The URL of the trade offer. - **message** (str, optional) - A message to include with the trade offer. Defaults to an empty string. - **case_sensitive** (bool, optional) - Whether item matching should be case-sensitive. Defaults to True. ### Request Example ```python from steampy.client import SteamClient, Asset from steampy.utils import GameOptions steam_client = SteamClient('MY_API_KEY') steam_client.login('MY_USERNAME', 'MY_PASSWORD', 'PATH_TO_STEAMGUARD_FILE') trade_url = 'https://steamcommunity.com/tradeoffer/new/?partner=...' # Replace with actual trade offer URL game = GameOptions.TF2 # Example: Team Fortress 2 # Assume you have obtained lists of Asset objects for items you want to trade # Example: Getting assets from your inventory my_inventory = steam_client.get_my_inventory(game) # Select specific items to offer (replace with actual item selection logic) my_first_item_data = next(iter(my_inventory.values())) my_asset = Asset(my_first_item_data['id'], game) # Placeholder for items requested from the partner (you would typically get these from the URL or another source) items_from_them_list = [] # Create and send the offer trade_offer_result = steam_client.make_offer_with_url([my_asset], items_from_them_list, trade_url, 'Offer via URL') print(f"Trade offer created: {trade_offer_result.get('tradeofferid')}") ``` ### Response #### Success Response (dict) - A dictionary containing information about the created trade offer, including the `tradeofferid`. #### Response Example ```json { "tradeofferid": "6677889900", "success": true } ``` ``` -------------------------------- ### Initialize SteamClient with API Key and Login Credentials Source: https://github.com/bukson/steampy/blob/master/README.md Initializes the SteamClient with an API key and then logs in using username, password, and a SteamGuard file. This is a common way to authenticate for full access to Steam functionalities. ```python from steampy.client import SteamClient steam_client = SteamClient('MY_API_KEY') steam_client.login('MY_USERNAME', 'MY_PASSWORD', 'PATH_TO_STEAMGUARD_FILE') ``` -------------------------------- ### Create Trade Offer from URL Source: https://github.com/bukson/steampy/blob/master/README.md Creates a trade offer using a trade offer URL provided by the partner. Similar to `make_offer`, it requires lists of assets and an optional message. Authentication relies on the provided URL. ```python from steampy.client import SteamClient, Asset from steampy.utils import GameOptions steam_client = SteamClient('MY_API_KEY') steam_client.login('MY_USERNAME', 'MY_PASSWORD', 'PATH_TO_STEAMGUARD_FILE') partner_id = 'PARTNER_ID' trade_offer_url = 'YOUR_TRADE_OFFER_URL' game = GameOptions.CS my_items = steam_client.get_my_inventory(game) # Assuming you have items to offer and a valid trade_offer_url my_asset = Asset(next(iter(my_items.values()))['id'], game) # For simplicity, not adding items from them, adjust as needed steam_client.make_offer_with_url([my_asset], [], trade_offer_url, 'Offer via URL') ``` -------------------------------- ### Create a Sell Order Source: https://github.com/bukson/steampy/blob/master/README.md Creates a sell order for a specific asset on the Steam market. The `money_to_receive` parameter must be provided in cents. Prior login with SteamClient.login is necessary. ```python from steampy.client import SteamClient from steampy.models import GameOptions with SteamClient('MY_API_KEY', 'MY_USERNAME', 'MY_PASSWORD', 'PATH_TO_STEAMGUARD_FILE') as client: asset_id_to_sell = 'some_asset_id' game = GameOptions.DOTA2 sell_response = client.market.create_sell_order(asset_id_to_sell, game, "10000") ``` -------------------------------- ### Create a Buy Order Source: https://github.com/bukson/steampy/blob/master/README.md Initiates a buy order for an item on the Steam market. The `price_single_item` must be specified in cents. This function requires prior login using SteamClient.login. ```python from steampy.client import SteamClient from steampy.models import GameOptions, Currency with SteamClient('MY_API_KEY', 'MY_USERNAME', 'MY_PASSWORD', 'PATH_TO_STEAMGUARD_FILE') as client: response = client.market.create_buy_order("AK-47 | Redline (Field-Tested)", "1034", 2, GameOptions.CS, Currency.EURO) buy_order_id = response["buy_orderid"] ``` -------------------------------- ### Buy Item Directly from Market (Python) Source: https://context7.com/bukson/steampy/llms.txt Purchases a specific item listing from the Steam Community Market immediately at the asking price. This requires the market item name, listing ID, total price (in cents), fee (in cents), game options, and currency. It confirms success and updates the wallet balance. ```python from steampy.client import SteamClient from steampy.models import GameOptions, Currency with SteamClient('API_KEY', 'USERNAME', 'PASSWORD', 'STEAMGUARD_PATH') as client: market_name = 'AK-47 | Redline (Field-Tested)' market_id = '1942659007774983251' # Get from market listing price = 1150 # Total price in cents ($11.50) fee = 150 # Fee in cents ($1.50) response = client.market.buy_item( market_name, market_id, price, fee, GameOptions.CS, Currency.USD ) if response.get('wallet_info', {}).get('success') == 1: new_balance = response['wallet_info']['wallet_balance'] print(f"Item purchased successfully") print(f"New wallet balance: ${new_balance / 100:.2f}") ``` -------------------------------- ### Create Buy Order on Steam Market (Python) Source: https://context7.com/bukson/steampy/llms.txt Places a buy order for a specified item at a target price and quantity on the Steam Community Market. This function requires item name, price per item (in cents), quantity, game options, and currency. It returns the buy order ID on success. ```python from steampy.client import SteamClient from steampy.models import GameOptions, Currency with SteamClient('API_KEY', 'USERNAME', 'PASSWORD', 'STEAMGUARD_PATH') as client: item_name = "AK-47 | Redline (Field-Tested)" price_per_item = "1034" # $10.34 in cents quantity = 3 response = client.market.create_buy_order( item_name, price_per_item, quantity, GameOptions.CS, Currency.USD ) if response.get('success') == 1: buy_order_id = response.get('buy_orderid') print(f"Buy order created successfully: {buy_order_id}") else: print(f"Failed to create buy order") ``` -------------------------------- ### Create Buy Order Source: https://github.com/bukson/steampy/blob/master/README.md Creates a buy order for an item on the Steam market. Requires prior SteamClient login. ```APIDOC ## POST /market/buy_order ### Description Creates a buy order for an item on the Steam market. ### Method POST ### Endpoint /market/buy_order ### Parameters #### Request Body - **market_name** (str) - Required - The market name of the item (e.g., "AK-47 | Redline (Field-Tested)"). - **price_single_item** (str) - Required - The price for a single item, in cents (e.g., "1034" for $10.34). - **quantity** (int) - Required - The number of items to buy. - **game** (GameOptions) - Required - The game the item belongs to (e.g., GameOptions.CS). - **currency** (Currency) - Optional - The currency for the transaction (default is Currency.USD). ### Request Example ```python from steampy.client import SteamClient from steampy.models import GameOptions, Currency with SteamClient('MY_API_KEY', 'MY_USERNAME', 'MY_PASSWORD', 'PATH_TO_STEAMGUARD_FILE') as client: response = client.market.create_buy_order("AK-47 | Redline (Field-Tested)", "1034", 2, GameOptions.CS, Currency.EURO) buy_order_id = response["buy_orderid"] ``` ### Response #### Success Response (200) - **buy_orderid** (str) - The ID of the created buy order. #### Response Example ```json { "buy_orderid": "1234567890" } ``` ``` -------------------------------- ### Generate Confirmation and Allow Keys - Python Source: https://context7.com/bukson/steampy/llms.txt Generates a confirmation key and an allow key using the provided identity secret and a timestamp. These keys are typically used for trade confirmations. ```python from steampy.utils import generate_confirmation_key import time # Assuming identity_secret is already defined and holds your secret key identity_secret = "your_identity_secret_here" timestamp = int(time.time()) conf_key = generate_confirmation_key(identity_secret, 'conf', timestamp) print(f"Confirmation key: {conf_key}") # Generate for different operations allow_key = generate_confirmation_key(identity_secret, 'allow', timestamp) print(f"Allow key: {allow_key}") ``` -------------------------------- ### SteamClient Authentication and Usage Source: https://github.com/bukson/steampy/blob/master/README.md Demonstrates how to initialize and log in to the SteamClient, with options for using a `with` statement for automatic login/logout. ```APIDOC ## SteamClient Initialization and Login ### Description Initializes the SteamClient and logs into a Steam account. Supports direct login or using a `with` statement for automatic session management. ### Method `SteamClient(api_key, username=None, password=None, steam_guard_path=None)` ### Endpoint N/A (Client-side library) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```python from steampy.client import SteamClient # Direct login steam_client = SteamClient('MY_API_KEY') steam_client.login('MY_USERNAME', 'MY_PASSWORD', 'PATH_TO_STEAMGUARD_FILE') # Using 'with' statement with SteamClient('MY_API_KEY', 'MY_USERNAME', 'MY_PASSWORD', 'PATH_TO_STEAMGUARD_FILE') as client: client.some_method1(...) client.some_method2(...) ``` ### Response N/A (Client-side operation) ``` -------------------------------- ### Get Wallet Balance with Steampy Source: https://github.com/bukson/steampy/blob/master/README.md Retrieves the Steam account's wallet balance. It can convert the balance to a Decimal type or return it as a string. It also supports fetching the on-hold balance. Requires SteamClient initialization with API key, username, password, and Steam Guard file path. ```python from steampy.client import SteamClient from decimal import Decimal with SteamClient('MY_API_KEY', 'MY_USERNAME', 'MY_PASSWORD', 'PATH_TO_STEAMGUARD_FILE') as client: wallet_balance = client.get_wallet_balance() on_hold_wallet_balance = client.get_wallet_balance(on_hold = True) assert type(wallet_balance) == Decimal assert type(on_hold_wallet_balance) == Decimal ``` -------------------------------- ### Fetch Trade Offers (Python) Source: https://context7.com/bukson/steampy/llms.txt Retrieves active trade offers, both sent and received, using the `get_trade_offers` method. The `merge=True` option enriches offer data by combining item descriptions with asset information, including names and icons. It then iterates through received and sent offers to print details. ```python from steampy.client import SteamClient with SteamClient('API_KEY', 'USERNAME', 'PASSWORD', 'STEAMGUARD_PATH') as client: # Get all active trade offers (sent and received) with merged descriptions offers = client.get_trade_offers(merge=True) received_offers = offers['response']['trade_offers_received'] sent_offers = offers['response']['trade_offers_sent'] print(f"Received {len(received_offers)} offers") for offer in received_offers: offer_id = offer['tradeofferid'] items_to_receive = offer.get('items_to_receive', []) items_to_give = offer.get('items_to_give', []) print(f"Offer {offer_id}: Receiving {len(items_to_receive)} items, Giving {len(items_to_give)} items") ``` -------------------------------- ### Create Trade Offer Source: https://github.com/bukson/steampy/blob/master/README.md Creates a trade offer between the current user and a partner. Requires lists of assets from both parties, the partner's Steam ID, and an optional message. Uses Steam Guard identity secret for confirmation. ```python from steampy.client import SteamClient, Asset from steampy.utils import GameOptions steam_client = SteamClient('MY_API_KEY') steam_client.login('MY_USERNAME', 'MY_PASSWORD', 'PATH_TO_STEAMGUARD_FILE') partner_id = 'PARTNER_ID' game = GameOptions.CS my_items = steam_client.get_my_inventory(game) partner_items = steam_client.get_partner_inventory(partner_id, game) my_first_item = next(iter(my_items.values())) partner_first_item = next(iter(partner_items.values())) my_asset = Asset(my_first_item['id'], game) partner_asset = Asset(partner_first_item['id'], game) steam_client.make_offer([my_asset], [partner_asset], partner_id, 'Test offer') ``` -------------------------------- ### Buy an Item Directly Source: https://github.com/bukson/steampy/blob/master/README.md Purchases a specific item directly from a market listing. This operation requires the item's market name, listing ID, price, fee, game, and currency. Login via SteamClient.login is a prerequisite. ```python from steampy.client import SteamClient from steampy.models import Currency, GameOptions with SteamClient('MY_API_KEY', 'MY_USERNAME', 'MY_PASSWORD', 'PATH_TO_STEAMGUARD_FILE') as client: response = client.market.buy_item('AK-47 | Redline (Field-Tested)', '1942659007774983251', 81, 10, GameOptions.CS, Currency.RUB) wallet_balance = response["wallet_info"]["wallet_balance"] ``` -------------------------------- ### Create Trade Offer with URL using SteamPy Source: https://context7.com/bukson/steampy/llms.txt Creates a trade offer using a provided trade URL, allowing trades with users who are not Steam friends. It requires API keys, user credentials, and Steam Guard path for authentication. The function takes item assets to offer and items to receive, along with an optional message. It returns a response indicating the success of the trade offer creation. ```python from steampy.client import SteamClient, Asset from steampy.utils import GameOptions with SteamClient('API_KEY', 'USERNAME', 'PASSWORD', 'STEAMGUARD_PATH') as client: trade_offer_url = 'https://steamcommunity.com/tradeoffer/new/?partner=123456789&token=AbCdEfGh' game = GameOptions.CS # Get your inventory my_inventory = client.get_my_inventory(game) # Select item to give (empty list to receive items for free) my_item = next(iter(my_inventory.values())) my_asset = Asset(my_item['id'], game) # Create offer (giving one item, receiving nothing) response = client.make_offer_with_url( items_from_me=[my_asset], items_from_them=[], trade_offer_url=trade_offer_url, message='Here is your item!', case_sensitive=True ) if 'tradeofferid' in response: print(f"Trade offer sent: {response['tradeofferid']}") ``` -------------------------------- ### Initialize SteamClient with API Key and Login Cookies Source: https://github.com/bukson/steampy/blob/master/README.md Initializes the SteamClient with an API key and logs in using provided session cookies. This method bypasses the need for username and password, relying on existing browser session data. ```python from steampy.client import SteamClient login_cookies = {} # provide dict with cookies steam_client = SteamClient('MY_API_KEY',username='MY_USERNAME',login_cookies=login_cookies) assert steam_client.was_login_executed ``` -------------------------------- ### Fetch Price History with SteamPy Source: https://context7.com/bukson/steampy/llms.txt Retrieves the historical price data for an item, including price changes over time. It requires the item's market hash name and the game it belongs to. The output includes dates, prices, and trading volumes, allowing analysis of market trends. It's useful for tracking item value fluctuations. ```python from steampy.client import SteamClient from steampy.models import GameOptions with SteamClient('API_KEY', 'USERNAME', 'PASSWORD', 'STEAMGUARD_PATH') as client: item_name = 'M4A1-S | Cyrex (Factory New)' history = client.market.fetch_price_history(item_name, GameOptions.CS) if history.get('success') and history.get('prices'): print(f"Price history for {item_name}:") # Each entry: ['Date', price, volume] for entry in history['prices'][:10]: # First 10 entries date, price, volume = entry print(f" {date}: ${price} (volume: {volume})") ``` -------------------------------- ### Calculate Market Prices with Fees - Python Source: https://context7.com/bukson/steampy/llms.txt Calculates the gross price (buyer pays) or net price (seller receives) by factoring in both Steam and publisher fees. This utility is useful for determining exact transaction values on the Steam market. ```python from decimal import Decimal from steampy.utils import calculate_gross_price, calculate_net_price publisher_fee = Decimal('0.1') # 10% publisher fee (typical for most games) steam_fee = Decimal('0.05') # 5% Steam transaction fee # Calculate what buyer pays when seller wants to receive $100 seller_receives = Decimal('100') buyer_pays = calculate_gross_price(seller_receives, publisher_fee, steam_fee) print(f"Seller receives: ${seller_receives}") print(f"Buyer pays: ${buyer_pays}") # Calculate what seller receives when buyer pays $115 buyer_pays_example = Decimal('115') seller_receives_example = calculate_net_price(buyer_pays_example, publisher_fee, steam_fee) print(f"\nBuyer pays: ${buyer_pays_example}") print(f"Seller receives: ${seller_receives_example}") ``` -------------------------------- ### Create Sell Order Source: https://github.com/bukson/steampy/blob/master/README.md Creates a new sell order for a specific asset on the Steam market. Requires prior SteamClient login. ```APIDOC ## POST /market/sell_order ### Description Creates a sell order for an asset on the Steam market. ### Method POST ### Endpoint /market/sell_order ### Parameters #### Request Body - **assetid** (str) - Required - The unique identifier of the asset to sell. - **game** (GameOptions) - Required - The game the asset belongs to (e.g., GameOptions.DOTA2). - **money_to_receive** (str) - Required - The amount of money to receive, in cents (e.g., "10000" for $100.00). ### Request Example ```python from steampy.client import SteamClient from steampy.models import GameOptions with SteamClient('MY_API_KEY', 'MY_USERNAME', 'MY_PASSWORD', 'PATH_TO_STEAMGUARD_FILE') as client: asset_id_to_sell = 'some_asset_id' game = GameOptions.DOTA2 sell_response = client.market.create_sell_order(asset_id_to_sell, game, "10000") ``` ### Response #### Success Response (200) - **success** (bool) - Indicates if the sell order was created successfully. #### Response Example ```json { "success": true } ``` ``` -------------------------------- ### Make Trade Offer Source: https://github.com/bukson/steampy/blob/master/README.md Creates a new trade offer between the current user and another user. ```APIDOC ## Make Trade Offer ### Description Creates a new trade offer. This method handles the process of constructing and sending the offer, including using the SteamGuard identity secret for confirmation. It works for both friends and other Steam users. ### Method `make_offer(items_from_me: List[Asset], items_from_them: List[Asset], partner_steam_id: str, message: str = '') -> dict` ### Endpoint N/A (Internal API call) ### Parameters - **items_from_me** (List[Asset]) - A list of `Asset` objects representing items the current user is offering. - **items_from_them** (List[Asset]) - A list of `Asset` objects representing items the current user wants from the partner. - **partner_steam_id** (str) - The Steam ID of the trade partner. - **message** (str, optional) - A message to include with the trade offer. Defaults to an empty string. ### Request Example ```python from steampy.client import SteamClient, Asset from steampy.utils import GameOptions steam_client = SteamClient('MY_API_KEY') steam_client.login('MY_USERNAME', 'MY_PASSWORD', 'PATH_TO_STEAMGUARD_FILE') partner_id = 'PARTNER_ID' # Replace with actual partner Steam ID game = GameOptions.CS # Example: Counter-Strike: Global Offensive # Assume you have obtained lists of Asset objects for items you want to trade # Example: Getting assets from your inventory and partner's inventory my_inventory = steam_client.get_my_inventory(game) partner_inventory = steam_client.get_partner_inventory(partner_id, game) # Select specific items to offer (replace with actual item selection logic) my_first_item_data = next(iter(my_inventory.values())) partner_first_item_data = next(iter(partner_inventory.values())) my_asset = Asset(my_first_item_data['id'], game) partner_asset = Asset(partner_first_item_data['id'], game) # Create and send the offer trade_offer_result = steam_client.make_offer([my_asset], [partner_asset], partner_id, 'Let\'s trade!') print(f"Trade offer created: {trade_offer_result.get('tradeofferid')}") ``` ### Response #### Success Response (dict) - A dictionary containing information about the created trade offer, including the `tradeofferid`. #### Response Example ```json { "tradeofferid": "1122334455", "success": true } ``` ``` -------------------------------- ### Create Sell Order on Steam Market (Python) Source: https://context7.com/bukson/steampy/llms.txt Lists an item for sale on the Steam Community Market at a specified price. This function requires API keys, user credentials, and Steam Guard path for authentication. It returns the listing ID upon successful placement. ```python from steampy.client import SteamClient from steampy.models import GameOptions with SteamClient('API_KEY', 'USERNAME', 'PASSWORD', 'STEAMGUARD_PATH') as client: game = GameOptions.CS # Get inventory and select item inventory = client.get_my_inventory(game) item_to_sell = next(iter(inventory.values())) asset_id = item_to_sell['id'] # Price in cents - seller receives $10.00 money_to_receive = "1000" response = client.market.create_sell_order(asset_id, game, money_to_receive) if response.get('success'): print(f"Item listed successfully") print(f"Listing ID: {response.get('listingid')}") else: print(f"Error: {response.get('message')}") ``` -------------------------------- ### Direct API Call Source: https://github.com/bukson/steampy/blob/master/README.md Details on how to make a direct call to any Steam API method using `api_call()`. ```APIDOC ## Direct API Call ### Description Allows for directly calling any method from Steam API services. This provides flexibility for accessing endpoints not explicitly wrapped by the library. ### Method `api_call(request_method: str, interface: str, api_method: str, version: str, params: dict = None) -> requests.Response` ### Endpoint N/A (Client-side library, constructs endpoint dynamically) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Parameters (Method Arguments) - **request_method** (str) - The HTTP method (e.g., 'GET', 'POST'). - **interface** (str) - The Steam API interface name (e.g., 'IEconService'). - **api_method** (str) - The specific API method name (e.g., 'GetTradeOffersSummary'). - **version** (str) - The API version (e.g., 'v1'). - **params** (dict, optional) - Dictionary of parameters to send with the request. Defaults to None. ### Request Example ```python from steampy.client import SteamClient steam_client = SteamClient('MY_API_KEY') params = {'key': 'MY_API_KEY'} # Example: Get trade offers summary response = steam_client.api_call('GET', 'IEconService', 'GetTradeOffersSummary', 'v1', params) summaries = response.json() print(summaries) ``` ### Response #### Success Response (requests.Response) - The method returns a `requests.Response` object, which can be further processed (e.g., using `.json()`). #### Response Example (after calling .json() on the response object) ```json { "response": { "summary": { "trade_offers_sent": 0, "trade_offers_received": 0, "trade_offers_accepted": 0, "trade_offers_declined": 0, "trade_offers_escalated": 0 } } } ``` ```