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,050 points
23 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
• 27,630 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,050 points
89 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 in Blockchain by vishal tyagi
28 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
127 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 ariaholic
• 7,340 points
63 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,790 points
126 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
• 27,630 points
35 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
• 27,630 points
89 views