Reputation: 109
I would like to retrieve some historical stock prices via a REST API from the following site:
The response is a JSON.
Basically, the query can be done as follows: An OPTIONS call is sent without parameters and then a GET request with header parameters.
Both calls are sent to the following address:
The following two parameters are included in the header:
And now my question: how do you get the X-Client-TraceId? It looks like a UUID, but it doesn't seem to be one. The value changes with every page view in the browser. But you can't just enter any value.
Many greetings,
Trebor
Upvotes: 6
Views: 2645
Reputation: 17719
Making use of the blog post in the answer posted by @Elias Holzmann
please note
w4icATTGtnjAZMbkL3kJwxMfEAKDa3MN
to w4ivc1ATTGta6njAZzMbkL3kJwxMfEAKDa3MNr
X-Security
header and it still worksvar baseUrl = "https://api.boerse-frankfurt.de";
var now = _dateTimeService.UtcNow;
var minDate = now.AddYears(-2).ToString("yyyy-MM-dd");
var maxDate = now.ToString("yyyy-MM-dd");
var path = $"/v1/data/price_history?limit=2000&offset=0&isin={isin}&mic=XFRA&minDate={minDate}&maxDate={maxDate}&cleanSplit=false&cleanPayout=false&cleanSubscriptionRights=false";
var url = baseUrl + path;
using (var client = new HttpClient())
{
var contentType = "application/json";
client.BaseAddress = new Uri(baseUrl);
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue(contentType));
var request = new HttpRequestMessage(HttpMethod.Get, path);
var clientDate = now.ToString("yyyy-MM-ddTHH:mm:ss.fffZ");//now is DateTime.UtcNow
var salt = "w4ivc1ATTGta6njAZzMbkL3kJwxMfEAKDa3MNr";
var input = clientDate + url + salt;
var clientTraceId = "";
using (System.Security.Cryptography.MD5 md5 = System.Security.Cryptography.MD5.Create())
{
byte[] hash = md5.ComputeHash(System.Text.Encoding.ASCII.GetBytes(input));
clientTraceId = Convert.ToHexString(hash).ToLower();
}
request.Headers.Add("client-date", clientDate);
request.Headers.Add("x-client-traceId", clientTraceId);
var response = await client.SendAsync(request);
var json = await response.Content.ReadAsStringAsync();
}
Upvotes: 2
Reputation: 3649
Since this question was asked, someone has written a blog post about this exact topic. The algorithm detailed there still seems to be in use (as of 2022-03-12).
An excerpt of the relevant parts:
Client-Date
This is the current time, converted to a string with Javascript’s toISOString() function.
[...]
X-Client-TraceId
[...]
salt
is a fixed string, in this casew4icATTGtnjAZMbkL3kJwxMfEAKDa3MN
. Apparently it appears in the source code as-is so it must be constant.- X-Client-TraceId is the md5 of
time + url + salt
.
Note: time
is the string sent in the Client-Date
header.
The blog post has some additional information around the process of reverse engineering this algorithm and the X-Security
header.
Upvotes: 4