tardis-dev
Version:
Convenient access to tick-level historical and real-time cryptocurrency market data via Node.js
57 lines • 2.66 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.CoinbaseInternationalRealTimeFeed = void 0;
const crypto_1 = __importDefault(require("crypto"));
const realtimefeed_1 = require("./realtimefeed");
class CoinbaseInternationalRealTimeFeed extends realtimefeed_1.RealTimeFeedBase {
constructor() {
super(...arguments);
this._hasCredentials = process.env.COINBASE_INTERNATIONAL_API_KEY !== undefined &&
process.env.COINBASE_INTERNATIONAL_API_SECRET !== undefined &&
process.env.COINBASE_INTERNATIONAL_API_PASSPHRASE !== undefined;
}
get wssURL() {
return 'wss://ws-md.international.coinbase.com';
}
mapToSubscribeMessages(filters) {
if (this._hasCredentials == false) {
throw new Error('CoinbaseInternationalRealTimeFeed requires auth credentials env vars set(COINBASE_INTERNATIONAL_API_KEY, COINBASE_INTERNATIONAL_API_SECRET, COINBASE_INTERNATIONAL_API_PASSPHRASE)');
}
const authParams = this.getAuthParams();
return filters.map((filter) => {
if (!filter.symbols || filter.symbols.length === 0) {
throw new Error('CoinbaseInternationalRealTimeFeed requires explicitly specified symbols when subscribing to live feed');
}
return {
type: 'SUBSCRIBE',
product_ids: filter.symbols,
channels: [filter.channel],
signature: authParams.signature,
key: authParams.key,
time: authParams.time,
passphrase: authParams.passphrase
};
});
}
getAuthParams() {
const time = Date.now().valueOf() / 1000;
const apiSecret = process.env.COINBASE_INTERNATIONAL_API_SECRET;
const message = `${time}${process.env.COINBASE_INTERNATIONAL_API_KEY}CBINTLMD${process.env.COINBASE_INTERNATIONAL_API_PASSPHRASE}`;
const hmac = crypto_1.default.createHmac('sha256', Buffer.from(apiSecret, 'base64'));
const signature = hmac.update(message).digest('base64');
return {
signature,
key: process.env.COINBASE_INTERNATIONAL_API_KEY,
passphrase: process.env.COINBASE_INTERNATIONAL_API_PASSPHRASE,
time
};
}
messageIsError(message) {
return message.type === 'REJECT';
}
}
exports.CoinbaseInternationalRealTimeFeed = CoinbaseInternationalRealTimeFeed;
//# sourceMappingURL=coinbaseinternational.js.map