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,040 points
16 views

1 answer to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
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,620 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,040 points
51 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,610 points
92 views
0 votes
1 answer

How to create tokens in smart contracts from node.js?

Any modification to the Ethereum Blockchain will ...READ MORE

answered Jun 26, 2018 in Blockchain by Shashank
• 10,330 points
94 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,320 points
42 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
60 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,620 points
26 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,620 points
65 views

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.