Skip to content

Instantly share code, notes, and snippets.

@bumi
Created April 25, 2018 15:43
Show Gist options
  • Save bumi/e9e79d62b52ea424065b9fa6741fe959 to your computer and use it in GitHub Desktop.
Save bumi/e9e79d62b52ea424065b9fa6741fe959 to your computer and use it in GitHub Desktop.
streams all bitstamp buy/sell order updates and trades
const { LiveOrderStream, TickerStream, CURRENCY } = require("node-bitstamp");
const liveOrderStream = new LiveOrderStream();
const liveOrderTopic = liveOrderStream.subscribe(CURRENCY.BTC_EUR);
liveOrderStream.on("connected", () => { console.log('connected to live orders'); });
liveOrderStream.on("disconnected", () => { console.log('disconnected'); });
liveOrderStream.on(liveOrderTopic, data => {
console.log(`${data.id}: ${data.order_type === 1 ? 'SELL' : 'BUY'} ${data.amount}@${data.price}`);
});
const tickerStream = new TickerStream();
const tickerStreamTopic = tickerStream.subscribe(CURRENCY.BTC_EUR);
tickerStream.on("connected", () => { console.log('connected to trades'); });
tickerStream.on("disconnected", () => { console.log('disconnected'); });
tickerStream.on(tickerStreamTopic, data => {
console.log(`--- TRADE: buy ID: ${data.buy_order_id} sell ID: ${data.sell_order_id} amount: ${data.amount}@${data.price_str}`);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment