Node.js API wrapper for altcoin exchange

+1 vote

I'm trying to make a simple market maker bot and i need to use the variables bid, ask and spread in other functions to calculate what kind of buy/sell orders to create. How would i pass these variables along? Also how come i'm able to subtract (ask - bid) and not add like (bid + 0.001)

NPM poloniex.js

    function getSpread() {

    poloniex.getTicker(function(err, data){
    if (err){
        console.log('ERROR', err);
        return;
    }

    var ask = data.BTC_LTC.lowestAsk;
    var bid = data.BTC_LTC.highestBid;
    var spread = ((ask - bid) / ask);

    console.log('Ask:', ask,'Bid:', bid,'Spread:', spread); 

    });
}
Sep 10, 2018 in Blockchain by slayer
• 29,300 points
131 views

1 answer to this question.

0 votes

In order to pass these variables to a separate function, you may do something like this -

var calculateOrder = function (bid, ask, spread) {
    // Use variables
}

function getSpread() {
    poloniex.getTicker(function(err, data) {
        if (err){
            console.log('ERROR', err);
            return;
        }

        var ask = data.BTC_LTC.lowestAsk;
        var bid = data.BTC_LTC.highestBid;
        var spread = ((ask - bid) / ask);

        calculateOrder(bid, ask, spread);

    });
}

You should always convert lowestAsk and highestBid to numbers before doing mathematical operations on them

var ask = Number(data.BTC_LTC.lowestAsk);
var bid = Number(data.BTC_LTC.highestBid);
answered Sep 10, 2018 by digger
• 26,680 points

Related Questions In Blockchain

+1 vote
1 answer

Node.js blockchain bitcoin api

The callback URL should be the one ...READ MORE

answered Sep 10, 2018 in Blockchain by slayer
• 29,300 points
340 views
0 votes
0 answers

Is there any API for ether sent transaction in ethereum without using web3.js

I want to do a transaction (sent ...READ MORE

Jun 17, 2019 in Blockchain by vishal tyagi
394 views
+3 votes
2 answers

How to run ethereumjs using Node.JS

You need to install testrpc globally on ...READ MORE

answered Mar 27, 2018 in Blockchain by ned_crew
• 1,620 points
326 views
0 votes
1 answer

Protocols used in a distributed/dlt system for the nodes to establish communication

yes all are over TCP/IP connections secured by TLS encryption in hashgraph architecture-hashgraph, ...READ MORE

answered Aug 6, 2018 in Blockchain by aryya
• 7,400 points
317 views
0 votes
1 answer

Truffle tests not running after truffle init

This was a bug. They've fixed it. ...READ MORE

answered Sep 11, 2018 in Blockchain by Christine
• 15,810 points
434 views
0 votes
1 answer
0 votes
1 answer

How to add https security for Node js?

You need to add the key and cert to the createServer function. const options ...READ MORE

answered Aug 10, 2018 in Blockchain by digger
• 26,680 points
119 views
0 votes
1 answer

What do I import for SHA encryption in Node.js?

var sha = require('sha.js'); //... getHash() { ...READ MORE

answered Sep 21, 2018 in Blockchain by digger
• 26,680 points
243 views