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,370 points
636 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,740 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,370 points
1,076 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
1,244 views
0 votes
0 answers

Node.js blockchain bitcoin api

So I want to use this: (taken ...READ MORE

Apr 4, 2022 in Blockchain by Rahul
• 9,680 points
512 views
+1 vote
1 answer

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

yes all are over TCP/IP connections secured ...READ MORE

answered Aug 6, 2018 in Blockchain by aryya
• 7,460 points
1,459 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
1,941 views
0 votes
1 answer

Hyperledger Sawtooth vs Quorum in concurrency and speed Ask

Summary: Both should provide similar reliability of ...READ MORE

answered Sep 26, 2018 in IoT (Internet of Things) by Upasana
• 8,620 points
1,467 views
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,740 points
840 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,740 points
902 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP