Python Forum
Search a List of Dictionaries by Key-Value Pair; Return Dictionary/ies Containing KV
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Search a List of Dictionaries by Key-Value Pair; Return Dictionary/ies Containing KV
#3
Bittrex_Markets = requests.get("https://api.bittrex.com/api/v1.1/public/getmarkets").json()

Print (Bittrex_Markets)
>>>
{'success': True, 'message': '', 'result': [{'MarketCurrency': 'LTC', 'BaseCurrency': 'BTC', 'MarketCurrencyLong': 'Litecoin', 'BaseCurrencyLong': 'Bitcoin', 'MinTradeSize': 0.01686767, 'MarketName': 'BTC-LTC', 'IsActive': True, 'IsRestricted': False, 'Created': '2014-02-13T00:00:00', 'Notice': None, 'IsSponsored': None, 'LogoUrl': 'https://bittrexblobstorage.blob.core.windows.net/public/6defbc41-582d-47a6-bb2e-d0fa88663524.png'}, {'MarketCurrency': 'DOGE', 'BaseCurrency': 'BTC', 'MarketCurrencyLong': 'Dogecoin', 'BaseCurrencyLong': 'Bitcoin', 'MinTradeSize': 480.76923077, 'MarketName': 'BTC-DOGE', 'IsActive': True, 'IsRestricted': False, 'Created': '2014-02-13T00:00:00', 'Notice': None, 'IsSponsored': None, 'LogoUrl': 'https://bittrexblobstorage.blob.core.windows.net/public/a2b8eaee-2905-4478-a7a0-246f212c64c6.png'}, {'MarketCurrency': 'VDX', 'BaseCurrency': 'ETH', 'MarketCurrencyLong': 'Vodi X', 'BaseCurrencyLong': 'Ethereum', 'MinTradeSize': 300.0, 'MarketName': 'ETH-VDX', 'IsActive': True, 'IsRestricted': True, 'Created': '2019-05-23T00:41:32.987', 'Notice': None, 'IsSponsored': None, 'LogoUrl': 'https://bittrexblobstorage.blob.core.windows.net/public/3277e3cb-fe62-46df-9162-3d9ba67c521e.png'}]}




Bittrex_Get_Market_Summaries = requests.get("https://api.bittrex.com/api/v1.1/public/getmarketsummaries").json()

Print (Bittrex_Get_Market_Summaries)
>>>
{'success': True, 'message': '', 'result': [{'MarketName': 'BTC-DYN', 'High': 1.657e-05, 'Low': 1.437e-05, 'Volume': 83445.47466841, 'Last': 1.468e-05, 'BaseVolume': 1.27935571, 'TimeStamp': '2019-05-28T07:18:48.797', 'Bid': 1.437e-05, 'Ask': 1.461e-05, 'OpenBuyOrders': 42, 'OpenSellOrders': 738, 'PrevDay': 1.445e-05, 'Created': '2017-03-23T00:10:19.403'}, {'MarketName': 'USD-USDT', 'High': 1.009, 'Low': 1.00095, 'Volume': 283483.08497639, 'Last': 1.005, 'BaseVolume': 284948.3504794, 'TimeStamp': '2019-05-28T07:18:48.797', 'Bid': 1.002, 'Ask': 1.00481, 'OpenBuyOrders': 162, 'OpenSellOrders': 97, 'PrevDay': 1.00899, 'Created': '2018-05-31T13:27:08.477'}]}



Bittrex_Mrkt_0 = ((Bittrex_Markets)['result'][0])

Print (Bittrex_Mrkt_0)
>>>
{'MarketCurrency': 'LTC', 'BaseCurrency': 'BTC', 'MarketCurrencyLong': 'Litecoin', 'BaseCurrencyLong': 'Bitcoin', 'MinTradeSize': 0.01686767, 'MarketName': 'BTC-LTC', 'IsActive': True, 'IsRestricted': False, 'Created': '2014-02-13T00:00:00', 'Notice': None, 'IsSponsored': None, 'LogoUrl': 'https://bittrexblobstorage.blob.core.windows.net/public/6defbc41-582d-47a6-bb2e-d0fa88663524.png'}


Bittrex_Mrkt_Summary_0 = ((Bittrex_Get_Market_Summaries)['result'][0])

Print (Bittrex_Mrkt_Summary_0)
>>>
{'MarketName': 'BTC-DYN', 'High': 1.657e-05, 'Low': 1.437e-05, 'Volume': 83445.47466841, 'Last': 1.468e-05, 'BaseVolume': 1.27935571, 'TimeStamp': '2019-05-28T07:18:48.797', 'Bid': 1.437e-05, 'Ask': 1.461e-05, 'OpenBuyOrders': 42, 'OpenSellOrders': 738, 'PrevDay': 1.445e-05, 'Created': '2017-03-23T00:10:19.403'}


if ((Bittrex_Mrkt_0)['IsActive']) == True:
if ((Bittrex_Mrkt_0['IsRestricted'])) == False:
THEN HERE:


I need to return a dictionary from the list of dictionaries in Bittrex_Get_Market_Summaries, and I need to find that dictionary not by its index value but by it containing a 'MarketName': key value.

('\''+(Bittrex_Mrkt_0)['BaseCurrency']+'-'+(Bittrex_Mrkt_0)['MarketCurrency']+'\'')
'BTC-LTC'

That could be inserted after 'MarketName': but I don't know what to do beyond that. I'm still very new to Python. Maybe a for loop is what I'm looking for here?

In other words: I need information from BOTH of those links.

The first link gives the Active True/False and IsRestricted True/False information to the if statements.

Based on that, the Bid and Ask values are going to be pulled next for the same BTC-LTC pair.

So I can't go by the index in the list since they are totally different and will always possibly change.

I have to use 'BTC-LTC' as a way to search the second list of dictionaires, NOT the index.
Reply


Messages In This Thread
RE: Search a List of Dictionaries by Key-Value Pair; Return Dictionary/ies Containing KV - by dn237 - May-28-2019, 09:10 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Sort a list of dictionaries by the only dictionary key Calab 2 686 Apr-29-2024, 04:38 PM
Last Post: Calab
  How do I calculate a ratio from 2 numbers and return an equivalent list of about 1000 Pleiades 8 15,879 Jan-05-2024, 08:30 PM
Last Post: sgrey
  Dictionary in a list bashage 2 626 Dec-27-2023, 04:04 PM
Last Post: deanhystad
  filtering a list of dictionary as per given criteria jss 5 780 Dec-23-2023, 08:47 AM
Last Post: Gribouillis
  Search Excel File with a list of values huzzug 4 1,318 Nov-03-2023, 05:35 PM
Last Post: huzzug
  Access list of dictionaries britesc 4 1,159 Jul-26-2023, 05:00 AM
Last Post: Pedroski55
  How to add list to dictionary? Kull_Khan 3 1,072 Apr-04-2023, 08:35 AM
Last Post: ClaytonMorrison
  search a list or tuple for a specific type ot class Skaperen 8 2,027 Jul-22-2022, 10:29 PM
Last Post: Skaperen
  check if element is in a list in a dictionary value ambrozote 4 2,072 May-11-2022, 06:05 PM
Last Post: deanhystad
  Dictionary from a list failed, help needed leoahum 7 2,081 Apr-28-2022, 06:59 AM
Last Post: buran

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020