1

I have the following the function:

price = client.futures_recent_trades(symbol="BTCUSDT", limit=1)

of type <class 'list'> that has output:

[{'id': 1644406868, 'price': '58024.69', 'qty': '0.009', 'quoteQty': '522.22', 'time': 1637262411652, 'isBuyerMaker': False}]

and:

I want to return price value only : 'price': '58024.69' and therefore,

print(len(price))=1 but print(len(price[0]))= 6

But when I tried price[0][1], it throws an error list index out of range

2
  • 1
    price[0].price since price is a list of dictionaries/objects, price should be renamed to something like trades then it would be trades[0].price which would make more sense Commented Nov 18, 2021 at 19:12
  • price[0]["price"] Commented Nov 18, 2021 at 19:14

3 Answers 3

3

It's a dictionary within a list, so you should pass the key for the second index, like shown below.

price[0]['price']
Sign up to request clarification or add additional context in comments.

Comments

2
>>> list(price[0].items())[1]
('price', '58024.69')

Comments

0

thisdict = dict(price)

x = thisdict.get("price")

print("price: " + x)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.