0

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

0

1 Answer 1

1

You've missing a .result there.
result.result.ETH.available_balance.

You may got confused because you variable is also named result.

Sign up to request clarification or add additional context in comments.

4 Comments

awesome, thanks. this did solve the initial question. lastly, im trying to set it as a variable instead of console logging it to reuse later. have a say? :)
let my_awsome_available_balance = result.result.ETH.available_balance? I'm not really sure what you mean.
i.imgur.com/djKyOsV.png here's a visual of what im trying to pull off
You've to put the whole stuff within the then(result => { body. client.getWalletBalance({coin: 'ETH'}) seems to be an async function this means that you'll not directly receive a result.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.