JSPM

ig-connect

0.0.2
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • 0
  • Score
    100M100P100Q34251F
  • License MIT

Barebones IG API wrapper based on fetch() and Lightstreamer

Package Exports

  • ig-connect
  • ig-connect/ig.js

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (ig-connect) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

IG API

A barebones IG API wrapper based on fetch() and Lightstreamer.

Installation

npm i ig-connect

Usage

import IG from 'ig-connect';

const demoMode = true;
const ig = new IG('API_KEY', 'ACCOUNT_IDENTIFIER', 'ACCOUNT_PASSWORD', demoMode);

// Arbitrary Requests
const positionsResponse = await ig.request(2, 'GET', '/positions');
const { positions } = await positionsResponse.json();

const updatePositionResponse = await ig.request(2, 'PUT', `/positions/otc/{DEAL_ID}`, {
  limitLevel: 1.2345,
  stopLevel: 1.3456,
});

// Streaming Prices
// 1. Initialise a streaming client
const streamer = await ig.streamer({
  serverError: (code, message) => {
    console.error('Server error', code, message);
  },
  listenStart: () => {
    console.log('Streamer listening');
  },
  statusChange: (status) => {
    if (status === 'CONNECTED:WS-STREAMING') {
      console.log('Streamer connected');
    }
  },
}

// 2. Subscribe to price updates stream
ig.stream(streamer, 'MERGE', ['MARKET:CS.D.EURUSD.TODAY.IP'], ['BID', 'OFFER'], {
  subscriptionError: (code, message) => {
    console.error('Subscription error', code, message);
  },
  itemUpdate: (name, data) => {
    const { BID, OFFER } = data;
    console.log('Price Changed', name, BID, OFFER);
  },
});