Jump to content
  • 0

Error when using Schopenhauer API wrapper with NodeJS


Guest JohnRC

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
Link to comment

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

Link to comment
  • 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.

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Posts

    • In this buoyant market with Bitcoin hitting $42,000 and Ethereum reaching $2,200, there's a risk of getting swept up in the excitement fueled by wealth screenshots shared online. However, after impulsive investments, many realize they might still be at a loss, far from outperforming Bitcoin or Ethereum. Here are key takeaways to survive a bull market gleaned from over six years of experience: 01 Few Profits in a Bull Market A bull market implies rising cryptocurrency prices, driven by an optimistic outlook. Yet, making profits is not for everyone. Regardless of positive news or technology, price surges happen when buying outpaces selling. Bull markets inflate numbers but only a few benefit. 02 Preventing Bull Market Missteps In this evolving industry, new narratives emerge with each market rally, driving interest. To navigate: - New Narratives: Expect new storylines; innovation typically starts on-chain. Current trends hint at Bitcoin's ecosystem and various emerging concepts. - Consensus and Open-mindedness: Consensus drives interest. Keeping an open mind is crucial to understand new narratives. - Identifying Leaders: Market cap often defines leadership, but sectors may lack clear leaders or witness transitions. - Top Institutional Trends: Monitoring top institutions' moves is crucial, although they might influence the market significantly. 03 Pitfalls to Avoid Despite market surges, human impulses persist. Here are key pitfalls: - Leveraged Contracts: Playing these is risky; initial success may lead to overconfidence, resulting in significant losses. - All-In Attitude: Don't exhaust your capital; respect the market and learn from past market crashes. - Frequent Trading: Emotional trading often results in losses; patience is vital. - Following Trends Blindly: Avoid blindly following trends; understanding the project you're investing in is crucial. .Surviving a bull market isn't about picking money off the ground; it's about staying steady and avoiding pitfalls in an enticing yet volatile landscape.
    • Name of stock - Aura Minerals Name of Stock Exchange - Canada Leverage or Share dealing - Leverage Ticker - ORA Country of the stock - Canada Market Cap - 750M
    • SP500, NASDAQ, DAX 40, FTSE 100, ASX200. Elliott Wave Insights & Strategies  Summary:  US Indices Wave 2 retracement in progress and we will look to buy the low of wave 2 in due course. The SP500, Nasdaq 100, Russell 200 and the DAX 40 have this pattern. The FTSE 100 and the ASX 200 have different patterns, however these markets will follow the same intraday moments as the US Indices within reason and will also look to build long positions in the same timing of the US Indices and ETFs. Stocks: Two types of patterns occurring in these stocks. The stocks that have dropped a lot are still in their b) wave rally and will continue into the next session. Then there are the AAPL's that have made a new high. The main point is there are no decent trends occurring in the next session. Video Chapters 00:00 SP 500 (SPX)  10:56 NASDAQ (NDX) 17:27 Russell 2000 (RUT) 18:55 DAX 40 (DAX) 21:55 FTSE 100 UKX (UK100) 27:25 ASX 200 (XJO) 41:24 End Analyst Peter Mathers TradingLounge™ Australian Financial Services Licence - AFSL 317817 Source: tradinglounge com   Access Trial #sp500 #nasdaq100   
×
×
  • Create New...
us