So I Have a set of dicts (this is a sample) see the code below for the full set
{
"XETHXXBT": {
"altname": "ETHXBT",
"wsname": "ETH/XBT",
"aclass_base": "currency",
"base": "XETH",
"aclass_quote": "currency",
"quote": "XXBT",
"lot": "unit",
"pair_decimals": 5,
"lot_decimals": 8,
"lot_multiplier": 1,
"leverage_buy": [
2,
3,
4,
5
],
"leverage_sell": [
2,
3,
4,
5
],
"fees": [
[],
[],
[],
[],
[],
[],
[],
[],
[]
],
"fees_maker": [
[],
[],
[],
[],
[],
[],
[],
[],
[]
],
"fee_volume_currency": "ZUSD",
"margin_call": 80,
"margin_stop": 40,
"ordermin": "0.005"
},
"XXBTZUSD": {
...
"ordermin": "0.0002" }}
I would like to return the full dict when a key within matches.
I keep running into key errors when using:
import krakenex
kex = krankenex.API()
assets = kex.query_public('AssetPairs')
a = {x for x in assets if assets[x]['wsname'] == 'XBT/USD'}
I thought this was the 'pythonic' way of doing this sort of thing, but perhaps I am missing a step?
As per comment from @He3lixxx this seems to do the trick
a = {x for x in assets.keys() if assets[x].get('wsname') == 'XBT/USD'}
And is there a good general advice tag for answers because I should definitely be better about using try/except blocks?