├── README.md ├── main.py ├── marketdata.py └── requirements.txt /README.md: -------------------------------------------------------------------------------- 1 | # Still working 2 | I mostly have this up just for public reference of steam's backend. 3 | 4 | 5 | # CS2 Market API 6 | Implementation for a future CS2 Market Bot 7 | 8 | This is a Flask web app that provides two API endpoints to get item data for weapons, cases, and items in CS2. The item data is fetched by calling functions from another module called marketdata, which retrieves the highest buy order and lowest sell order price for an item, as well as its nameid. 9 | 10 | ## Installation 11 | 12 | To run the Flask app, you need to install Python 3 and the required Python packages listed in the requirements.txt file. You can install the packages using the following command: 13 | 14 | ``` 15 | pip install -r requirements.txt 16 | ``` 17 | 18 | ## Usage 19 | 20 | To start the Flask app, run the following command: 21 | 22 | ``` 23 | python main.py 24 | ``` 25 | 26 | This will start the app in debug mode. The API endpoints are: 27 | 28 | POST /api/weapon: retrieves item data for a weapon based on its name, skin, wear, and stat. 29 | POST /api/case: retrieves item data for a case based on its name. 30 | 31 | Both endpoints require a JSON object in the request body with the appropriate keys and values. If the item data is not available, the response will contain an error message. 32 | 33 | # API Documentation 34 | 35 | ## /api/weapon 36 | 37 | Returns data about a weapon skin in the game. 38 | 39 | ### Method 40 | 41 | POST 42 | 43 | ### Request Body 44 | 45 | | Parameter | Type | Description | Example | 46 | | --------- | ------- | ------------------------------------------------------------------------------------------------- | -------------- | 47 | | gun | string | The name of the weapon. | "AK-47" | 48 | | skin | string | The name of the skin for the weapon. | "Asiimov" | 49 | | wear | integer | The wear of the skin, represented by a number between 1 (Factory New) and 5 (Battle-Scarred). | 3 | 50 | | stat | integer | Whether the skin has StatTrak™ or not. 1 represents that the skin has StatTrak™, and 0 represents that it does not. | 1 | 51 | 52 | ### Example Request 53 | 54 | ```http 55 | POST /api/weapon HTTP/1.1 56 | Content-Type: application/json 57 | 58 | { 59 | "gun": "AK-47", 60 | "skin": "Redline", 61 | "wear": 3, 62 | "stat": 1 63 | } 64 | ``` 65 | 66 | Would return data for a StatTrak AK-47 | Redline (Field-Tested), such as 67 | ``` 68 | { 69 | "buy_req": 54.25, 70 | "nameid": "7180207", 71 | "sell_req": 60.79, 72 | "volume": 29 73 | } 74 | ``` 75 | 76 | ## /api/case 77 | 78 | Returns data about a case or item. The item functionality is limited and not reccommended to use. 79 | 80 | ### Method 81 | 82 | POST 83 | 84 | ### Request Body 85 | 86 | | Parameter | Type | Description | Example | 87 | | --------- | ------ | ----------------- | ---------------- | 88 | | case | string | The name of the case. | "Snakebite Case" | 89 | 90 | ### Example Request 91 | 92 | ```http 93 | POST /api/case HTTP/1.1 94 | Content-Type: application/json 95 | 96 | { 97 | "case": "Snakebite Case" 98 | } 99 | ``` 100 | 101 | Would return data for the Snakebite Case, such as 102 | ``` 103 | { 104 | "buy_req": 0.37, 105 | "nameid": "176240926", 106 | "sell_req": 0.38 107 | } 108 | ``` 109 | Note: volume data not avaliable for cases. 110 | 111 | ## TO-DO 112 | - Add proxy support (steam market ratelimit) 113 | - volume function might affect ratelimits? 114 | - Add other buy/sell orders 115 | - Make /api/case have better item functionality. 116 | -------------------------------------------------------------------------------- /main.py: -------------------------------------------------------------------------------- 1 | from flask import Flask, request, jsonify 2 | from marketdata import item_data, get_hashname 3 | 4 | app = Flask(__name__) 5 | 6 | @app.route('/api/weapon', methods=['POST']) 7 | def get_item_data(): 8 | gun = request.json['gun'] 9 | skin = request.json['skin'] 10 | wear = request.json['wear'] 11 | stat = request.json['stat'] 12 | hashname = get_hashname(gun, skin, wear, stat) 13 | try: 14 | data = item_data(hashname) 15 | return jsonify(data) 16 | except: 17 | return jsonify({"error": "Item data not available"}) 18 | 19 | @app.route('/api/case', methods=['POST']) 20 | def get_case_data(): 21 | case = request.json['case'] 22 | hashname = case.replace(' ', '%20') 23 | try: 24 | data = item_data(hashname) 25 | return jsonify(data) 26 | except: 27 | return jsonify({"error": "Item data not available"}) 28 | 29 | if __name__ == '__main__': 30 | app.run(debug=True) 31 | -------------------------------------------------------------------------------- /marketdata.py: -------------------------------------------------------------------------------- 1 | import requests 2 | 3 | def get_hashname(item, skin, wear, stat): 4 | item = item.replace(" ", "%20") 5 | skin = skin.replace(" ", "%20") 6 | float = {1: "%20%28Factory%20New%29",2: "%20%28Minimal%20Wear%29",3: "%20%28Field-Tested%29",4: "%20%28Well-Worn%29", 5:"%20%28Battle-Scarred%29"} 7 | wear = float[wear] 8 | if stat == 1: 9 | item = "StatTrak™%20"+item 10 | hashname = item + "%20%7C%20" + skin + wear 11 | return hashname 12 | 13 | def get_nameid(hashname): 14 | html = requests.get(f"https://steamcommunity.com/market/listings/730/{hashname}").text 15 | nameid = html.split('Market_LoadOrderSpread( ')[1] 16 | nameid = nameid.split(' ')[0] 17 | return int(nameid) 18 | 19 | def item_data(hashname): 20 | nameid = str(get_nameid(hashname)) 21 | out = {} 22 | order_data = (requests.get(f"https://steamcommunity.com/market/itemordershistogram?country=US¤cy=1&language=english&two_factor=0&item_nameid={nameid}").text) 23 | out["buy_req"] = int((order_data.split('\"highest_buy_order":\"')[1]).split('\"')[0])/100 24 | out["sell_req"] = int((order_data.split('\"lowest_sell_order":\"')[1]).split('\"')[0])/100 25 | try: 26 | out["volume"] = int(((requests.get(f"https://steamcommunity.com/market/priceoverview/?appid=730¤cy=1&market_hash_name={hashname}").text).split('volume\":"')[1]).split('\"')[0]) 27 | except: 28 | '' 29 | out["nameid"] = nameid 30 | return out 31 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | Flask==2.1.2 2 | requests==2.26.0 3 | --------------------------------------------------------------------------------