Proof of concept: read pricing stream from Oanda
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@ -1,2 +1,3 @@
|
|||||||
/.gradle
|
/.gradle
|
||||||
/build
|
/build
|
||||||
|
/bin/
|
||||||
|
|||||||
@ -24,7 +24,8 @@ dependencies {
|
|||||||
// Use JUnit test framework
|
// Use JUnit test framework
|
||||||
testCompile 'junit:junit:4.12'
|
testCompile 'junit:junit:4.12'
|
||||||
|
|
||||||
implementation 'com.espertech:esper:7.0.0'
|
implementation 'com.espertech:esper:7.1.0'
|
||||||
|
implementation 'com.oanda.v20:v20:3.0.21'
|
||||||
}
|
}
|
||||||
|
|
||||||
// In this section you declare where to find the dependencies of your project
|
// In this section you declare where to find the dependencies of your project
|
||||||
|
|||||||
@ -29,3 +29,41 @@ gradle init --type java-application
|
|||||||
#+BEGIN_SRC shell
|
#+BEGIN_SRC shell
|
||||||
./gradlew build
|
./gradlew build
|
||||||
#+END_SRC
|
#+END_SRC
|
||||||
|
|
||||||
|
#+BEGIN_SRC shell
|
||||||
|
./gradlew run
|
||||||
|
#+END_SRC
|
||||||
|
|
||||||
|
|
||||||
|
* Get sample data
|
||||||
|
|
||||||
|
#+BEGIN_SRC shell
|
||||||
|
curl -H "Authorization: Bearer 9a480f0b83e987f4015cf0846790c7d9-695ced635526744abd61bdf0e2ae8b71" https://stream-fxpractice.oanda.com/v3/accounts/101-001-7935538-001/pricing/stream\?instruments\=USD_CAD
|
||||||
|
#+END_SRC
|
||||||
|
|
||||||
|
#+BEGIN_SRC javascript
|
||||||
|
{"type":"PRICE",
|
||||||
|
"time":"2018-03-06T03:55:26.327901133Z",
|
||||||
|
"bids":[{"price":"1.29728","liquidity":10000000}],
|
||||||
|
"asks":[{"price":"1.29744","liquidity":10000000}],
|
||||||
|
"closeoutBid":"1.29728",
|
||||||
|
"closeoutAsk":"1.29744",
|
||||||
|
"status":"tradeable",
|
||||||
|
"tradeable":true,
|
||||||
|
"instrument":"USD_CAD"}
|
||||||
|
{"type":"HEARTBEAT","time":"2018-03-06T03:55:38.607009935Z"}
|
||||||
|
{"type":"PRICE","time":"2018-03-06T03:55:43.572975078Z","bids":[{"price":"1.29727","liquidity":10000000}],"asks":[{"price":"1.29745","liquidity":10000000}],"closeoutBid":"1.29727","closeoutAsk":"1.29745","status":"tradeable","tradeable":true,"instrument":"USD_CAD"}
|
||||||
|
{"type":"HEARTBEAT","time":"2018-03-06T03:55:43.625479422Z"}
|
||||||
|
{"type":"PRICE","time":"2018-03-06T03:55:43.635882478Z","bids":[{"price":"1.29726","liquidity":10000000}],"asks":[{"price":"1.29745","liquidity":10000000}],"closeoutBid":"1.29726","closeoutAsk":"1.29745","status":"tradeable","tradeable":true,"instrument":"USD_CAD"}
|
||||||
|
#+END_SRC
|
||||||
|
|
||||||
|
|
||||||
|
* eclim server
|
||||||
|
|
||||||
|
http://eclim.org/install.html
|
||||||
|
|
||||||
|
start with:
|
||||||
|
|
||||||
|
#+BEGIN_SRC shell
|
||||||
|
/home/alx/eclipse/java-oxygen/eclipse/eclimd
|
||||||
|
#+END_SRC
|
||||||
|
|||||||
@ -1,12 +1,75 @@
|
|||||||
/*
|
import java.io.BufferedReader;
|
||||||
* This Java source file was generated by the Gradle 'init' task.
|
import java.io.IOException;
|
||||||
*/
|
import java.io.InputStreamReader;
|
||||||
|
import java.net.MalformedURLException;
|
||||||
|
import java.net.SocketTimeoutException;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.net.URLConnection;
|
||||||
|
import java.net.URLEncoder;
|
||||||
|
|
||||||
|
import javax.net.ssl.HttpsURLConnection;
|
||||||
|
//import com.espertech.esper.client.*;
|
||||||
|
|
||||||
public class App {
|
public class App {
|
||||||
public String getGreeting() {
|
|
||||||
return "Hello world.";
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
System.out.println(new App().getGreeting());
|
|
||||||
|
//EPServiceProvider engine = EPServiceProviderManager.getDefaultProvider();
|
||||||
|
|
||||||
|
try {
|
||||||
|
String[] instruments = new String[] {"USD_CAD", "EUR_USD", "USD_JPY"};
|
||||||
|
|
||||||
|
String query = String.format("instruments=%s",
|
||||||
|
URLEncoder.encode(String.join(",", instruments), "UTF-8"));
|
||||||
|
|
||||||
|
openConnection("https://stream-fxpractice.oanda.com/v3/accounts/101-001-7935538-001/pricing/stream?" + query);
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void openConnection(String urlStr)
|
||||||
|
throws IOException
|
||||||
|
{
|
||||||
|
HttpsURLConnection httpConn = null;
|
||||||
|
String line = null;
|
||||||
|
try {
|
||||||
|
URL url = new URL(urlStr);
|
||||||
|
URLConnection urlConn = url.openConnection();
|
||||||
|
if (!(urlConn instanceof HttpsURLConnection)) {
|
||||||
|
throw new IOException ("URL is not an Https URL");
|
||||||
|
}
|
||||||
|
httpConn = (HttpsURLConnection)urlConn;
|
||||||
|
httpConn.setAllowUserInteraction(false);
|
||||||
|
httpConn.setInstanceFollowRedirects(true);
|
||||||
|
httpConn.setRequestMethod("GET");
|
||||||
|
httpConn.setReadTimeout(50 * 1000);
|
||||||
|
httpConn.setRequestProperty("Authorization", "Bearer 9a480f0b83e987f4015cf0846790c7d9-695ced635526744abd61bdf0e2ae8b71");
|
||||||
|
BufferedReader is =
|
||||||
|
new BufferedReader(new InputStreamReader(httpConn.getInputStream()));
|
||||||
|
|
||||||
|
while ((line = is.readLine( )) != null) {
|
||||||
|
System.out.println(line);
|
||||||
|
// Message msg = Message.obtain();
|
||||||
|
// msg.what=1;
|
||||||
|
// msg.obj=line;
|
||||||
|
// mhandler.sendMessage(msg);
|
||||||
|
|
||||||
|
}
|
||||||
|
} catch (MalformedURLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} catch(SocketTimeoutException e){
|
||||||
|
e.printStackTrace();
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
//Message msg = Message.obtain();
|
||||||
|
//msg.what=2;
|
||||||
|
//BufferedInputStream in = new BufferedInputStream(httpConn.getErrorStream());
|
||||||
|
//line = new String(readStream(in));
|
||||||
|
//msg.obj = line;
|
||||||
|
//mhandler.sendMessage(msg);
|
||||||
|
} finally {
|
||||||
|
httpConn.disconnect();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -7,6 +7,6 @@ import static org.junit.Assert.*;
|
|||||||
public class AppTest {
|
public class AppTest {
|
||||||
@Test public void testAppHasAGreeting() {
|
@Test public void testAppHasAGreeting() {
|
||||||
App classUnderTest = new App();
|
App classUnderTest = new App();
|
||||||
assertNotNull("app should have a greeting", classUnderTest.getGreeting());
|
//assertNotNull("app should have a greeting", classUnderTest.getGreeting());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user