I wrote "def" that it fetch contracts like below:
instruments =send_request(.......)
contractdict = dict()
if instruments is not None:
for s in instruments['data']:
contractdict [s['symbol']] = Contract(s, "bingx")
And it works correctly.
Now I write another "def" like this, but I want to fetch 'asset', I put it below:
margindata =send_request(.......)
balancedic = dict()
if margindata is not None:
for b in margindata ['balance']:
balancedic [b['asset']] = balance(b, "bingx")
But, it has type error!
TypeError: string indices must be integers, not 'str'
Send_request in both the above functions will return the correct answer.
I also put the reference link below:
I also test to change 'key' name such as 'asset','data','balance', but they are wrong too.
Please tell me how to fetch every fields of margindata dictionary like instruments.
***I not used any library like ccxt,... .
You are sending a request to
/openApi/swap/v2/user/balanceendpoint. Which returns a json response that looks like this:Please note that if you are trading perpetual futures, then opening a position would not add that symbol to your perpetual balance.
I suppose this would solve your issue: