Check out this preliminary code snippet for a DataHub structure. Essentially it takes in two arguments, exchanges which is array of exchanges needed, and pairs which is a array of pairs. It also takes in 'all' for either argument to create a structure with all of the pairs/exchanges.
// Info for available pairs in each exchange (needs to be filled out)
var info = {
poloniex : {
BTCUSD : "USDT_BTC",
ETHBTC : "BTC_ETH"
},
gdax : {
BTCUSD : "BTC-USD",
ETHBTC : "ETH-BTC"
},
kraken : {
BTCUSD : "XXBTZUSD",
ETHBTC : "XETHXXBT"
},
bitfinex : {
BTCUSD : "BTCUSD",
ETHBTC : "ETHBTC"
}
}
// Base order book constructor
let orderbook = function orderbook(pair) {
return {
pair : pair,
last30Day : [],
currTopOrderBook : [],
OrderBook : {}
}
}
// Exchanges constructer
let subSetExchs = function subSetExchs (exchanges, pairs){
var Exchs = {};
if (exchanges == 'all'){
exchanges = ["poloniex", "gdax", "kraken", "bitfinex"];
}
for (var i=0; i<exchanges.length ; i++){
if (info[exchanges[i]]){
Exchs[exchanges[i]] = subSetExch(exchanges[i], pairs);
}
}
return Exchs;
}
// Single exchange constructor
let subSetExch = function subSetExch (exchange, pairs){
var Exch = {};
if (pairs == 'all'){
pairs = [];
var i = 0;
for (var key in info[exchange]){
if (info[exchange].hasOwnProperty(key)) {
pairs[i] = key;
i++;
}
}
}
for (var i=0; i<pairs.length ; i++){
if (info[exchange][pairs[i]]){
Exch[pairs[i]] = orderbook(info[exchange][pairs[i]]);
}
}
return Exch;
}
var exchanges = subSetExchs("all", "all");
{ poloniex:
{ BTCUSD:
{ pair: 'USDT_BTC',
last30Day: [],
currTopOrderBook: [],
OrderBook: {} },
ETHBTC:
{ pair: 'BTC_ETH',
last30Day: [],
currTopOrderBook: [],
OrderBook: {} } },
gdax:
{ BTCUSD:
{ pair: 'BTC-USD',
last30Day: [],
currTopOrderBook: [],
OrderBook: {} },
ETHBTC:
{ pair: 'ETH-BTC',
last30Day: [],
currTopOrderBook: [],
OrderBook: {} } },
kraken:
{ BTCUSD:
{ pair: 'XXBTZUSD',
last30Day: [],
currTopOrderBook: [],
OrderBook: {} },
ETHBTC:
{ pair: 'XETHXXBT',
last30Day: [],
currTopOrderBook: [],
OrderBook: {} } },
bitfinex:
{ BTCUSD:
{ pair: 'BTCUSD',
last30Day: [],
currTopOrderBook: [],
OrderBook: {} },
ETHBTC:
{ pair: 'ETHBTC',
last30Day: [],
currTopOrderBook: [],
OrderBook: {} } } }