WorldTradingData.com

Hello, i am trying to get a connection to the free finance api of worldtradingdata.com up and running. As far as I understood, I should be able to send a get URL and receive and parse the json response. But I am already stuck at getting the socket to send the URL.

So far I have tried to

[code]Dim Socket as new HTTPSocket
Dim Result As String

Result = Socket.get(“https://api.worldtradingdata.com/api/v1/forex_history?base=GBP&convert_to=EUR&api_token=***********”, 30)
Result = DefineEncoding(Result, Encodings.UTF8)

Window1.ResponseArea.Text =Result
[/code]

But my response is this. ( Yes I have entered and tested a valid api_token, just opening the url in a browser receives the json data)

[code]

301 Moved Permanently

301 Moved Permanently


nginx/1.15.8 [code][/code][/code]

Any pointers where I am going wrong?

Markus

  1. Use the HTTPSecureSocket class instead of HTTPSocket for HTTPS connections
  2. For 301 responses, the redirect url is given in the Location header. Though using the HTTPSecureSocket may do away with the redirect.

Thank you for the fast reply. I solved it in the end by using just a URLConnection

Dim content As String = Window1.Worldata.SendSync("GET","https://api.worldtradingdata.com/api/v1/forex_hist..........

Here is the final code that returns date and price from the worldtradingdata api. The Url can be adjusted to receive other symbols, dates etc…
(Window1.Worlddata is a public URLConnection)

[code]Dim content As String = Window1.Worlddata.SendSync(“GET”,“https://api.worldtradingdata.com/api/v1/forex_history?base=GBP&convert_to=EUR&api_token=yourToken”,30)
Var j As String = content.DefineEncoding(Encodings.UTF8)
Var ji As New JSONItem(j)
Var j0 As JSONItem = ji.Child(“history”)

For Each name As String In j0.Names
System.DebugLog(name)
System.DebugLog(j0.Value(name))
Next[/code]

Hope it helps somebody else as well.