Transaction history

6 posts / 0 new
Last post
PascalSonia
Transaction history

Hi,

I built the following code to get history but have the 'Bad URL' error.

I don't understand because the API companion is built with the same URL and there is no error !!!!

'-----------------------------------------------------
' Get historical transactions API
'-----------------------------------------------------
Public Function TransactionsHistory() As Collection

' Header
Call oXMLHTTP.Open("GET", IG_API_HOST + "/history/transactions", False)
Call oXMLHTTP.SetRequestHeader("X-SECURITY-TOKEN", m_accountToken)
Call oXMLHTTP.SetRequestHeader("CST", m_clientToken)
Call oXMLHTTP.SetRequestHeader("X-IG-API-KEY", m_apiKey)
Call oXMLHTTP.SetRequestHeader("Content-Type", "application/json; charset=utf-8")
Call oXMLHTTP.SetRequestHeader("Accept", "application/json; charset=utf-8")
Call oXMLHTTP.send

' Result correct
If oXMLHTTP.Status = 200 Then
[APIMsg].value = ""
Dim Data As Dictionary
Set Data = JSON.parse(oXMLHTTP.responseText)
Set TransactionsHistory = Data.Item("sprintMarketPositions")

' Result error
Else
[APIMsg] = "Transactions: " & oXMLHTTP.responseText
[APIMsg].WrapText = False
Set TransactionsHistory = Nothing
End If

End Function

Chris
Re; Transaction history

Hi PascalSonia

I think you might need to add Version 2 to the header, as you're using the Version 2 endpoint. Can you try that to see if that helps?

Chris

maz
Transaction History Help

Hi PascalSonia / Chris

I don't know how to code but would like to automate the capture of transaction history in my spreadsheet.

Would you be able to take your code above and merge it with the login/authentication features IG provides in the "Sample Apps & SDKs" section, and make it available as a spreadsheet? Perhaps with some parameters to specify the number of transactions that are called?

If you are too busy for this, could you recommend someone who could do the programming for a fee?

Much appreciate your help.

Maz

Chris
Re: Transaction History Help

Hi Maz,

Due to current development worked already penciled in to the road map, we won't have any time in the near future to make any updates such as the above to the Excel sample app, nor are we able to provide recommendations for individual developers.

Maybe another member of the community may be able to assist?

Chris

maz
Thanks Chris.

Thanks Chris.

That's too bad. Would love to have some help from someone else in the community.

In the meanwhile, I've messed about with PascalSonia's code above to work for activities:

'-----------------------------------------------------
' Get transactions activity API
'-----------------------------------------------------

Public Function activities() As Collection

' Header
Call oXMLHTTP.Open("GET", IG_API_HOST + "/history/activity?from=2015-12-01&to=2015-12-31", False)
Call oXMLHTTP.SetRequestHeader("X-SECURITY-TOKEN", m_accountToken)
Call oXMLHTTP.SetRequestHeader("CST", m_clientToken)
Call oXMLHTTP.SetRequestHeader("X-IG-API-KEY", m_apiKey)
Call oXMLHTTP.SetRequestHeader("Content-Type", "application/json; charset=utf-8")
Call oXMLHTTP.SetRequestHeader("Accept", "application/json; charset=utf-8")
Call oXMLHTTP.send
' Result correct
If oXMLHTTP.Status = 200 Then
[APIMsg].value = ""
Dim Data As Dictionary
Set Data = JSON.parse(oXMLHTTP.responseText)
Set activities = Data.Item("ctivities")
' Result error
Else
MsgBox oXMLHTTP.responseText
Set activities = Nothing
End If

End Function

It generates a 403 Forbidden error. I suppose it has to do with a version 2 vs. version 1 problem. I don't know how to request the optional parameters to specify the dates. Could you help?

Once again, apologies for these very rudimentary question.

Mazen

Chris
Re: Transaction History Help

Hi Maz,

The code is good apart from the endpoint is version 2. Required is ..
Call oXMLHTTP.SetRequestHeader("version", 2)

Let us know how you get on!

Chris

Log in or register to post comments