I have downloaded an API called "financequotes" for Java (Link: http://financequotes-api.com/) and have attempted to use it for a project. It has been imported into my class path and all the methods run, however when I ask for a stocks details
Stock s = new Stock("INTC");
s.print();
I am given back all the details which should have been obtained online as null including name, currency, quote, etc.
Why is this?
ALTERNATIVELY - Could you suggest another finance API which is relatively simple to use to gather basic financial data?
Thanks
The creator of the API has answered - Here was the problem
The code doesn't have a request to Yahoo Finance yet. There's 2 alternative ways to fix this.
Request it through the YahooFinance static methods
Stock stock = YahooFinance.get("INTC");
stock.print();
Force a refresh of the stock's quote by using the getQuote(boolean refresh) method
Stock stock = new Stock("INTC");
stock.getQuote(true);
stock.print();
This will automatically also load/refresh the statistics and dividend data.
Intrinio provides a simple to use API for financial information. It looks like you are a Java user, there are packages on for connecting via rest API and for connecting to real time prices via websocket.
The API is easy to use for stock prices, fundamentals, options, analyst estimates, etc. This tutorial will get you started, but here is an example in curl:
curl "https://api.intrinio.com/prices?ticker=AAPL" -u "API_Password:API_Username"
Related
We have two AWS accounts. One is for production and another is for testing. We need to differentiate the environment we are running. We can see that a simple way is to get account name and once we get that it will be very straight forward. But, we don't know how to get it from AWS credentials or properties. Does anyone have idea about how to get account information using AWS credentials?
I considered the possibility of account permissions, account type etc, but I think it should not prevent us from getting account name?
With a rather recent aws java sdk you can use getCallerIdentity:
AWSSecurityTokenServiceClientBuilder.standard().build()
.getCallerIdentity(new GetCallerIdentityRequest()).getAccount()
You can see the GetUserResult. This is returned by getUser(). GetUserResult has a method to get User. This User has all the fields to get the required information you need.
look at the account number that is returned in the get_user (iam user)
eg,
"Arn": "arn:aws:iam::THISISYOURNUMERICACCOUNTNUMBER:user/lcerezo"
AmazonIdentityManagementClient iamClient = new AmazonIdentityManagementClient();
String accountNumber = iamClient.getUser().getUser().getArn().split(":")[4]);
In case you are using the Secured Token Service, you will not be able to get the user details to get the account number. You can instead use the role. Below is the sample code.
AmazonIdentityManagementClient iamClient = new AmazonIdentityManagementClient();
GetRoleRequest getRoleRequest = new GetRoleRequest();
getRoleRequest.setRoleName("roleName");
String accountNumber = iamClient.getRole(getRoleRequest).getRole().getArn().split(":")[4];
Using the AWS v2.0 Java SDK, you can use software.amazon.awssdk.services.sts.StsClient#getCallerIdentity.
First add a dependency to the sts module, eg in gradle:
implementation platform("software.amazon.awssdk:bom:2.14.2")
implementation "software.amazon.awssdk:sts"
Then:
log.info("{}", StsClient.create().getCallerIdentity());
will return:
GetCallerIdentityResponse(UserId=AJAIVBQXMUAJAIVBQXMU, Account=298232720644, Arn=arn:aws:iam::298232720644:user/adrian)
Is there a way to call solrs analysis api in java using solr-core and get the analyzed tokens.
Analysis api takes fieldName or fieldType and values and give the analyzed tokens.
Is there a way to get those tokens from java?
I found the following link: FieldAnalysisRequestHandler, But I could not get any examples to use it.
In the Admin UI (for which the FieldAnalysisRequestHandler is meant) you can call it by selecting a core and then go to the "Analysis" entry.
See https://cwiki.apache.org/confluence/x/UYDxAQ or https://cwiki.apache.org/confluence/x/FoDxAQ for that.
From a client (which I guess you mean, as you tagged this question with solrj) you need to call the correct URL.
Typically the FieldAnalysisRequestHandler is bound to /analysis/field, see your solrconfig.xml.
From Solrj it should work like this:
SolrQuery query = new SolrQuery();
solrQuery.setRequestHandler("/analysis/field");
solrQuery.set("analysis.fieldtype", "mytype");
solrQuery.set("analysis.fieldvalue", "myval");
QueryResponse solrResponse = solrServer.query(solrQuery);
But it doesn't seem like there's a great support for this in Solrj, probably because it's meant to be called from the Solr Admin UI as mentioned.
I am using AWS Java SDK to generate RealTime Predictions. To get the output of prediction i need to know what kind of machine learning model is being used is it binary , regression or multiclass. I have only the model id which i can use to locate model.Is there any API or some other way through which i can know the model type in my application.
I have searched through the documentation but haven't found anything that suits my requirement.
You can get the model type by calling the GetMLModel API.
AmazonMachineLearningClient client = ...;
GetMLModelRequest request = new GetMLModelRequest().withMLModelId("...");
client.getMLModel(request).getMLModelType();
I am making a call from a server that is located in US to FindItemsAdvanced of ebay finding api.
I define ListedIn as "EBAY-ENCA", however, when I make the call - I see that it doesn't return results. I believe that this is because that items are not available to US.
I see that there is a parameter called: AvailableTo - but how can I say "to all countries" ? Writing each iso code in the world could be exhausting..
My code:
ItemFilter marketFilter = new ItemFilter();
marketFilter.setName(ItemFilterType.LISTED_IN);
marketFilter.getValue().add("EBAY-ENCA");
request.getItemFilter().add(marketFilter);
ItemFilter conditionFilter = new ItemFilter();
conditionFilter.setName(ItemFilterType.AVAILABLE_TO);
conditionFilter.getValue().add("UK");
request.getItemFilter().add(conditionFilter);
In general this call should work - regardless from where you call the API. So I assume that you get an error message from the API that prevent items from being returned. Be aware that the FindItemsAdvanced call of the eBay Finding API requires either a given "categoryId" or a "keyword". Do you set any of these?
Here is the XML payload of a working call:
<findItemsAdvancedRequest xmlns="http://www.ebay.com/marketplace/search/v1/services">
<keywords>iPhone6</keywords>
<itemFilter>
<name>ListedIn</name>
<value>EBAY-ENCA</value>
</itemFilter>
</findItemsAdvancedRequest>
I've created an example in our API playground. It uses the XML version of the Finding API. Just execute the call to see the valid response with items included. You can adapt and customize the request parameters to your needs and see how the API responses.
The "AvailableTo" filter can only be used once per request with exactly one value. So it won't be possible to add it multiple times or to add it once with multiple values. But I'm not sure if I get your use case right. Do you really want to get only those items that are available world wide? If yes, then I'm afraid this most probably isn't possible without filtering them locally (eg. by filtering for "Worldwide" in the "shipToLocations").
I am developing a functionality for my project that when user enters 'Postal Code' the co-ordinates(latitude, longitude) for the corresponding 'postal code' should display. the implementation platform is 'JAVA'.
I googled for the java api but i did not find any specific resource.
Any suggstions will be greatly appriciated
You can (now) check out the open-source Java client library for Geocoding, Directions, DistanceMatrix, Elevation and TimeZone too: https://github.com/googlemaps/google-maps-services-java
It's quite straight forward. E.g. have a look at the geocode method of this class. Pass your postalcode (along with the country) to the method and you should be fine. (The GLatLng class can be found here but should be replaced by you according to your needs.)
[edit]
I just saw that this example is still using Google Maps v2, but it should be a breeze to convert it to v3.
In the linked documents you can also find the restrictions regarding the use of this service (paragraph "Usage Limits")
You could try to write a REST client (using e.g. Apache HttpClient) for Google geocoding API RESTful web service.
The docs on this are not new user friendly. For me the java docs worked best although theyre quite rigid: https://www.javadoc.io/doc/com.google.maps/google-maps-services/latest/com/google/maps/GeocodingApiRequest.html
Here is how to do so using the newest Google Geocoding API:
//use your google api key to create a GeoApiContext instance
GeoApiContext context = new GeoApiContext.Builder().apiKey("xxxxxx").build();
//this will get geolocation details via zip
GeocodingResult[]results = GeocodingApi.newRequest(context).components(ComponentFiler.postalCode("75002")).await();
System.out.println(results[0]);
//this will get geolocation details via address
GeocodingResult[] results2 = GeocodingApi.geocode(context, "One Apple Park Way Cupertino, CA 95014").await();
System.out.println(results2[0]);
//another way to get geolocation details via address
GeocodingResult[] results3 = GeocodingApi.newRequest(context).address("One Apple Park Way Cupertino, CA 95014").await();
System.out.println(results3[0]);
//geolocation details via lat lng
GeocodingResult[] results4 = GeocodingApi.newRequest(context).latlng(latLng).await();
System.out.println(results4[0]);
from there you'll get a bunch of data on the returned location in the results array, you can parse it as you wish to extract your choice of data. heres an ex of what that data looks like....
[GeocodingResult placeId=ChIJyTSQVXm0j4ARmdUQoA1BpwQ [Geometry: 37.31317000,-122.07238160 (APPROXIMATE) bounds=[37.34159500,-121.99557710, 37.24799500,-122.14382300], viewport=[37.34159500,-121.99557710, 37.24799500,-122.14382300]], formattedAddress=MONTE VISTA, CA 95014, USA, types=[postal_code], addressComponents=[[AddressComponent: "95014" ("95014") (postal_code)], [AddressComponent: "MONTE VISTA" ("MONTE VISTA") (locality, political)], [AddressComponent: "Santa Clara County" ("Santa Clara County") (administrative_area_level_2, political)], [AddressComponent: "California" ("CA") (administrative_area_level_1, political)], [AddressComponent: "United States" ("US") (country, political)]], postcodeLocalities=[Cupertino, MONTE VISTA, Permanente]]
Here is a way for doing it (include source):
http://halexv.blogspot.mx/2015/07/java-geocoding-using-google-maps-api.html
The blog explain how to do it without having and API_KEY and a way for filtering the locatiotions into the most probable one.
Give it a try.