Bloomberg API - using .Net API to get the FUT_CHAIN on an underlying security - c#

I am trying to query the Bloomberg API (.Net) to get the future chain on an underlying security. Preferably, I would be able to get the list of futures for a given date in the past.
The equivalent operation in Excel using the worksheet formula API would be the following:-
=BDS("ERA COMDTY","FUT_CHAIN","CHAIN_DATE=20120103",
"INCLUDE_EXPIRED_CONTRACTS=Yes")
I looked at a large number of online resources, and I don't seem to be getting anywhere.

For the v3 API, you need to use request overrides.
Request request = refDataService.createRequest("ReferenceDataRequest");
request.append("securities", "ERA Comdty");
request.append("fields","FUT_CHAIN");
Element overrides = request.getElement("overrides");
Element override1 = overrides.appendElement();
override1.setElement("fieldId", "CHAIN_DATE");
override1.setElement("value", "20120103");
Element override2 = overrides.appendElement();
override2.setElement("fieldId", "INCLUDE_EXPIRED_CONTRACTS);
verride2.setElement("value", 'Y');
session.sendRequest(request);

Related

Microsoft.Azure.CognitiveServices.Language.SpellCheck NuGet not working with Bing Search API (unauthorized)

I'm using .net-core3.1 with Microsoft.Azure.CognitiveServices.Language.SpellCheck NuGet package. I've read through entire documentation around Bing/cognitive API but I still find it very confusing as there are multiple APIs doing the same thing.
I got the API key from Microsoft.BingSearch on portal.azure.com and I'm using the free subscription. My subscription should however be valid as I am already using their LUIS without problems. Azure links to https://learn.microsoft.com/en-us/bing/search-apis/bing-spell-check/quickstarts/rest/python for quick start but this does not work for me ("https://api.bing.microsoft.com/v7.0/SpellCheck" url gives me "NotFound" using the code below with my key).
code sample:
var x = new SpellCheckClient(new ApiKeyServiceClientCredentials("<API_KEY>"));
// endpoints I tried:
// x.Endpoint = "https://westeurope.api.bing.microsoft.com/v7.0/spellcheck";
// x.Endpoint = "https://cognitiveservices.azure.com/bing/v7.0";
// x.Endpoint = "https://api.bing.microsoft.com"; -- Not found
// x.Endpoint = "https://cognitiveservices.azure.com"; -- The requested name is valid, but no data of the requested type was found.
var y = await x.SpellCheckerWithHttpMessagesAsync("gona");
Using default endpoint gives me Unauthorized error code.
Anyone has any idea on how to use this API?
You are right, the endpoint seems to be wrong. As you can see in the documentation here, regarding this value:
Supported Cognitive Services endpoints (protocol and hostname, for
example: "https://westus.api.cognitive.microsoft.com",
"https://api.cognitive.microsoft.com").
So if you are using West Europe, it should be "https://westus.api.cognitive.microsoft.com"
You can also check your API key by directly testing the console here: https://westeurope.dev.cognitive.microsoft.com/docs/services/5f7d486e04d2430193e1ca8f760cd7ed/operations/57855119bca1df1c647bc358
Choose your resource region (the one selected during key creation on Azure portal)
Set your key value in "Ocp-Apim-Subscription-Key" field
Edit the "text" value in the query parameters
Run the request

Azure .NET SDK not handling filters correctly (ConsumptionClient)?

I'm calling the Azure Usage API trying to use a filter to get machine specific information.
The return values are valid, but it seems like either the REST API or the C# library is sending the request incorrectly.
This is the code:
var filterString = $"instanceName eq '{vm.VirtualMachineName}'";
vmConsumptionData = await consumptionClient.Item1.UsageDetails.ListAsync(
scope: $"/subscriptions/{subscriptionId}",
filter: filterString
);
According to the log, my request is being sent with the following:
https://management.azure.com//subscriptions/{SubscriptionId}/providers/Microsoft.Consumption/usageDetails?$filter=instanceName%20eq%20%27{correct instance name}%27&api-version=2017-11-30
However, this is always returning the same 24 results, even when submitting a different instance name.
I have tried removing certain parts of the filter 'query' and it always returns the same 24 results (which are not virtual machine resource types).
Am I calling the library incorrectly? Reference here
Apparently the SDK differs in the filtering and is somewhat clear from the documentation. You should call with the following:
properties/usageEnd (Utc time)
properties/usageStart (Utc time)
properties/resourceGroup
properties/instanceName
properties/instanceId
Changing my filterString to:
var filterString = $"properties/instanceName eq \'{vm.VirtualMachineName}\'";
Did the job.

Google Site Search C# API doesn't return any promotions

I am using google's "CustomSearch API Client Library for .NET" and trying to retrieve the promotions which I have created through the Control panel with the Add Promotion functionality. I have a paid version of Google Site Search.
When I test it with the "Google Search"INSIDE the control panel it shows the promotion, but when I try to search through the .Net API, it returns Null in promotions.
I dont even get the promotions shown when I search with the API explorer.
The promotion is active.
Does it require some additional coding to get the promotions through the API?
Thank you..
I found the answer.
The reason for why I wasn't getting any Promotion Results was because I had set the SiteSearch property to the domain.
When I removed the value from that property then it all worked :)
var listRequest = svc.Cse.List(query);
listRequest.Hl = language;
listRequest.Cx = this.cx;
listRequest.Start = startIndex;
listRequest.SiteSearch = "www.domain.name"; <-- this has to be removed

Bloomberg API - get list of government bonds

When hitting KENGB <Govt> <GO> on the Bloomberg terminal I get list of all Kenya government bonds.
How do I get this list through Bloomberg API? Or list of their tickers?
(I download PX_LAST prices and historical prices for various securities regularly, so I am pretty familiar with service "//blp/refdata" and request "ReferenceDataRequest" ... but cannot figure out how to retrieve list of securities (and its tickers) programmatically)
try to take a look at this:
http://www.openbloomberg.com/content/uploads/sites/2/2013/04/blpapi-developers-guide.pdf
at page 77 it explains which service you must call to have Government Bonds.
this is teh c++ code:
Service govtService = session.getService("//blp/instruments");
Request request = govtService.createRequest("govtListRequest");
request.asElement().setElement("partialMatch", true);
request.asElement().setElement("query", "T*");// this plus the previous line permits to retrieve all the thicker that begins with T
request.asElement().setElement("ticker", "LANG_OVERRIDE_NONE");
request.asElement().setElement("maxResults", 10);
sendRequest(request, session);
The only way I know to get a list of securities via API v3 is to use the EQS API where you set up an EQS screen and then use the API to get the matching securities. Not sure if this lets you achieve the same result you get from security search on the Terminal.

Simple C# Evernote API OAuth example or guide?

Anybody know where I can find a simple example C# code example? Apparently really tough to find.
I'm just starting out, got my Developer key.
Initial (really noob question/presumption) - -Can (should/must) my solution be a web service client? No new libraries I need to install in .Net right?
Basically, as a test, I want to be able to securely present a single note from a private notebook in html similar to what the Everfort export in html looks like on a outside WebSite.
Many Thanks in Advance!
You should start by downloading our API ZIP from http://www.evernote.com/about/developer/api/. You'll find C# client sample code in /sample/csharp. This sample code demonstrates using the Evernote API from a desktop application that authenticates using username and password.
I am not sure if you ever got this working, but I was playing around with Evernote, OpenAuth and C# this morning and managed to get it all working. I have put together a blog post / library explaining the experience and outlining how to do it with MVC here - http://www.shaunmccarthy.com/evernote-oauth-csharp/ - it uses the AsyncOAuth library: https://github.com/neuecc/AsyncOAuth
I wrote a wrapper around AsyncOAuth that you might find useful here: https://github.com/shaunmccarthy/AsyncOAuth.Evernote.Simple
One prickly thing to be aware of - the Evernote Endpoints (/oauth and /OAuth.action) are case sensitive
// Download the library from https://github.com/shaunmccarthy/AsyncOAuth.Evernote.Simple
// Configure the Authorizer with the URL of the Evernote service,
// your key, and your secret.
var EvernoteAuthorizer = new EvernoteAuthorizer(
"https://sandbox.evernote.com",
"slyrp-1234", // Not my real id / secret :)
"7acafe123456badb123");
// First of all, get a request token from Evernote - this causes a
// webrequest from your server to Evernote.
// The callBackUrl is the URL you want the user to return to once
// they validate the app
var requestToken = EvernoteAuthorizer.GetRequestToken(callBackUrl);
// Persist this token, as we are going to redirect the user to
// Evernote to Authorize this app
Session["RequestToken"] = requestToken;
// Generate the Evernote URL that we will redirect the user to in
// order to
var callForwardUrl = EvernoteAuthorizer.BuildAuthorizeUrl(requestToken);
// Redirect the user (e.g. MVC)
return Redirect(callForwardUrl);
// ... Once the user authroizes the app, they get redirected to callBackUrl
// where we parse the request parameter oauth_validator and finally get
// our credentials
// null = they didn't authorize us
var credentials = EvernoteAuthorizer.ParseAccessToken(
Request.QueryString["oauth_verifier"],
Session["RequestToken"] as RequestToken);
// Example of how to use the credential with Evernote SDK
var noteStoreUrl = EvernoteCredentials.NotebookUrl;
var noteStoreTransport = new THttpClient(new Uri(noteStoreUrl));
var noteStoreProtocol = new TBinaryProtocol(noteStoreTransport);
var noteStore = new NoteStore.Client(noteStoreProtocol);
List<Notebook> notebooks = client.listNotebooks(EvernoteCredentials.AuthToken);
http://weblogs.asp.net/psteele/archive/2010/08/06/edamlibrary-evernote-library-for-c.aspx might help. As the author states it just bundles some and fixes some. Haven't tried it myself but thought I'd mention for a possibly easier way to get started. Possibly.
This might help too...found it using the Way Back Machine since the original blog site was offline.
https://www.evernote.com/pub/bluecockatoo/Evernote_API#b=bb2451c9-b5ff-49bb-9686-2144d984c6ba&n=c30bc4eb-cca4-4a36-ad44-1e255eeb26dd
The original blog post: http://web.archive.org/web/20090203134615/http://macrolinz.com/macrolinz/index.php/2008/12/
Scroll down and find the post from December 26 - "Get it while it's hot..."

Categories