Jump to content
  • 0
Sign in to follow this  

Error when using Schopenhauer API wrapper with NodeJS

Question

I am new to IG API so I may be making an elementary mistake.

I want to use the IG API interface into a Node-js application. I have tested my login and api key with the Streaming Companion and the API Companion and they work fine.

I have downloaded the Schopenhauer wrapper from GitHub and am trying out the example code given on the GitHub page, which is:

Quote

const IG = require('ig-markets');
const ig = new IG(key, identifier, password, isDemo);

try {
  const data = await ig.prices('CS.D.EURUSD.MINI.IP');
  console.log(data);
} catch(e) {
  console.error(e);
}

I tried the code verbatim with my login details and API key but this threw the error "await is invalid outside an async function", so I wrapped that code into a function declared as async with a call to the function like this:

Quote
 
const IG = require('ig-markets');
const ig = new IG(IG_API_KEY, IG_IDENTIFIER, IG_PASSWORD, IG_DEMO);
 
async function runx() {
    try {
        const data = await ig.prices('CS.D.EURUSD.MINI.IP');
        console.log(data);
    } catch(e) {
        console.error(e);
    }
}
 
runx();

Now it seems to run but throws this error:

Quote

TypeError [ERR_HTTP_INVALID_HEADER_VALUE]: Invalid value "undefined" for header "X-SECURITY-TOKEN"

So now I am unable to move forward. Any ideas would be much appreciated.

Edited by JohnRC

Share this post


Link to post

2 answers to this question

Recommended Posts

  • 0

It seems that the example code given is wrong.

Firstly, the parameter IG_DEMO for the call to IG is not defined in the actual ig.js code, so the system attempts to login to the live account even when the IG_DEMO is set to true;

Secondly, the URLs for the IG live and demo accounts are hard-coded, even though this is deprecated in the IG coding guidelines.

Still testing....

  • Like 1

Share this post


Link to post
  • 0

Having had some difficulty in getting this code to work I am now switching to developing a separate set of wrappers, as I need to interface to both the Dealing and Streaming APIs. So I don't need the answer to this question for now. If anyone is interested in my analysis of the issues, happy to share.

Share this post


Link to post

Join the conversation

You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
You are posting as a guest. If you have an account, please sign in.
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

  • Our picks

    • Post in Indices
      "UK retail sales at 9:30 and US durable goods at 1:30. Strong bear day yesterday though only Nikkei tested key support levels." Stay up to date on how the indices are moving and have your say.
    • Post in Successful strategy?
      Analysis of 43 million trades by DailyFX showed that 61% of trades are actually profitable (when looking at EURUSD specifically). Read more about that and check out their Podcast here. Have any questions? Ask away.
        • Thanks
        • Like
    • Brent Crude rally ends, time for the big Bear!
      "Looks to me like my question as to whether the the 25 April turn was a rally end or a simple retrace may have been answered as Brent price dropped hard through the supporting lower channel line.  I would like to see the recent lows broken to confirm but odds are that this market is now heading down.  Could this mean that Stocks have also topped out?"
      • 8 replies
    • Post in Dax & Dow
      What are your long term opinions on market movements? "As for the Dow above 26k lets rock and roll long. Below 25k time to get more aggressively short in my eyes."
        • Like
    • Post in US 500 - Potential Shorting Opportunity
      What's your trigger for opening a trade? Discuss with others on the Community, specifically about the US500: "I think there's a potential possibility of shorting S&P 500 brewing.  I want to wait to see if the 20 MA does drop beneath the 50 MA."
  • Member Statistics

    • Total Topics
      6,746
    • Total Posts
      31,157
    • Total Members
      40,996
    Newest Member
    marcorosso13
    Joined 24/05/19 14:00
  • Posts

    • A list of books on trading strategies with back test studies by reputable traders. Following the Trend – Andreas Clenow Unholy Grails – Nick Radge Dual Momentum – Gary Antonacci Mean Reversion Trading Systems – Howard Bandy Short-term trading strategies that work – Larry and Cesar Building Reliable Trading Systems – Keith F courtesy of Raynar Teo.   
    • 1 hour chart showing a bit of a nod to the downside.  Not conclusive yet but indicative.
    • @Mercury That's a very elaborate way to say, you agree with me. Your Elliot waves always look very cool and as ever great charts.
    • Brent looks to have put in a small rally and bounced back off my alternative channel line, a parallel line off the previous low turning point.  This coincides with support line, now resistance.  The market is now heading down to the 6600/6550 key support zone.  A break here is very bearish in my book.  I have started to pyramid his market.
    • BTC stickingon that 8k handle.  Worried on volumes for a mean reversion move tho
×
×