Good luck.
Welcome to the Java Programming Forums
The professional, friendly Java community. 21,500 members and growing!
The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.
>> REGISTER NOW TO START POSTING
Members have full access to the forums. Advertisements are removed for registered users.
Good luck.
If you don't understand my answer, don't ignore it, ask a question.
class Ticker extends FXRateEvent { // No key set and no match implemented; this event matches all RateEventInfos FXPair changedPair; FXRateEventInfo REI; public void handle(FXEventInfo EI, FXEventManager EM) { //Just print the tick REI = (FXRateEventInfo) EI; System.out.println(REI.getTick()+ ":"+ REI.getTimestamp()); // changedPair = REI.getPair(); // System.out.println(changedPair); } public FXPair changedPair() { return changedPair; } }
You need to put your variables into fields outside of the methods, then set them inside the methods only stating the variable, and not the type.
Thank you micecd.
No problem, would you mind clicking the thanks button under my username? ^^
And did you get your project working?
TorusMonkey (September 13th, 2014)
It is working. I didn't get it going though. I'm working with someone whose trade is programming. So he fixed it. Doesn't help me much in terms of learning. I need to spend more time on JAVA.
I use code to trade forex, been working in MQL, but the broker I've been using is closing its retail devision. So now I have to make a move and the best alternative option is using Oanda's REST API, with JAVA. Just takes so damn long to make anything work in JAVA, just don't have the experience to hunt down problems in a hurry.
--- Update ---
In fact, maybe you can tell me why this isn't working, it's either a malformed link problem or I'm sending the header wrong:
import java.io.IOException; import java.io.InputStream; import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.Date; import org.apache.http.*; import org.apache.http.client.methods.*; import org.apache.http.impl.client.BasicResponseHandler; import org.apache.http.impl.client.HttpClientBuilder; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.message.BasicHeader; import org.apache.http.util.EntityUtils; import org.apache.http.client.HttpClient; import org.json.simple.JSONObject; import org.json.simple.JSONValue; public class OandaRestProjectMain { public static void main (String[]args) throws IOException { CloseableHttpClient httpClient = HttpClientBuilder.create().build(); try { // Set these variables to whatever personal ones are preferred String domain = "https://api-fxpractice.oanda.com"; String access_token = "Token"; String account_id = "AccountNR"; String instruments = "EUR_USD"; HttpUriRequest httpGet = new HttpGet(domain + "/v1/prices?accountId=" + account_id + "&instruments=" + instruments); httpGet.setHeader(new BasicHeader("Authorization: ", "Bearer " + access_token)); System.out.println("Executing request: " + httpGet.getRequestLine()); System.out.println("Header info: "+ "Authorization: " + "Bearer " + access_token); HttpResponse resp = httpClient.execute(httpGet); HttpEntity entity = resp.getEntity(); if (resp.getStatusLine().getStatusCode() == 200 && entity != null) { InputStream stream = entity.getContent(); String line; BufferedReader br = new BufferedReader(new InputStreamReader(stream)); while ((line = br.readLine()) != null) { Object obj = JSONValue.parse(line); JSONObject tick = (JSONObject) obj; // unwrap if necessary if (tick.containsKey("tick")) { tick = (JSONObject) tick.get("tick"); } // ignore heartbeats if (tick.containsKey("instrument")) { System.out.println("-------"); String instrument = tick.get("instrument").toString(); String time = tick.get("time").toString(); double bid = Double.parseDouble(tick.get("bid").toString()); double ask = Double.parseDouble(tick.get("ask").toString()); System.out.println(instrument); System.out.println(time); System.out.println(bid); System.out.println(ask); } } } else { // print error message String responseString = EntityUtils.toString(entity, "UTF-8"); System.out.println(responseString); } } finally { httpClient.close(); } } }
The error message is:
And I'm very sure I am sending the right token. So it must be the header delivering it wrong.{
"code" : 4,
"message" : "The access token provided does not allow this request to be made",
"moreInfo" : "http:\/\/developer.oanda.com\/docs\/v1\/auth\/#overview"
}
Those do not look like java programming errors. If you are trying to interface to some site, perhaps someone at the site could help you.
If you can identify a java programming problem, please ask about it.
If you don't understand my answer, don't ignore it, ask a question.
The problem is in the code. I had someone else check out my token and it works. I suspect I am sending the header wrong or the token wouldn't have been rejected, sometimes I get a different error message as if the token is going through, but the link is malformed, so my JAVA question is, is there a problem with these lines, one of them appears not to be working properly:
HttpUriRequest httpGet = new HttpGet(domain + "/v1/prices?accountId=" + account_id + "&instruments=" + instruments);
httpGet.setHeader(new BasicHeader("Authorization: ", "Bearer " + access_token));
Do you know what the header should look like?suspect I am sending the header wrong
There are test servers you can use that will show you what the program is sending.
If you can see what is sent by the program and compare that to what the desired header should be you should be able to change the program to sent the correct header.
Again compare what is correct with what the program generates so you can change the code to match what is right.is there a problem with these lines, one of them appears not to be working properly:
If you don't understand my answer, don't ignore it, ask a question.
They've updated their code. There were deprecated classes in their old example, that I changed in my example. Probably used the wrong class.
https://github.com/oanda/java-api-st...Streaming.java
So I've been running, but they still have a deprecated class in their example. Not sure why they updated half the blood thing. Now this line doesn't work...
} finally {
// httpClient.getConnectionManager().shutdown();
}
Thanks for the attempts to help...
Usually deprecated classes will continue to work for a while.
If you don't understand my answer, don't ignore it, ask a question.
Eclipse refuses to compile it.
Screen Shot 2014-09-16 at 2.18.33 PM.png
Try asking what to do on an Eclipse users forum.
If you don't understand my answer, don't ignore it, ask a question.