I'm looking now in Bloomberg Data License Web Services. Note, that this is different from Bloomberg API ( Session/Service/Request, b-pipe, etc ). It is SOAP-based solution to retrieve reference data from Bloomberg DBs. I created a test application just to quickly evaluate this solution:
var client = new PerSecurityWSClient("PerSecurityWSPort");
client.ClientCredentials.ClientCertificate.Certificate = new X509Certificate2("{path-to-certificate}", "{password}");
client.ClientCredentials.UserName.UserName = "";
client.ClientCredentials.UserName.Password = "";
client.ClientCredentials.Windows.ClientCredential.Domain = "";
var companyFields = new string[] { "ID_BB_COMPANY", "ID_BB_ULTIMATE_PARENT_CO_NAME" , /* ... all other fields I'm interested in */ };
var getCompanyRequest = new SubmitGetCompanyRequest {
headers = new GetCompanyHeaders { creditrisk = true },
instruments = new Instruments {
instrument = new Instrument[] {
new Instrument { id = "AAPL US", yellowkey = MarketSector.Equity, yellowkeySpecified = true },
new Instrument { id = "PRVT US", yellowkey = MarketSector.Equity, yellowkeySpecified = true }
}
},
fields = companyFields
};
var response = client.submitGetCompanyRequest(getCompanyRequest);
if(response.statusCode.code != SUCCESS) {
System.Console.Error.WriteLine("Response status is " + response.statusCode);
return;
}
var retrieve = new RetrieveGetCompanyRequest { responseId = response.responseId };
RetrieveGetCompanyResponse getCompanyResponse = null;
do {
System.Console.Write("*");
Thread.Sleep(1000);
getCompanyResponse = client.retrieveGetCompanyResponse(retrieve);
} while (getCompanyResponse.statusCode.code == DATA_NOT_AVAILABLE);
if (getCompanyResponse.statusCode.code != SUCCESS) {
System.Console.Error.WriteLine("Response status is " + response.statusCode);
return;
}
System.Console.WriteLine();
foreach (var instrumentData in getCompanyResponse.instrumentDatas) {
Console.WriteLine("Data for: " + instrumentData.instrument.id + " [" + instrumentData.instrument.yellowkey + "]");
int fieldIndex = 0;
foreach (var dataEntry in instrumentData.data) {
if (dataEntry.isArray) {
Console.WriteLine(companyFields[fieldIndex] + ":");
foreach(var arrayEntry in dataEntry.bulkarray) {
foreach(var arrayEntryData in arrayEntry.data) {
Console.WriteLine("\t" + arrayEntryData.value);
}
}
}
else {
Console.WriteLine(companyFields[fieldIndex] + ": " + dataEntry.value);
}
++fieldIndex;
}
System.Console.WriteLine("-- -- -- -- -- -- -- -- -- -- -- -- --");
}
The code looks somewhat bloated (well, it is indeed, SOAP-based in 2015). Hence is my question -- I assume there should be some wrappers, helpers, anything else to facilitate reference data retrieval, but even on SO there is only one question regarding BB DLWS. Is here anyone using DLWS? Are there any known libraries around BB DLWS? Is it supposed to be that slow?
Thanks.
I'm just getting into this myself. There are two options for requesting data: SFTP and Web Services. To my understanding, the SFTP option requires a Bloomberg application ("Request Builder") in order to retrieve data.
The second option (Web Services) doesn't seem well-documented, at least for those working with R (like myself). So, I doubt a library exists for Web Services at this point. Bloomberg provides an authentication certificate in order to gain access to their network, as well as their web services host and port information. Now, in terms of using this information to connect and download data, that is still beyond me.
If you or anyone else has been able to successfully connect and extract data using Bloomberg Web Services and R, please post the detailed code to this Blog!
Related
I am trying to get Amazon's Route53 Recovery Controller to update control states from a .net application and I keep getting an error. I see on the documentation that I need to set the region and cluster endpoint, but I can't figure out how to do it.
Here a sample of the code I am using:
AmazonRoute53RecoveryControlConfigConfig configConfig = new AmazonRoute53RecoveryControlConfigConfig();
configConfig.RegionEndpoint = RegionEndpoint.USWest2;
AmazonRoute53RecoveryControlConfigClient configClient = new AmazonRoute53RecoveryControlConfigClient(_awsCredentials, configConfig);
DescribeClusterResponse describeClusterResponse = await configClient.DescribeClusterAsync(new DescribeClusterRequest()
{
ClusterArn = "arn:aws:route53-recovery-control::Account:cluster/data"
});
foreach (ClusterEndpoint clusterEndpoint in describeClusterResponse.Cluster.ClusterEndpoints)
{
AmazonRoute53RecoveryClusterConfig clusterConfig = new AmazonRoute53RecoveryClusterConfig();
clusterConfig.RegionEndpoint = RegionEndpoint.GetBySystemName(clusterEndpoint.Region);
AmazonRoute53RecoveryClusterClient client = new AmazonRoute53RecoveryClusterClient(_awsCredentials, clusterConfig);
GetRoutingControlStateResponse getRoutingControlStateResponseWest = await client.GetRoutingControlStateAsync(new GetRoutingControlStateRequest()
{
RoutingControlArn = "arn:aws:route53-recovery-control::Account:controlpanel/data/routingcontrol/data"
});
GetRoutingControlStateResponse getRoutingControlStateResponseEast = await client.GetRoutingControlStateAsync(new GetRoutingControlStateRequest()
{
RoutingControlArn = "arn:aws:route53-recovery-control::Account:controlpanel/data/routingcontrol/data"
});
UpdateRoutingControlStatesRequest request = new UpdateRoutingControlStatesRequest();
request.UpdateRoutingControlStateEntries = new List<UpdateRoutingControlStateEntry>()
{
new UpdateRoutingControlStateEntry()
{
RoutingControlArn = "arn:aws:route53-recovery-control::Account:controlpanel/data/routingcontrol/data",
RoutingControlState = getRoutingControlStateResponseWest.RoutingControlState == RoutingControlState.On ? RoutingControlState.Off : RoutingControlState.On
},
new UpdateRoutingControlStateEntry()
{
RoutingControlArn = "arn:aws:route53-recovery-control::Account:controlpanel/data/routingcontrol/data",
RoutingControlState = getRoutingControlStateResponseEast.RoutingControlState == RoutingControlState.On ? RoutingControlState.Off : RoutingControlState.On
}
};
UpdateRoutingControlStatesResponse response = await client.UpdateRoutingControlStatesAsync(request);
if (response.HttpStatusCode == HttpStatusCode.OK)
{
break;
}
}
When this code executes I get this error when it tries to get the control state: The requested name is valid, but no data of the requested type was found.
I see in the java example you can set the region and the data plane url endpoint, but I don't see the equivalent in .net.
https://docs.aws.amazon.com/r53recovery/latest/dg/example_route53-recovery-cluster_UpdateRoutingControlState_section.html
This works when I use the cli which I can also set the region and url endpoint.
https://docs.aws.amazon.com/r53recovery/latest/dg/getting-started-cli-routing.control-state.html
What am I doing wrong here?
There is a solution to this question here: https://github.com/aws/aws-sdk-net/issues/1978.
Essentially use the ServiceURL on the configuration object and add a trailing / to the endpoint url.
AmazonRoute53RecoveryClusterConfig clusterRecoveryConfig = new AmazonRoute53RecoveryClusterConfig();
clusterRecoveryConfig.ServiceURL = $"{clusterEndpoint.Endpoint}/";
AmazonRoute53RecoveryClusterClient client = new AmazonRoute53RecoveryClusterClient(_awsCredentials, clusterRecoveryConfig);
A REST client consumes a series of API calls, 6 to be exact. They take a notable time to complete those series of calls even though both applications are in the same machine. The code is something like the following:
// 1.
CreateUserOption createUserOption = new CreateUserOption(username, jobCandidatePassword, email, fullName);
Optional<User> userOptional = createUserAccount(createUserOption, tokenValue);
if (userOptional.isEmpty()) return false;
// 2.
GenerateRepoOption generateRepoOption = new GenerateRepoOption(templateName.replace("template", "") + username, templateOwner);
Optional<Repository> repositoryOptional = this.generateRepo(generateRepoOption, templateOwner, templateName, tokenValue);
if (repositoryOptional.isEmpty()) return false;
// 3.
TransferRepoOption transferRepoOption = new TransferRepoOption(username);
Optional<Repository> transferRepositoryOptional = transferRepo(
transferRepoOption,
repositoryOptional.get().getOwner().getLogin(),
repositoryOptional.get().getName(),
tokenValue
);
if (transferRepositoryOptional.isEmpty()) return false;
// 4.
List<Organization> organizations = this.getOrganizationsOfCurrentUser(tokenValue);
if (!organizations.isEmpty()) {
// 5.
Organization organization = organizations.get(0);
Optional<Team> teamOptional =
this.createTeamInOrganization(new CreateTeamOption("t-" + username), organization.getUsername(), tokenValue);
if (!teamOptional.isEmpty()) {
// 6.
this.addTeamMember(teamOptional.get().getId(), username, tokenValue);
}
}
return true;
and those functions are consuming a REST API. For example,
private Optional<User> createUserAccount(CreateUserOption account, String tokenValue) {
log.debug(":::: createUserAccount : {}", account.toString());
String postBody = createUserOptionJsonAdapter.toJson(account);
okhttp3.RequestBody body = okhttp3.RequestBody.create(postBody, okhttp3.MediaType.parse("application/json"));
Request request = new Request.Builder()
.url(apiBaseurl + "/admin/users")
.header("User-Agent", "OkHttp Headers.java")
.addHeader("Accept", MediaType.APPLICATION_JSON.toString())
.addHeader("Authorization", "token " + tokenValue)
.post(body)
.build();
try (Response response = client.newCall(request).execute()) {
if (!response.isSuccessful()) {
log.error(response.code() + " - " + response.message());
return Optional.empty();
}
User user = giteaUserJsonAdapter.fromJson(response.body().string());
return Optional.of(user);
} catch (IOException ioe) {
log.error(ioe.getMessage());
return Optional.empty();
}
}
Those 6 calls can be divided into two groups and 3 calls in each group, the next call needs the returned data from the previous one. Firing another thread for one group of API calls is one way to improve the performance.
Any better approaches on the client?
The client app is built with Java and Moshi HTTP client library.
I am developing an Android app in Unity. I am trying to make UnityWebRequests to work with Vuforia's Web Services API. Currently every method works - GET/PUT/DELETE, but I cannot POST anything, I always get an error:
Error:Generic/unknown HTTP error
Response code:400
Even though according to Vuforia's documentation POST requires the same request body as PUT and I am generating it using the same approach:
public string CreateNewUpdateBody(Text name, Text width, RawImage image, Toggle active_flag, Text application_metadata)
{
dynamic BodyData = new System.Dynamic.ExpandoObject();
if (!string.IsNullOrEmpty(name.text))
{
BodyData.name = name.text; // mandatory for post
}
if (!string.IsNullOrEmpty(width.text))
{
BodyData.width = float.Parse(width.text); // mandatory for post
}
if (image.texture != null)
{
Texture2D texture = (Texture2D)image.texture;
BodyData.image = System.Convert.ToBase64String(ImageConversion.EncodeToJPG(texture)); // mandatory for post
}
if (active_flag.interactable)
{
BodyData.active_flag = active_flag.isOn;
}
if (!string.IsNullOrEmpty(application_metadata.text))
{
BodyData.application_metadata = System.Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(application_metadata.text));
}
string json = JsonConvert.SerializeObject(BodyData);
Debug.Log("Body data: " + json);
return json;
}
Then I send the web request like this:
private IEnumerator PostTarget(MonoBehaviour mono, string postBody)
{
var request = UnityWebRequest.Post(url + "/targets", postBody);
SetHeaders(request); // Must be done after setting the body
Debug.Log("Starting request " + request.method + " " + request.url);
yield return request.SendWebRequest();
while (!request.isDone) yield return null;
if (request.isHttpError || request.isNetworkError)
{
Debug.LogError("Request was not completed");
Debug.LogError("Error:" + request.error + " Response code:" + request.responseCode);
Debug.LogError(request.downloadHandler.text); // result_code is always just "Fail"
mono.StopAllCoroutines();
yield break;
}
else
{
Debug.Log("Request completed successfuly!");
Debug.Log(request.downloadHandler.text);
}
response = JsonUtility.FromJson<ResponsePostNewTarget>(request.downloadHandler.text);
Debug.Log("\nCreated target with id: " + response.target_id);
}
Any thoughts or suggestions? I appreciate the time you take to read this.
If everything works BUT posting data, either 1 vuforia doesn't support it or 2 (most likely) you're missing something.
Try adding this to your request
private UploadHandler GetUploadHandler(string postBody)
{
UploadHandler handler = new UploadHandlerRaw(System.Text.Encoding.UTF8.GetBytes(postBody));
handler.contentType = "application/json";
return handler;
}
And call it after SetHeaders
request.uploadHandler = GetUploadHandler(postBody);
I'm using Microsoft Bot Framework using the channel registration product and the REST API. I have setup the "messaging endpoint" and everything works fine for sending and receiving messages.
But I don't just want to send/receive messages. Something as simple as setting up a welcome message seems impossible because my endpoint receives nothing other than messaging events (when the bot is in the channel / conversation.)
Is there something I have missed?
I would like to setup several endpoints, or use the same, whatever, to listen to other types of events.
You need to implement in the MessageController something like these:
Pay attention in the else if. The funcition in the controller is HandleSystemMessage.
else if (message.Type == ActivityTypes.ConversationUpdate)
{
// Handle conversation state changes, like members being added and removed
// Use Activity.MembersAdded and Activity.MembersRemoved and Activity.Action for info
// Not available in all channels
IConversationUpdateActivity update = message;
var cliente = new ConnectorClient(new System.Uri(message.ServiceUrl), new MicrosoftAppCredentials());
if (update.MembersAdded != null && update.MembersAdded.Count > 0)
{
foreach(var member in update.MembersAdded)
{
if(member.Id != message.Recipient.Id)
{
//var username = System.Security.Principal.WindowsIdentity.GetCurrent().Name;
var username = message.From.Name;
var reply = message.CreateReply();
//string dir = System.AppDomain.CurrentDomain.BaseDirectory + "Images" + Path.DirectorySeparatorChar + "cajamar.png";
string dir = HttpRuntime.AppDomainAppPath + "Images" + Path.DirectorySeparatorChar + "cajamar.png";
reply.Attachments.Add(new Attachment(
contentUrl: dir,
contentType: "image/png",
name: "cajamar.png"
));
reply.Text = $"Bienvenido {username} al ChatBot de convenios:";
cliente.Conversations.ReplyToActivity(reply);
//var reply = message.CreateReply();
//reply.Text = $"El directorio base es: {HttpRuntime.AppDomainAppPath}";
//cliente.Conversations.ReplyToActivityAsync(reply);
}
}
}
}
I have a WorkFlow Service hosted in a server: http://myServer.net/MyWorkflowService.xamlx
and it's working normally, I called it from a Windows Phone app before and working.
Now, I wanted to call it from a PCL Project (profile 78) for Xamarin.
I got this error:
A correlation query yielded an empty result set. Please ensure
correlation queries for the endpoint are correctly configured.
I added it as a service reference, and I call an Async Method, and subscribes for completed event:
example
TaskCompletionSource<MyResponse> tsk = new TaskCompletionSource<MyResponse>();
WorkFlowService.SubmitModel serviceModel = new WorkFlowService.SubmitModel()
{
List = MyList.ToArray<string>(),
Guid = Guid,
Description = Description,
userid = UserId
};
WorkFlowClient.SubmitCompleted += (sender, eventArgs) => {
if (eventArgs.Error != null)
{
Debug.WriteLine("Exception : DataService : Adding New" + eventArgs.Error.Message);
tsk.TrySetResult(new MyResponse() {
HasError = true
});
}
else
{
tsk.TrySetResult(new MyResponse()
{
HasError = false
});
}
};
WorkFlowClient.SubmitAsync(new WorkFlowService.SubmitRequest((serviceModel)));
return tsk.Task;
I should send an array of strings with my request, Should I provide ServiceReferences.ClientConfig file and what is the build action for it inside the PCL?!