Printing more than one market's data from Bittrex Websocket


#1

I created a bot that sums the last orders for a given currency on Bittrex exchange, the problem is that it works on a single currency, while i want to make it work on more currencies. I tried to run it in multiple ways, but none of those works, or instead of printing one by one every market, it sums them, here is my example

Other than that, i tried making more SocketConnect and orderPrinter functions, one for each market, but it didn’t work, invoking more markets didn’t work either. Can anyone please give me some help to make it work?


#2

Which programming language are you using?

Tested here with Node.js and it seems pretty OK:

const bittrex = require('node-bittrex-api');

bittrex.options({
    'apikey': '<YOUR API KEY>',
    'apisecret': '<YOUT API SECRET>'
});

bittrex.websockets.subscribe(['BTC-ETH', 'BTC-LTC'], function (data, client) {
    if (data.M === 'updateExchangeState') {
        data.A.forEach(function (dataFor) {
            var reduceFunction = function (oldVal, curVal, index, arr) {
                return {
                    rateSum: oldVal.rateSum + curVal.Rate,
                    quantitySum: oldVal.quantitySum + curVal.Quantity
                };
            };

            var infoBuys = dataFor.Buys.reduce(reduceFunction, { rateSum: 0, quantitySum: 0 });
            var infoSells = dataFor.Sells.reduce(reduceFunction, { rateSum: 0, quantitySum: 0 });

            console.log('Currency Pair:');
            console.log('\t' + dataFor.MarketName);
            console.log('Buys:');
            console.log('\tRate:', infoBuys.rateSum);
            console.log('\tQuantity:', infoBuys.quantitySum);
            console.log('Sells:');
            console.log('\tRate:', infoSells.rateSum);
            console.log('\tQuantity:', infoSells.quantitySum);
            console.log();
            
            /* Or you can retrieve more data from the order book:
            
            bittrex.getorderbook({ market : dataFor.MarketName, depth : 10, type : 'both' }, function (data, err) {
                if (err) {
                    return console.error(err);
                }

                Do whatever you want here with the buy and sell data
            }); */
        });
    }
});

And it produced the following results, when subscribed for BTC-ETH and BTC-LTC:

$ node test1.js
Currency Pair:
	BTC-ETH
Buys:
	Rate: 0.25818521
	Quantity: 1.74551275
Sells:
	Rate: 0.14010517
	Quantity: 0.58364842

Currency Pair:
	BTC-LTC
Buys:
	Rate: 0.01672
	Quantity: 81.77470484
Sells:
	Rate: 0
	Quantity: 0

Currency Pair:
	BTC-ETH
Buys:
	Rate: 0.20303032
	Quantity: 14.329538220000002
Sells:
	Rate: 0.20972073000000002
	Quantity: 290.89204177000005

Currency Pair:
	BTC-LTC
Buys:
	Rate: 0.01672
	Quantity: 81.8093288
Sells:
	Rate: 0.033543
	Quantity: 15.6061

Currency Pair:
	BTC-ETH
Buys:
	Rate: 0.32475454
	Quantity: 1.31231688
Sells:
	Rate: 0.13971735000000002
	Quantity: 1.48

Currency Pair:
	BTC-ETH
Buys:
	Rate: 0.39629877
	Quantity: 452.81160122
Sells:
	Rate: 0
	Quantity: 0

Currency Pair:
	BTC-LTC
Buys:
	Rate: 0.049893969999999996
	Quantity: 87.27095252999999
Sells:
	Rate: 0.01676899
	Quantity: 14.1309

Currency Pair:
	BTC-ETH
Buys:
	Rate: 0.6549242900000001
	Quantity: 136.34102624
Sells:
	Rate: 0.27682345
	Quantity: 0.61127551

Currency Pair:
	BTC-LTC
Buys:
	Rate: 0.049920339999999994
	Quantity: 81.41694509
Sells:
	Rate: 0
	Quantity: 0

Currency Pair:
	BTC-ETH
Buys:
	Rate: 0.19596997
	Quantity: 3.21791245
Sells:
	Rate: 0
	Quantity: 0

Currency Pair:
	BTC-LTC
Buys:
	Rate: 0.01672
	Quantity: 81.77054382
Sells:
	Rate: 0
	Quantity: 0

Currency Pair:
	BTC-ETH
Buys:
	Rate: 0.40540757
	Quantity: 14.861831050000001
Sells:
	Rate: 0.14089794
	Quantity: 0.12297848

Currency Pair:
	BTC-LTC
Buys:
	Rate: 0.03069553
	Quantity: 0.06147971
Sells:
	Rate: 0
	Quantity: 0

Currency Pair:
	BTC-ETH
Buys:
	Rate: 0.06814997
	Quantity: 2.45154085
Sells:
	Rate: 0.14089794
	Quantity: 18.58011

And as you may notice, sometimes the Buys array comes empty, sometimes the Sells array comes empty, sometimes both arrays comes empty

The getorderbook seems to be safer, but dunno if you can flood their server sending a request every time you get a message from the websocket (even more now that they use CloudFlare). Maybe you will get banned or something like that


Bittrex bot php
#3

Sorry for the late late answer and thanks for your reply! The code I am using is Python!


#4

Using libraries like this one, it should be almost the same