Jump to content
  • 0

Can't access /history/transactions v2 via API


Rick

Question

I'm trying to access /history/transactions v2 via API, in order to retrieve accurate entry and exit times (not supported in v1).

I'm writing in C#, based on the API samples, but they only seem to support v1, and not the v2 documented in the Reference guide.

Anyone know how to amend the v1 code to make it support v2 ... the call in sample code is

        public async Task<IgResponse<TransactionHistoryResponse>> lastTransactionPeriod(string transactionType, string lastPeriod) 
        {
            return await _igRestService.RestfulService<TransactionHistoryResponse>("/gateway/deal/history/transactions/" + transactionType + "/" + lastPeriod, HttpMethod.Get, "1", _conversationContext);
        }

.. and yes, I did try just changing the "1" to a "2" ... I get an Error 500.

Any help most gratefully received!  This has been driving me crazy!

Link to comment

3 answers to this question

Recommended Posts

  • 0

I use the transactions endpoint in my Excel Add-in and it works well. However, as you say it need to be set to API V2 as V1 is no longer supported.

The API version needs to be set on the request header, for example:

Quote

            HttpClient client = new HttpClient();
            client.DefaultRequestHeaders.Add("Version", "2");

I would check the code where the actual request is made and make sure this is being set correctly.

I hope this helps.
 

  • Like 1
Link to comment
  • 0

Thanks for responding Andy.

Stepping through the code, the relevant section of the IG sample API code can be precised as

var client = new HttpClient();

            ...

            if (conversationContext != null)
            {
                if (conversationContext.apiKey != null)
                {
                    client.DefaultRequestHeaders.Add("X-IG-API-KEY", conversationContext.apiKey);
                }
                if (conversationContext.cst != null)
                {
                    client.DefaultRequestHeaders.Add("CST", conversationContext.cst);
                }
                if (conversationContext.xSecurityToken != null)
                {
                    client.DefaultRequestHeaders.Add("X-SECURITY-TOKEN", conversationContext.xSecurityToken);
                }
                client.DefaultRequestHeaders.Add("VERSION", version);


            }          
            //This only works for version 1 !!!           
            //client.DefaultRequestHeaders.TryAddWithoutValidation("version", version ?? "1");

            ...

            var response = new HttpResponseMessage();
            string content = null;

            switch (method.Method)
            {
                case "POST": ...

                case "GET":
                    var myGetTask = client.GetAsync(_baseUrl + uri);
                    response = myGetTask.Result;                                 
                    break;

This returns transaction data quite happily using Version 1 of the interface (but without the additional V2 data), but errors if I try to run it with Version=2 ...

image.thumb.png.47a7f5cd0a93873ac2e7c49c603463d4.png

Any ideas?  Note the comment in the IG code!!! Or could you send me a code sample in VB from your spreadsheet, to see if I can translate into C# (shouldn't be too difficult) ...

Rick

 

Link to comment
  • 0

Well, as always with these things, if you beat your head against the wall for long enough you can probably fix it 🤣.  I realised that the sample code uses the URI /history/transactions/{transactionType}/{lastPeriod} to access the V1 interface.  V2 uses a slightly different URI ... just /history/transactions, with variable parameters  passed using the '?' construct.  I picked this up from the API Companion app, which helpfully shows the generated GET URIs.  Then I had to invent a new V2Transaction type ( since the demo code only supports V1) to persuade JSON to deserialise to result for me.  Problem (eventually) solved.

I'm still grateful to Andy for responding, and giving me confidence that there are those out there who care.  If anyone wants more details on this particular problem, let me know, and I'll try to post some revised code (once I've cleaned it up, of course!).

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

    • Sainsburys full year earnings and Unilever’s first quarter trading update both say the same thing, UK consumers are in for higher prices. The war in Ukraine, supply chain issues and the effects of ongoing Covid all to blame.      
    • US Dollar (DXY) Daily Price and Analysis US Q1 GDP may stall the greenback’s advance. A 20-year high nears for the US dollar. The multi-month US dollar rally continues with the greenback printing a fresh high today ahead of the first look at US Q1 GDP at 12.30 GMT. The US dollar basket (DXY) has been boosted by renewed weakness in the Euro and the Japanese Yen, as investors move from lower-yielding to higher-yielding currencies, while safe-haven flows continue to benefit the greenback. The US growth release later in the session is expected to show a sharp slowdown from the robust Q4 figure of 6.9%. The markets are currently pricing in growth of just 1% for the first three months of this year, with the slowdown mainly due to a reduction in inventory accrual over the quarter. This release is unlikely to move the greenback, unless there is a large miss or beat, as the Fed believe that 2022 US growth will be robust enough to let them tighten monetary policy sharply without damaging the economy. The latest US Core PCE data – the Fed’s preferred inflation reading – is released on Friday and this may have more effect on the US dollar than today’s GDP data. For all market moving economic data and events, see the DailyFX Calendar. The ongoing US dollar rally has been aided by weakness across a range of G7 currencies including the Euro, the Japanese Yen, and the British Pound. The Euro continues to battle with lowly growth expectations, exacerbated by energy concerns, the British Pound is mired by weak economic data, while the Japanese Yen is in freefall as the BoJ continues with its ultra-loose monetary policy.   The US dollar continues to press higher and looks set to break above 103.96, the March 2020 high. Above here the US dollar would be back at levels last seen nearly two decades ago. The March resistance will likely hold in the short-term, especially with month-end portfolio rebalancing at the end of the week, but US dollar strength is set to continue in the months ahead. USDOLLAR (DXY) WEEKLY PRICE CHART – APRIL 28, 2022 {{THE_FUNDAMENTALS_OF_BREAKOUT_TRADING}} What is your view on the US Dollar – bullish or bearish?   Apr 28, 2022 | DailyFX Nick Cawley, Strategist
    • While Tesla has nothing directly to do with Elon Musk buying Twitter - TSLA stock closed down 12% on news that Musk may have to sell stock and use other holdings to stand against the loan to finalise the purchase of the social media giant.        
×
×
  • Create New...