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,389
    • Total Posts
      28,409
    • Total Members
      37,292
    Newest Member
    LordEarlo
    Joined 21/03/19 09:02
  • Our picks

    • APAC brief - 21 Mar
      Market action proves it again: this market hinges on the Fed: The US Fed has proven itself as the most important game in town for traders. The FOMC met this morning, and lo-and-behold: the dovish Fed has proven more dovish than previously thought; the patient Fed has proven more patient that previously thought. Interest rates have remained on hold, but everyone knew that was to be the case today. It was about the dot-plots, the neutral-rate, the economic projections, and the balance sheet run-off. On all accounts, the Fed has downgraded their views on the outlook. And boy, have markets responded. The S&P500 has proven its major-sensitivity to FOMC policy and whipsawed alongside a fall in US Treasury yields, as traders price-in rate cuts from the Fed in the future.


      The US Dollar sends some asset classes into a tizz: The US Dollar has tumbled across the board consequently, pushing gold prices higher. The Australian Dollar, even for all its current unattractiveness, has burst higher, to be trading back toward the 0.7150 mark. Commodity prices, especially those of thriving industrial metals, have also rallied courtesy of the weaker greenback. Emerging market currencies are collectively stronger, too. This is all coming because traders are more-or-less betting that the Fed is at the end of its hiking cycle, and financial conditions will not be constricted by policy-maker intervention. Relatively cheap money will continue to flow, as yields remain depressed, and allow for the (sometimes wonton) risk-taking conditions that markets have grown used to in the past decade.
        • Great!
        • Like
      • 0 replies
×
×