import statistics
import requests
API = "https://api.cspriceapi.com"
KEY = "YOUR_API_KEY"
HEADERS = {"Authorization": f"Bearer {KEY}"}
CASH_MARKETS = ("youpin", "buff163", "skinport", "skinbaron", "csfloat", "dmarket")
def price_batch(names: list[str]) -> dict:
r = requests.post(
f"{API}/v1/prices/latest",
headers=HEADERS,
json={"items": names, "markets": ",".join(CASH_MARKETS)},
timeout=60,
)
r.raise_for_status()
return r.json()
def listing_median(rows: list[dict], name: str, phase: str | None) -> float | None:
prices = []
for market_block in rows if isinstance(rows, list) else [rows]:
for item in market_block.get("items", []):
if item.get("market_hash_name") != name:
continue
if (item.get("doppler_phase") or None) != (phase or None):
continue
p = item.get("price")
if p is not None:
prices.append(float(p))
return statistics.median(prices) if prices else None
# inventory = [{"name": "...", "qty": 1, "phase": None}, ...]
Extend with: FX conversion (CNY→USD/EUR), fee tables, and buyorder join.