0

Say this is the response

{
  "symbol": "LTCBTC",
  "bidPrice": "4.00000000",
  "bidQty": "431.00000000",
  "askPrice": "4.00000200",
  "askQty": "9.00000000"
}

how would I store only 4.00000200 from the askPrice as a variable, so I can perform math on later?

The answers in the other question do not explain how to store the response. They explain how to get parts of it once you have already stored it.

blahahaaahahaa
  • 195
  • 1
  • 9

3 Answers3

1

You can get your response in a variable like this. you can fetch every data of resopnse in a obtdata

var obtdata = { 
  "symbol": "LTCBTC",
  "bidPrice": "4.00000000",
  "bidQty": "431.00000000",
  "askPrice": "4.00000200",
  "askQty": "9.00000000"
}

var symbol = obtdata.symbol
var bidPrice =obtdata.bidPrice
var bidQty =obtdata.bidQty
var askPrice =obtdata.askPrice
var askQty =obtdata.askQty

For more information you can go this link

Vaish
  • 21
  • 7
0

You can access object response object property by object_name.property

Like let price = response.askPrice

Varis Bhalala
  • 123
  • 11
0

JavaScript is async, you need to use async / await, or a callback to get the data after it has been received:

async function getData(){
    var obtdata = await binanceRest.bookTicker({symbol: 'BTCUSDT'})
    var symbol = obtdata.symbol
    var bidPrice = obtdata.bidPrice
    var bidQty = obtdata.bidQty
    var askPrice = obtdata.askPrice
    var askQty = obtdata.askQty

    console.log(askPrice);
}

Using callback function:

 binanceRest.bookTicker({symbol: 'BTCUSDT'},(obtdata)=>{
    var symbol = obtdata.symbol
    var bidPrice = obtdata.bidPrice
    var bidQty = obtdata.bidQty
    var askPrice = obtdata.askPrice
    var askQty = obtdata.askQty

    console.log(askPrice);
})
Gaurav Punjabi
  • 153
  • 1
  • 6