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  

  • IG ISA Season

  • Member Statistics

    • Total Topics
      6,421
    • Total Posts
      28,556
    • Total Members
      37,555
    Newest Member
    MaxwellIG
    Joined 25/03/19 21:20
  • Our picks

    • APAC brief 26 Mar
      Markets trade-off Friday overhang: Markets traded in something of a vacuum Monday. The themes driving price action were more-or-less those that had determined activity to end last week. The effects of this were pronounced in the Asian session, but much less so in Europe and North America. It stands to reason: Asian markets were still to digest Friday night’s abysmal European PMI figures. That data’s impact is still rippling through the market. Anxieties about global growth and the likelihood for a global recession is the topic of the day. But the material losses stemming from these concerns, though broad-based, have been limited overnight. Wall Street is down but bouncing; European stocks were down; while futures contracts for Asian markets are mixed.

      Risk-off generally prevails: Fear is demonstrably higher. On balance, safety was generally sought on Monday. In something of a bittersweet development, the VIX has pulled of its lows, to trade above 16, as traders reprice volatility and risk. In the broader G10 currency complex, the Yen has been led the pack, though its rally has steadied, and it is currently shuffling around the 110-handle. Investment grade credit spreads have widened notably, as speculation about slower growth has fanned-fear regarding the massive US corporate debt burden. And finally, the overnight-drop in the US Dollar, combined with the ubiquitous disappearance of safe-yielding assets the world-over, has pushed gold prices to $US1322 per ounce.
      • 0 replies
×
×