this is going to be a really easy question, but quite frankly I can't word it well enough to discover the answer on my own. I should be able to roll forward with an answer.
client.getWalletBalance({coin: 'ETH'})
.then(result => {
console.log(result.ETH.available_balance);
var availableBal = result;
})
.catch(err => {
console.error(err);
});
later in the code:
'wallet balance:' + availableBal + ' ETH'
TypeError: Cannot read property 'available_balance' of undefined
and
ReferenceError: availableBal is not defined
Here's the Response Example
{
"ret_code": 0,
"ret_msg": "OK",
"ext_code": "",
"ext_info": "",
"result": {
"ETH": {
"equity": 1002, //equity = wallet_balance + unrealised_pnl
"available_balance": 999.99987471, //available_balance
"used_margin": 0.00012529, //used_margin = wallet_balance - available_balance
"order_margin": 0.00012529, //Used margin by order
"position_margin": 0, //position margin
"occ_closing_fee": 0, //position closing fee
"occ_funding_fee": 0, //funding fee
"wallet_balance": 1000, //wallet balance. When in Cross Margin mod, the number minus your unclosed loss is your real wallet balance.
"realised_pnl": 0, //daily realized profit and loss
"unrealised_pnl": 2, //unrealised profit and loss
"cum_realised_pnl": 0, //total relised profit and loss
"given_cash": 0, //given_cash
"service_cash": 0 //service_cash
}
},
"time_now": "1578284274.816029",
"rate_limit_status": 98,
"rate_limit_reset_ms": 1580885703683,
"rate_limit": 100
}
essentially im trying to pick the certain part of the response, set it as a variable and reuse it later on
You've missing a .result
there.
result.result.ETH.available_balance
.
You may got confused because you variable is also named result
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.