Skip to content

Instantly share code, notes, and snippets.

@m-root
Created April 14, 2018 19:27
Show Gist options
  • Save m-root/8c53bdebf0b779b5d28944e31a9cedd6 to your computer and use it in GitHub Desktop.
Save m-root/8c53bdebf0b779b5d28944e31a9cedd6 to your computer and use it in GitHub Desktop.
How to get specific key values from a list with a dictionary in it. I do hope that it helps someone.
sd = [{'id': 'e270648a-d4c3-4c04-8bb8-65fbb304d6c8', 'price': '9060.00000000', 'size': '0.20000000', 'product_id': 'BTC-USD', 'side': 'sell', 'type': 'limit', 'time_in_force': 'GTC', 'post_only': True, 'created_at': '2018-03-22T03:34:41.985706Z', 'fill_fees': '0.0000000000000000', 'filled_size': '0.00000000', 'executed_value': '0.0000000000000000', 'status': 'open', 'settled': False},
{'id': '8c13b41f-2037-4a6a-b7e2-f02e06c3b10e', 'price': '9238.58000000', 'size': '0.50000000', 'product_id': 'BTC-USD', 'side': 'sell', 'type': 'limit', 'time_in_force': 'GTC', 'post_only': True, 'created_at': '2018-03-14T04:03:01.41252Z', 'fill_fees': '0.0000000000000000', 'filled_size': '0.00000000', 'executed_value': '0.0000000000000000', 'status': 'active', 'settled': False},
]
for i in range(len(sd)):
if sd[i].get('price') and sd[i].get('status')=='active':
entryPrice = sd[i].get('price')
entryPrice = float(entryPrice)
if entryPrice > 9100:
fd = sd[i].get('id')
print(entryPrice)
print(fd)
###############################################################################################################
sd = [{'id': 'e270648a-d4c3-4c04-8bb8-65fbb304d6c8', 'price': '9060.00000000', 'size': '0.20000000', 'product_id': 'BTC-USD', 'side': 'sell', 'type': 'limit', 'time_in_force': 'GTC', 'post_only': True, 'created_at': '2018-03-22T03:34:41.985706Z', 'fill_fees': '0.0000000000000000', 'filled_size': '0.00000000', 'executed_value': '0.0000000000000000', 'status': 'open', 'settled': False},
{'id': '8c13b41f-2037-4a6a-b7e2-f02e06c3b10e', 'price': '9238.58000000', 'size': '0.50000000', 'product_id': 'BTC-USD', 'side': 'sell', 'type': 'limit', 'time_in_force': 'GTC', 'post_only': True, 'created_at': '2018-03-14T04:03:01.41252Z', 'fill_fees': '0.0000000000000000', 'filled_size': '0.00000000', 'executed_value': '0.0000000000000000', 'status': 'active', 'settled': False},
]
for i , dict in enumerate(sd):
if sd[i].get('price') and sd[i].get('status')=='active':
entryPrice = sd[i].get('price')
entryPrice = float(entryPrice)
if entryPrice > 9100:
fd = sd[i].get('id')
print(entryPrice)
print(fd)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment