const { TapClient } = require("liquid-tap");
var tap = new TapClient({
auth: { tokenId: token_id, tokenSecret: token_secret }
});
var protected_channel = tap.subscribe("user_account_usd_trades");
rotected_channel.bind("updated", function(data) {
console.log("Trades Updated: ", data);
});
const pricebook_channel = tap.subscribe("price_ladders_cash_btcjpy");
const orders_channel = tap.subscribe("user_account_jpy_orders");
const trades_channel = tap.subscribe("user_account_usd_trades");
const executions_channel = tap.subscribe("user_executions_cash_btcjpy");
/* javascript - using raw websockets */
const jwt = require('jwt-simple');
var authPayload = {
token_id: 1234,
path: '/realtime',
nonce: Date.now()
};
var tokenSecret = '<token_secret>';
const authRequest = {
headers: {
'X-Quoine-Auth': jwt.encode(authPayload, tokenSecret)
},
path: '/realtime'
}
const ws = new WebSocket('wss://tap.liquid.com/app/LiquidTapClient');
ws.onmessage = (message) => {
const wsEvent = JSON.parse(message.data);
switch(wsEvent.event){
case 'pusher:connection_established':
console.log('Connected');
ws.send(JSON.stringify({ "event":"quoine:auth_request", "data": authRequest }));
break;
case 'quoine:auth_success':
console.log('Authenticated');
ws.send(JSON.stringify({"event":"pusher:subscribe","data":{"channel":"user_account_usd_trades"}}));
break;
case 'quoine:auth_failure':
console.log('Auth failed');
break;
case 'pusher_internal:subscription_succeeded':
console.log('Subscribed: ' + wsEvent.channel);
case 'updated':
console.log('Trades Updated: ', wsEvent.data);
}
}