1

I'm trying to get certain data from a json link: bittrex.com/api/v1.1/public/getticker?market=BTC-DRS

in my node IRC bot using: https://www.npmjs.org/package/node.bittrex.api

Part of the code:

var url = ('https://bittrex.com/api/v1.1/public/getticker?market=BTC-DRS');

bittrex.options({
    'apikey' : settings.ticker.apikey,
    'apisecret' : settings.ticker.secretkey,
    'stream' : false,
    'verbose' : false,
    'cleartext' : true,
});
   case 'ticker':
    var user = from.toLowerCase();
    bittrex.sendCustomRequest(url, function(ticker, err) {
    if(err) {
      winston.error('Error in !ticker command.', err);
      client.say(channel, settings.messages.error.expand({name: from}));
      return;
    }
    winston.info('Fetched Price From BitTrex', ticker);
    client.say(channel, settings.messages.ticker.expand({name: user, price: ticker}));
   });
   break;

It works but outputs in IRC

[1:21am] <nrpatten> !ticker
[1:21am] <DRSTipbot> nrpatten The current DRS price at BitTrex {"success":true,"message":"","result":{"Bid":0.00000155,"Ask":0.00000164,"Last":0.00000155}}

I have used a couple of things to get it to show only "Last" from the reply but i keep getting errors.

Or get certain data from https://bittrex.com/api/v1.1/public/getmarketsummaries

Like any info i want from:

{"MarketName":"BTC-DRS","High":0.00000161,"Low":0.00000063,"Volume":280917.11022708,"Last":0.00000155,"BaseVolume":0.33696054,"TimeStamp":"2014-10-04T15:14:19.66","Bid":0.00000155,"Ask":0.00000164,"OpenBuyOrders":33,"OpenSellOrders":138,"PrevDay":0.00000090,"Created":"2014-06-18T04:35:38.437"}

Thanks for any help

1 Answer 1

1

Assuming you've parsed the JSON (e.g. via JSON.parse(str);), you just use whatever property name you want to get at. For example:

var info = JSON.parse('{"MarketName":"BTC-DRS","High":0.00000161,"Low":0.00000063,"Volume":280917.11022708,"Last":0.00000155,"BaseVolume":0.33696054,"TimeStamp":"2014-10-04T15:14:19.66","Bid":0.00000155,"Ask":0.00000164,"OpenBuyOrders":33,"OpenSellOrders":138,"PrevDay":0.00000090,"Created":"2014-06-18T04:35:38.437"}');
console.log(info.Bid);

Also, on an unrelated matter, typically callback parameters follow the error-first format (e.g. (err, result) instead of (result, err)) in order to be consistent with node core and most other modules on npm.

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.