Jump to content
  • 0

Error when using Schopenhauer API wrapper with NodeJS


Guest JohnRC

Question

Posted

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.

2 answers to this question

Recommended Posts

Posted

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....

Posted

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.

Archived

This topic is now archived and is closed to further replies.

  • image.png

  • Posts

    • Movement (MOVE) introduces the first MEVM (Move + EVM) ZK Layer 2 solution on Ethereum. It combines the security of MoveVM with Ethereum’s liquidity and user base.     Key Highlights: Lightning-fast speeds: 145,000 TPS Subsecond finality with low gas fees Secure, cost-effective smart contracts     Could this be the future of blockchain scalability? You can join as we explore on BingX.
    • Bitcoin has reached an unprecedented $104,000, marking a significant moment in its history. The surge is attributed to institutional adoption, such as BlackRock’s Bitcoin ETF success, positive geopolitical developments, and the deflationary effects of Bitcoin's halving cycle. These factors underscore Bitcoin’s growing importance as a global store of value and financial tool.   Fractal Bitcoin complements this growth by expanding Bitcoin’s scalability while adhering to its core principles of decentralization and transparency. The bullish momentum of its FB token, backed by it's active community got the project to be bullish, and since after it's listing the price of FB in the market has been performing extremely well, and most investors in the community are using their DCA strategy to ape more tokens.   FB is trading on bingx spot market, coupled by an ongoing carnival event that will be shared among traders that consists of 1,666 tokens for the community bullish and have decided to get their hands on some free tokens. Use this link to trade FB Trade $FB here.  
    • With Bitcoin finally surpassing the much awaited $100k hallmark, all indication points to the much-awaited bull-run. I attended an X space recently and one of the speakers highlighted that the bull-run has already started when Bitcoin surpassed it previous ATH. He noted that is normal for many people not to notice it since Eth is yet to reclaim Ath but with the like of Sol, BNB, BGB and setting a new all-time high show make it clearer. He highlights that the most surprising token was BGB, which rose from $0.5 to $2.7 and still showing signs of hitting $5. He made few assumptions that made the token achieve that hallmark before swiftly making some bold predictions that once Eth reclaim ATH then we should expect much volatility in the industry . One of the speaker claimed that the bull cycle is always short while the bear cycle is mostly longer. He said that Bitcoin normally set an all time high after swearing in of new US presidential candidate and he predicted that with the new president full support for Crypto we might see the longest bear market in the history. I have seen a lot of predictions that the mother token could hit over $200k in 2025 but what factors could push this.
×
×
  • Create New...
us