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
  • image.png

  • Posts

    • What is Foreign Exchange? Foreign exchange (Forex or FX) is the conversion of one currency into another at a specific rate known as the foreign exchange rate. The conversion rates for almost all currencies are constantly floating as they are driven by the market forces of supply and demand. The most traded currencies in the world are the United States dollar, Euro, Japanese yen, British pound, and Australian dollar. The US dollar remains the key currency, accounting for more than 87% of total daily value traded.Factors that Affect Foreign Exchange Rates Many factors can potentially influence the market forces behind foreign exchange rates. The factors include various economic, political, and even psychological conditions. The economic factors include a government’s economic policies, trade balances, inflation, and economic growth outlook. Political conditions also exert a significant impact on the forex rate, as events such as political instability and political conflicts may negatively affect the strength of a currency. The psychology of forex market participants can also influence exchange rates. The Foreign Exchange Market The foreign exchange market is a decentralized and over-the-counter market where all currency exchange trades occur. It is the largest (in terms of trading volume) and the most liquid market in the world. On average, the daily volume of transactions on the forex market totals $5.1 trillion, according to the Bank of International Settlements’ Triennial Central Bank Survey (2016). The forex market major trading centers are located in major financial hubs around the world, including New York, London, Frankfurt, Tokyo, Hong Kong, and Sydney. Due to this reason, foreign exchange transactions are executed 24 hours, five days a week (except weekends). Despite the decentralized nature of forex markets, the exchange rates offered in the market are the same among its participants, as arbitrage opportunities can arise otherwise. The foreign exchange market is probably one of the most accessible financial markets. Market participants range from tourists and amateur traders to large financial institutions (including central banks) and multinational corporations. Also, the forex market does not only involve a simple conversion of one currency into another. Many large transactions in the market involve the application of a wide variety of financial instruments, including forwards, swaps, options, etc. Foreign currency exchange (forex) A foreign currency exchange rate is a price that represents how much it costs to buy the currency of one country using the currency of another country. Currency traders buy and sell currencies through forex transactions based on how they expect currency exchange rates will fluctuate. When the value of one currency rises relative to another, traders will earn profits if they purchased the appreciating currency, or suffer losses if they sold the appreciating currency.  
    • Totally agree, the growth of Bitget Wallet will have a positive impact on $BWB. The potential for both seems exciting. Good luck to you too, and hopefully everyone can benefit from these earning opportunities.
    • Sounds like Mystiko Network is making some serious waves in the interoperability space. Seamless compatibility across multiple blockchains is a game changer, especially with the ZK SDK for secure and private dApps. Big backing from Samsung and Coinlist adds credibility too. I will keep an eye on that Bitget listing, it could be a major boost for $XZK
×
×
  • Create New...
us