Get free balance available in the list
Question:
json data is coming from the remote server with ccxt.
How can I get the current balance of "NEO" in it?
def check_balance(symbol):
balance = exchange.fetch_balance()
sonuc = balance['info']['balances']
print(type(sonuc))
return check_balance
type = list
[
{'asset': 'BTC', 'free': '0.00000000', 'locked': '0.00000000'},
{'asset': 'LTC', 'free': '0.00000000', 'locked': '0.00000000'},
{'asset': 'ETH', 'free': '0.00000000', 'locked': '0.00000000'},
{'asset': 'NEO', 'free': '0.00000000', 'locked': '0.00000000'}
]
Answers:
Loop through the list and search for NEO
def find_asset(asset_str, asset_list):
for asset in asset_list:
if asset['asset'] == asset_str:
return asset
print(find_asset("NEO", my_list))
Something like this:
for i in sonuc:
if i['asset'] == 'NEO':
print(i['free'],i['locked'])
Here is one liner for that
neo_balance = next((sub for sub in source if sub['asset'] == 'NEO'), None)
json data is coming from the remote server with ccxt.
How can I get the current balance of "NEO" in it?
def check_balance(symbol):
balance = exchange.fetch_balance()
sonuc = balance['info']['balances']
print(type(sonuc))
return check_balance
type = list
[
{'asset': 'BTC', 'free': '0.00000000', 'locked': '0.00000000'},
{'asset': 'LTC', 'free': '0.00000000', 'locked': '0.00000000'},
{'asset': 'ETH', 'free': '0.00000000', 'locked': '0.00000000'},
{'asset': 'NEO', 'free': '0.00000000', 'locked': '0.00000000'}
]
Loop through the list and search for NEO
def find_asset(asset_str, asset_list):
for asset in asset_list:
if asset['asset'] == asset_str:
return asset
print(find_asset("NEO", my_list))
Something like this:
for i in sonuc:
if i['asset'] == 'NEO':
print(i['free'],i['locked'])
Here is one liner for that
neo_balance = next((sub for sub in source if sub['asset'] == 'NEO'), None)