I'm trying to get the min price for the requested item. I don't get how. Can anyone help?
import requests
import json
item = input('put your item here please : ')
gg = item.replace(' ', '_')
response_url = requests.get(f'https://api.warframe.market/v1/items/' gg '/orders?include=item')
data = json.loads(response_url.text)
price = data['payload']['orders'][0]['platinum']
print(price)
here is an example url: https://api.warframe.market/v1/items/mirage_prime_systems/orders?include=item
Here's a small sample of the data from data["payload"]["orders"]
:
{'visible': True,
'order_type': 'buy',
'quantity': 1,
'platinum': 11,
'user': {'reputation': 4,
'region': 'en',
'avatar': 'user/avatar/60e52c93a4784b00c68db129.png?558d0a9d0e4627de50c4218bda527217',
'last_seen': '2021-10-01T16:31:55.334 00:00',
'ingame_name': 'WDNMDXZLL',
'status': 'ingame',
'id': '60e52c93a4784b00c68db129'},
'platform': 'pc',
'region': 'en',
'creation_date': '2021-10-01T16:13:57.000 00:00',
'last_update': '2021-10-01T16:13:57.000 00:00',
'id': '615733c5db3f3b01febb45a4'},
{'order_type': 'sell',
'visible': True,
'platinum': 19,
'quantity': 1,
'user': {'reputation': 0,
'region': 'en',
'last_seen': '2021-10-01T19:36:31.682 00:00',
'ingame_name': 'Weshu',
'avatar': 'user/avatar/5f775345d5551401da6e613f.png?38078a7a72b95c6a3f2b34319aea3e05',
'status': 'ingame',
'id': '5f775345d5551401da6e613f'},
'platform': 'pc',
'region': 'en',
'creation_date': '2021-10-01T17:49:13.000 00:00',
'last_update': '2021-10-01T17:49:13.000 00:00',
'id': '61574a195af7c701d3bcbf74'},
we get lot of offers and lot of prices im trying to get min price of them all and display it !! thanks for help in advance
CodePudding user response:
You don't specify what you mean by "min price of them all" so I'll assume you want both the minimum buy price and the minimum sell price:
orders = data["payload"]["orders"]
min_buy_price = min(o["platinum"] for o in orders if o["order_type"] == "buy")
min_sell_price = min(o["platinum"] for o in orders if o["order_type"] == "sell")