You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何从Warframe Market API返回的订单数据中提取所有价格并计算最小值

Warframe道具最低白金报价实现方案

核心修改逻辑

  • 过滤有效订单:可根据实际需求筛选order_type,如果是查询你可购买的最低报价,保留order_type="sell"(卖家挂单)、visible=True的有效订单即可,也可额外添加用户在线状态、地区、平台的过滤条件
  • 批量提取所有符合条件订单的platinum数值
  • 对价格列表取最小值输出,新增异常处理逻辑覆盖道具不存在、无有效报价的场景

完整实现代码

import requests
import json

item = input('请输入要查询的道具名称:')
format_item = item.replace(' ', '_').lower()

try:
    # 请求接口
    resp = requests.get(f'https://api.warframe.market/v1/items/{format_item}/orders?include=item')
    resp.raise_for_status() # 接口请求失败直接抛出异常
    data = resp.json()

    # 过滤有效卖单,提取价格
    sell_prices = []
    for order in data['payload']['orders']:
        # 可根据需要调整过滤条件,比如加platform='pc'、user['status']='ingame'等
        if order['order_type'] == 'sell' and order['visible'] == True:
            sell_prices.append(order['platinum'])
    
    if not sell_prices:
        print("当前没有有效卖单报价")
    else:
        min_price = min(sell_prices)
        print(f"该道具最低白金报价为:{min_price}")

except requests.exceptions.HTTPError as e:
    if resp.status_code == 404:
        print("输入的道具名称不存在,请检查名称拼写")
    else:
        print(f"接口请求失败:{e}")
except Exception as e:
    print(f"运行出错:{e}")

可选优化说明

如果需要仅查询在线玩家的报价,可以在过滤条件中添加order['user']['status'] == 'ingame';如果需要限定平台,可添加order['platform'] == 'pc'(或对应平台参数)。

内容的提问来源于stack exchange,提问作者yxxhixx

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.01 20:15:02