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
  • General Statistics

    • Total Topics
      23,059
    • Total Posts
      95,467
    • Total Members
      43,679
    • Most Online
      7,522
      10/06/21 10:53

    Newest Member
    Alastair
    Joined 02/10/23 23:07
  • Posts

    • Commodities Market Trading Report - Technical Analysis is Elliott Wave and Trading Strategies Content: US Bond Yields, USD, DXY, US Gold XAU, GDX, Silver XAG, Gold Stocks, Iron Ore, Copper, Uranium, Crude Oil, Natural Gas. Commodities Market Summary: While the USD continues higher, gold and silver will continue to be lower. Copper will continue lower, while Uranium is in a bullish Wave (iv) corrective pattern. Crude Oil is creating five waves down from the high and Natural Gas still hasn’t given a buy signal. Video Chapters 00:00  TLT Bonds. US Gov Bonds 10/5 Yr Yields 07:19 US Dollar Index, DXY 12:02 Precious Metals: Spot Gold  / US Spot Silver / XGD 27:37 Base Metals: XME ETF, Iron Ore, Copper. Uranium URA. 33:35 Energy: XLE ETF / Crude Oil / Natural Gas  41:40 End Analyst Peter Mathers TradingLounge™ Australian Financial Services Licence - AFSL 317817 Source: tradinglounge.com  Access Trial here  
    • I have recently researched cryptocurrency exchange tokens with good potential that would be a profitable investment for the upcoming bull market. This is what I found so far. 1. Binance's token BNB, BNB is the biggest exchange token and has done well over the years. However, its performance this year has not been great and it currently trades at over $200. 2. OKX's token, OKB, is trading at over $40 and has performed very well in 2023. It may be a good addition to our portfolio for the upcoming bull market. 3. Bitget's token, BGB. The BGB daily chart looks fascinating and it currently trades around $0.40. Based on the exchange's growth in 2023, BGB seems to be the most promising exchange token I have researched. I will continue to research other exchange tokens, but for now, I would like to know your thoughts on these tokens.
    • If you have been into cryptocurrency over the time, you'd have noticed it has faced a lot of ups and downs, from several crackdowns to adoptions, ranging from China's ban, to El Salvador's adoption, including Tesla's adoption and others, and it looks as though in an ever developing world of technology, adoption seems to be the resolution for advancing companies and now we have another adoption, Honda Motor Co. Honda Motor Co., a well-known Japanese automaker, has made a surprising decision to accept digital assets as payment for its goods. By collaborating with the blockchain payment platform FCF Pay, Honda now makes it possible for clients to lease or buy their cars and power equipment using different cryptocurrencies, including XRP and the most popular doge token, Shiba Inu (SHIB). This partnership increases the possibilities accessible to customers who may now purchase Honda's cars, motorbikes, and power equipment using digital currencies like Bitcoin (BTC), Ether (ETH), Binance Coin (BNB), Polkadot (DOT), and other well-known cryptocurrencies in addition to XRP and Shiba Inu (SHIB) rather than conventional cash. The unique feature of Honda's offering is that it accepts a variety of more uncommon meme-inspired coins, such as Pepe Coin (PEPE), Floki Inu (FLOKI), Bone ShibaSwap (BONE), and Doge Killer (LEASH). Connecting the dots of various happenings in the crypto space and sudden adoption by various companies and even some economies, where do you see cryptocurrency in the coming years and what steps are you taking in preparation for it?
×
×
  • Create New...
us