0

I m trying to use the node-binance-api to retreive cryptocurency value.

I am able to get the information and display it in the node console.

Im doing so like this;

var express = require('express');
var app = express(); 
var mongo = require('mongodb');
var db = require('mongojs')("mongodb://URL")
var nodeBinanceApi = require("node-binance-api");



const binance = require('node-binance-api')().options({
  APIKEY: '***',
  APISECRET: '***',
  useServerTime: true, // If you get timestamp errors, synchronize to server time at startup
  test: true // If you want to use sandbox mode where orders are simulated
});

app.use(function(req, res, next) {
  res.header("Access-Control-Allow-Origin", "*");
  res.header("Access-Control-Allow-Methods", "GET,PUT,POST,DELETE");
  res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
  next();
});

binance.prices((error, ticker) => {
  console.log("Price: ", ticker);         <--------------------------
  console.log("Price of BTC: ", ticker.BTCUSDT);
  });

 app.use(express.static(__dirname + '/www'));

app.listen(81);

I would like to pass the json information in ticker to my scope in another script on the page. Should i use routes? and the use get request in the scope?

It does work with routes!

I added

app.get('/crypto', function(req, res){
  //calling the function
  binance.prices((error, ticker) => {

    res.jsonp(ticker);
    console.log(ticker);
    });

  return;

  });

Now I can see the prices of all cryptosurrency on my page!

Estus Flask
  • 206,104
  • 70
  • 425
  • 565
MadeInDreams
  • 1,991
  • 5
  • 33
  • 64

0 Answers0