Skip to content

Subscribing to real time data

Filip Hallqvist edited this page Jul 17, 2017 · 4 revisions

NOTE: This Wiki is only for versions < 1.0.0. For 1.0.0 docs, refer to API.md.

Socket

The private API also supports subscribing to real-time data.

Usage

Follow the example below to get started.

avanza.socket.on('connect', () => {

  /**
   * 5479 is the instrumentId for Telia.
   */
  avanza.socket.subscribe('5479', ['quotes', 'brokertradesummary']);
});

avanza.socket.on('quote', data => {

  /**
   * Do something with the real-time quote data
   */
  console.info(Date.now(), 'Received quote: ', data);
});

/**
 * Authenticate as usual
 */
avanza.authenticate({
    username: 'draghimario',
    password: 'cashisking1337'
}).then(() => {

  /**
   * Initialize the socket after authentication
   */
  avanza.socket.initialize();
})

Channels

Instrument quotes quotes

This channel is mostly used for comparing one instrument with another. Receives minute-wise data regarding the instrument in question, containing current price, change, total volume traded etc.

Orderdepths orderdepths

Updates whenever a new order is received. The data consists of the best five offers, on both sides, as well as the current total volume on each side.

Trades trades

When a new trade is made, this channel updates with information regarding the trade. The data returned contains volume, price and broker, among other things.

Broker summaries brokertradesummary

Pushes data about which brokers are long/short, and also how big their current net volume is.

Positions positions

Get data about your own positions.

Orders orders

Seems like this channel is currently unused. See orderdepths instead.

Deals deals

Seems like this channel is currently unused. See trades instead.