Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor into separate Maven modules
- Loading branch information
Showing
11 changed files
with
158 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,4 @@ target | |
.DS_Store | ||
*.iml | ||
.idea | ||
api-keys.properties |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,14 @@ | ||
# A Kraken API Client in Java | ||
Query the Kraken API in Java. No external libraries used. | ||
|
||
Execute `mvn clean package` and the JAR will be in the `target` folder. After that, `Examples.java` can also be executed using `java -cp target/classes edu/self/kraken/Examples`. | ||
Query the Kraken API in Java. | ||
|
||
Execute `mvn clean package` and the JAR will be in the `target` folder. After that, `Examples.java` can also be executed | ||
using `java -cp target/classes edu/self/kraken/Examples`. | ||
|
||
https://www.kraken.com/en-us/help/api | ||
|
||
TODO: | ||
|
||
* return json objects instead of string | ||
* return objects for method calls | ||
* SLF4J |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
|
||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<parent> | ||
<groupId>edu.self.nyg</groupId> | ||
<artifactId>kraken-api-parent</artifactId> | ||
<version>1.0.0-SNAPSHOT</version> | ||
</parent> | ||
|
||
<artifactId>kraken-api-examples</artifactId> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>edu.self.nyg</groupId> | ||
<artifactId>kraken-api</artifactId> | ||
<version>${project.version}</version> | ||
</dependency> | ||
</dependencies> | ||
|
||
</project> |
64 changes: 64 additions & 0 deletions
64
examples/src/main/java/edu/self/nyg/kraken/example/Examples.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package edu.self.nyg.kraken.example; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.security.InvalidKeyException; | ||
import java.security.NoSuchAlgorithmException; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.Properties; | ||
|
||
import edu.self.nyg.kraken.api.KrakenApi; | ||
|
||
public class Examples { | ||
|
||
public static void main(String[] args) throws IOException, InvalidKeyException, NoSuchAlgorithmException { | ||
|
||
Properties apiKeys = readPropertiesFromFile("/api-keys.properties"); | ||
|
||
KrakenApi api = new KrakenApi(); | ||
api.setKey(apiKeys.getProperty("key")); | ||
api.setSecret(apiKeys.getProperty("secret")); | ||
|
||
String response; | ||
Map<String, String> input = new HashMap<>(); | ||
|
||
input.put("pair", "XBTEUR"); | ||
response = api.queryPublic(KrakenApi.Method.TICKER, input); | ||
System.out.println(response); | ||
|
||
input.clear(); | ||
input.put("pair", "XBTUSD,XLTCZUSD"); | ||
response = api.queryPublic(KrakenApi.Method.ASSET_PAIRS, input); | ||
System.out.println(response); | ||
|
||
input.clear(); | ||
input.put("asset", "ZEUR"); | ||
response = api.queryPrivate(KrakenApi.Method.BALANCE, input); | ||
System.out.println(response); | ||
|
||
input.clear(); | ||
input.put("ordertype", "limit"); | ||
input.put("type", "sell"); | ||
input.put("volume", "1"); | ||
input.put("pair", "XLTCZUSD"); | ||
input.put("price", "1000"); | ||
input.put("oflags", "post,fciq"); | ||
input.put("validate", "true"); | ||
response = api.queryPrivate(KrakenApi.Method.ADD_ORDER, input); | ||
System.out.println(response); | ||
|
||
} | ||
|
||
private static Properties readPropertiesFromFile(String path) { | ||
try { | ||
InputStream stream = Examples.class.getResourceAsStream(path); | ||
Properties properties = new Properties(); | ||
properties.load(stream); | ||
return properties; | ||
} | ||
catch (IOException e) { | ||
throw new RuntimeException(String.format("Could not read properties file: %s", path)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
key=YOUR-API-KEY | ||
secret=YOUR-API-SECRET |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
|
||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<parent> | ||
<groupId>edu.self.nyg</groupId> | ||
<artifactId>kraken-api-parent</artifactId> | ||
<version>1.0.0-SNAPSHOT</version> | ||
</parent> | ||
|
||
<artifactId>kraken-api</artifactId> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.projectlombok</groupId> | ||
<artifactId>lombok</artifactId> | ||
</dependency> | ||
</dependencies> | ||
|
||
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.