Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@digilabs/ngest-ig

Package Overview
Dependencies
Maintainers
2
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@digilabs/ngest-ig - npm Package Compare versions

Comparing version 1.1.1 to 1.1.2

69

lib/client/authenticat.js

@@ -24,3 +24,3 @@ 'use strict'

"method": "post",
"version": 3,
"version": 2,
"description": "Creates a trading session, obtaining session tokens for subsequent API access"

@@ -95,4 +95,4 @@ },

setEnvironment(){
let environment = (process.env.IG_ALGO_DEMO) === true ? 'dev' : 'prod';
setEnvironment() {
const environment = (typeof process.env.IG_ALGO_DEMO) === 'undefined' ? 'dev' : process.env.IG_ALGO_DEMO;
this.config_env = this.config[environment];

@@ -102,8 +102,21 @@ if (!this.config_env) throw new Error('The environment config is missing')

setAPIVersion(version){
setAPIVersion(version) {
this.apiVersion = version;
}
login() {
// check if already logged in
if (this.loggedin){
console.log('user already logged in')
return Promise.resolve('User is logged in')
}
// get credentials
if (!process.env.IG_USERNAME || !process.env.IG_PASSWORD)
return Promise.reject({
status: 403,
statusText: 'Please supply credentials'
})
let creds = {

@@ -124,14 +137,19 @@ 'identifier': process.env.IG_USERNAME,

.then(response => {
// console.log('Response from login', response)
this.loggedin = true;
return this.authenticateAddToken(response)
})
.catch(err => {
return Promise.reject({
status: err.response.status,
statusText: err.response.statusText,
method: 'PlatformIG::login',
url: err.response.config.url,
error: err.response.data.errorCode
})
console.log(err)
return Promise.reject(err)
// return Promise.reject({
// status: err.response.status,
// statusText: err.response.statusText,
// method: 'PlatformIG::login',
// url: err.response.config.url,
// error: err.response.data.errorCode
// })
})
}
/**

@@ -195,2 +213,5 @@ * Authenticates a user account

setHttpAuthHeaders(passed_headers) {
console.log("this is the current env config", this.config_env.api)
if (!process.env.IG_API_KEY)

@@ -209,6 +230,14 @@ throw new Error('No Bearer Authorisation, please set API key')

if (this.config_env.accountId) {
headers['Authorization'] = 'Bearer ' + this.config_env.api.oauth.access_token;
headers['IG-ACCOUNT-ID'] = this.config_env.accountId;
}
if (typeof this.config_env.api.oauth !== 'undefined'){
headers['Authorization'] = 'Bearer ' + this.config_env.api.oauth.access_token;
}
if (this.config_env.api.poll.XSecurityToken){
headers['X-SECURITY-TOKEN'] = this.config_env.api.poll.XSecurityToken;
headers['CST'] = this.config_env.api.poll.CST;
}
if (passed_headers && passed_headers.version) {

@@ -229,7 +258,13 @@ headers['VERSION'] = passed_headers.version

authenticateAddToken(response) {
console.log("Adding the access tokens", response.headers)
this.config_env.api.oauth = response.data.oauthToken;
this.config_env.accountId = response.data.accountId;
this.config_env.clientId = response.data.clientId;
if (!response.data.oauthToken) {
this.config_env.api.poll.CST = response.headers.cst;
this.config_env.api.poll.XSecurityToken = response.headers['x-security-token'];
// set the time of login
this.login_time = new Date().getTime() / 1000;
// this.expiry_time = this.login_time + response.data.oauthToken.expires_in;
if (!response.data.oauthToken && !this.config_env.api.poll.CST) {
return Promise.reject('Login tokens not present')

@@ -257,3 +292,3 @@ }

return new Promise( (resolve, reject) => {
return new Promise((resolve, reject) => {
let options = {

@@ -293,3 +328,3 @@ method: IG_ENDPOINTS.watchlists.action.get.method,

method: IG_ENDPOINTS.watchlists.action.get.method,
url: IG_ENDPOINTS.watchlists.endpoint + '/'+id,
url: IG_ENDPOINTS.watchlists.endpoint + '/' + id,
baseURL: this.getBaseUrl(),

@@ -304,3 +339,2 @@ // data: creds,

getBaseUrl() {
console.log('returning base url')
return (this.environment !== 'prod') ? 'https://demo-api.ig.com/gateway/deal' : 'https://api.ig.com/gateway/deal';

@@ -321,2 +355,3 @@ }

.then(res => {
// console.log(res)
return Promise.resolve(res.data)

@@ -323,0 +358,0 @@ })

{
"name": "@digilabs/ngest-ig",
"version": "1.1.1",
"version": "1.1.2",
"description": "IG API nodejs client",

@@ -5,0 +5,0 @@ "main": "index.js",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc