tlab-trading-toolkit
Version:
A trading toolkit for building advanced trading bots on the GDAX platform
42 lines (41 loc) • 1.9 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
const ProductMap_1 = require("../exchanges/ProductMap");
const BinanceFeed_1 = require("../exchanges/binance/BinanceFeed");
function getExchangeProduct(genericProduct) {
return ProductMap_1.ProductMap.ExchangeMap.get('Binance').getExchangeProduct(genericProduct);
}
/**
* Convenience function to connect to and subscribe to the given channels. Binance uses SignalR, which handles reconnects for us,
* so this is a much simpler function than some of the other exchanges' methods.
*/
function getSubscribedFeeds(options, products) {
options.products = products;
return new Promise((resolve, reject) => {
const feed = new BinanceFeed_1.BinanceFeed(options);
feed.on('websocket-connection', () => {
return resolve(feed);
});
});
}
exports.getSubscribedFeeds = getSubscribedFeeds;
/**
* This is a straightforward wrapper around getSubscribedFeeds using the Factory pattern with the most commonly used
* defaults. For customised feeds, use getSubscribedFeeds instead. It's really not adding much, but we keep it here
* to maintain a consistent method naming strategy amongst all the exchanges
*
* It is assumed that your API keys are stored in the BINANCE_KEY and BINANCE_SECRET envars
*/
function FeedFactory(logger, productIds, auth) {
auth = auth || {
key: process.env.BINANCE_KEY,
secret: process.env.BINANCE_SECRET
};
productIds = productIds.map((genericProduct) => {
console.log('Product ID', genericProduct);
return getExchangeProduct(genericProduct) || genericProduct;
});
// There are too many books on BINANCE to just subscribe to all of them, so productIds is a required param
return getSubscribedFeeds({ auth: auth, logger: logger, wsUrl: null }, productIds);
}
exports.FeedFactory = FeedFactory;