Skip to content

Commit 471b5ae

Browse files
committed
✨ New account endpoint, stoploss example
1 parent 8bef6a3 commit 471b5ae

File tree

4 files changed

+106
-12
lines changed

4 files changed

+106
-12
lines changed

README.md

Lines changed: 52 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ This is the Java wrapper for the Bitvavo API. This project can be used to build
2727
* Cancel Orders [REST](https://github.com/bitvavo/java-bitvavo-api#cancel-orders) [Websocket](https://github.com/bitvavo/java-bitvavo-api#cancel-orders-1)
2828
* Orders Open [REST](https://github.com/bitvavo/java-bitvavo-api#get-orders-open) [Websocket](https://github.com/bitvavo/java-bitvavo-api#get-orders-open-1)
2929
* Trades [REST](https://github.com/bitvavo/java-bitvavo-api#get-trades) [Websocket](https://github.com/bitvavo/java-bitvavo-api#get-trades-1)
30+
* Account [REST](https://github.com/bitvavo/java-bitvavo-api#get-account) [Websocket](https://github.com/bitvavo/java-bitvavo-api#get-account-1)
3031
* Balance [REST](https://github.com/bitvavo/java-bitvavo-api#get-balance) [Websocket](https://github.com/bitvavo/java-bitvavo-api#get-balance-1)
3132
* Deposit Assets [REST](https://github.com/bitvavo/java-bitvavo-api#deposit-assets) [Websocket](https://github.com/bitvavo/java-bitvavo-api#deposit-assets-1)
3233
* Withdraw Assets [REST](https://github.com/bitvavo/java-bitvavo-api#withdraw-assets) [Websocket](https://github.com/bitvavo/java-bitvavo-api#withdraw-assets-1)
@@ -616,7 +617,9 @@ for(int i = 0; i < response.length(); i ++) {
616617
When placing an order, make sure that the correct optional parameters are set. For a limit order it is required to set both the amount and price. A market order is valid if either the amount or the amountQuote has been set.
617618
```java
618619
// optional parameters: limit:(amount, price, postOnly), market:(amount, amountQuote, disableMarketProtection),
619-
// both: timeInForce, selfTradePrevention, responseRequired
620+
// stopLoss/takeProfit:(amount, amountQuote, disableMarketProtection, triggerType, triggerReference, triggerAmount)
621+
// stopLossLimit/takeProfitLimit:(amount, price, postOnly, triggerType, triggerReference, triggerAmount)
622+
// all orderTypes: timeInForce, selfTradePrevention, responseRequired
620623
System.out.println(bitvavo.placeOrder("BTC-EUR", "sell", "limit",
621624
new JSONObject("{ amount: 0.1, price: 4000 }")).toString(2));
622625
```
@@ -654,7 +657,8 @@ System.out.println(bitvavo.placeOrder("BTC-EUR", "sell", "limit",
654657
When updating an order make sure that at least one of the optional parameters has been set. Otherwise nothing can be updated.
655658
```java
656659
// Optional parameters: limit:(amount, amountRemaining, price, timeInForce, selfTradePrevention, postOnly)
657-
// (set at least 1) (responseRequired can be set as well, but does not update anything)
660+
// untriggered stopLoss/takeProfit:(amount, amountQuote, disableMarketProtection, triggerType, triggerReference, triggerAmount)
661+
// stopLossLimit/takeProfitLimit: (amount, price, postOnly, triggerType, triggerReference, triggerAmount)
658662
System.out.println(bitvavo.updateOrder("BTC-EUR", "81080b09-2415-44e3-b61c-50ffca4a0221",
659663
new JSONObject("{ amount: 0.2 }")));
660664
```
@@ -974,6 +978,24 @@ for(int i = 0; i < response.length(); i ++) {
974978
```
975979
</details>
976980

981+
#### Get account
982+
```java
983+
System.out.println(bitvavo.account().toString(2));
984+
```
985+
<details>
986+
<summary>View Response</summary>
987+
988+
```java
989+
{
990+
"fees": {
991+
"taker": "0.0025",
992+
"maker": "0.0015",
993+
"volume": "100"
994+
}
995+
}
996+
```
997+
</details>
998+
977999
#### Get balance
9781000
Returns the balance for this account.
9791001
```java
@@ -1780,7 +1802,9 @@ ws.ticker24h(new JSONObject(), new WebsocketClientEndpoint.MessageHandler() {
17801802
When placing an order, make sure that the correct optional parameters are set. For a limit order it is required to set both the amount and price. A market order is valid if either the amount or the amountQuote has been set.
17811803
```java
17821804
// optional parameters: limit:(amount, price, postOnly), market:(amount, amountQuote, disableMarketProtection),
1783-
// both: timeInForce, selfTradePrevention, responseRequired
1805+
// stopLoss/takeProfit:(amount, amountQuote, disableMarketProtection, triggerType, triggerReference, triggerAmount)
1806+
// stopLossLimit/takeProfitLimit:(amount, price, postOnly, triggerType, triggerReference, triggerAmount)
1807+
// all orderTypes: timeInForce, selfTradePrevention, responseRequired
17841808
ws.placeOrder("BTC-EUR", "sell", "limit", new JSONObject("{ amount: 0.1, price: 4000 }"),
17851809
new WebsocketClientEndpoint.MessageHandler() {
17861810
public void handleMessage(JSONObject responseObject) {
@@ -1822,7 +1846,8 @@ ws.placeOrder("BTC-EUR", "sell", "limit", new JSONObject("{ amount: 0.1, price:
18221846
When updating an order make sure that at least one of the optional parameters has been set. Otherwise nothing can be updated.
18231847
```java
18241848
// Optional parameters: limit:(amount, amountRemaining, price, timeInForce, selfTradePrevention, postOnly)
1825-
// (set at least 1) (responseRequired can be set as well, but does not update anything)
1849+
// untriggered stopLoss/takeProfit:(amount, amountQuote, disableMarketProtection, triggerType, triggerReference, triggerAmount)
1850+
// stopLossLimit/takeProfitLimit: (amount, price, postOnly, triggerType, triggerReference, triggerAmount)
18261851
ws.updateOrder("BTC-EUR", "81080b09-2415-44e3-b61c-50ffca4a0221", new JSONObject("{ amount: 0.2 }"),
18271852
new WebsocketClientEndpoint.MessageHandler() {
18281853
public void handleMessage(JSONObject responseObject) {
@@ -2170,6 +2195,29 @@ ws.trades("BTC-EUR", new JSONObject(), new WebsocketClientEndpoint.MessageHandle
21702195
```
21712196
</details>
21722197

2198+
#### Get account
2199+
```java
2200+
ws.account(new WebsocketClientEndpoint.MessageHandler() {
2201+
public void handleMessage(JSONObject responseObject) {
2202+
JSONObject response = responseObject.getJSONObject("response");
2203+
System.out.println(response.toString(2));
2204+
}
2205+
});
2206+
```
2207+
<details>
2208+
<summary>View Response</summary>
2209+
2210+
```java
2211+
{
2212+
"fees": {
2213+
"taker": "0.0025",
2214+
"maker": "0.0015",
2215+
"volume": "100"
2216+
}
2217+
}
2218+
```
2219+
</details>
2220+
21732221
#### Get balance
21742222
Returns the balance for this account.
21752223
```java

src/main/java/com/bitvavo/api/Bitvavo.java

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -553,7 +553,10 @@ public JSONArray ticker24h(JSONObject options) {
553553
* @param market The market for which the order should be created
554554
* @param side is this a buy or sell order
555555
* @param orderType is this a limit or market order
556-
* @param body optional body parameters: limit:(amount, price, postOnly), market:(amount, amountQuote, disableMarketProtection), both: timeInForce, selfTradePrevention, responseRequired
556+
* @param body optional body parameters: limit:(amount, price, postOnly), market:(amount, amountQuote, disableMarketProtection)
557+
* stopLoss/takeProfit:(amount, amountQuote, disableMarketProtection, triggerType, triggerReference, triggerAmount)
558+
* stopLossLimit/takeProfitLimit:(amount, price, postOnly, triggerType, triggerReference, triggerAmount)
559+
* all orderTypes: timeInForce, selfTradePrevention, responseRequired
557560
* @return JSONObject response, get status of the order through response.getString("status")
558561
*/
559562
public JSONObject placeOrder(String market, String side, String orderType, JSONObject body) {
@@ -582,7 +585,8 @@ public JSONObject getOrder(String market, String orderId) {
582585
* @param market the market the order resides on
583586
* @param orderId the id of the order which should be updated
584587
* @param body optional body parameters: limit:(amount, amountRemaining, price, timeInForce, selfTradePrevention, postOnly)
585-
* (set at least 1) (responseRequired can be set as well, but does not update anything)
588+
* untriggered stopLoss/takeProfit:(amount, amountQuote, disableMarketProtection, triggerType, triggerReference, triggerAmount)
589+
* stopLossLimit/takeProfitLimit: (amount, price, postOnly, triggerType, triggerReference, triggerAmount)
586590
* @return JSONObject response, get status of the order through response.getString("status")
587591
*/
588592
public JSONObject updateOrder(String market, String orderId, JSONObject body) {
@@ -649,6 +653,14 @@ public JSONArray trades(String market, JSONObject options) {
649653
return privateRequestArray("/trades", postfix, "GET", new JSONObject());
650654
}
651655

656+
/**
657+
* Return the fee tier for an account
658+
* @return JSONObject response, get taker fee through: response.getJSONObject("fees").getString("taker")
659+
*/
660+
public JSONObject account() {
661+
return privateRequest("/account", "", "GET", new JSONObject());
662+
}
663+
652664
/**
653665
* Returns the balance for an account
654666
* @param options optional parameters: symbol
@@ -908,7 +920,10 @@ public void tickerBook(JSONObject options, WebsocketClientEndpoint.MessageHandle
908920
* @param market market on which the order should be created
909921
* @param side is this a sell or buy order
910922
* @param orderType is this a limit or market order
911-
* @param body optional body parameters: limit:(amount, price, postOnly), market:(amount, amountQuote, disableMarketProtection), both: timeInForce, selfTradePrevention, responseRequired
923+
* @param body optional body parameters: limit:(amount, price, postOnly), market:(amount, amountQuote, disableMarketProtection)
924+
* stopLoss/takeProfit:(amount, amountQuote, disableMarketProtection, triggerType, triggerReference, triggerAmount)
925+
* stopLossLimit/takeProfitLimit:(amount, price, postOnly, triggerType, triggerReference, triggerAmount)
926+
* all orderTypes: timeInForce, selfTradePrevention, responseRequired
912927
* @param msgHandler callback
913928
* @return JSONObject response, get order object through response.getJSONObject("response")
914929
*/
@@ -944,7 +959,8 @@ public void getOrder(String market, String orderId, WebsocketClientEndpoint.Mess
944959
* @param market market on which the order should be updated
945960
* @param orderId the order which should be updated
946961
* @param body optional body parameters: limit:(amount, amountRemaining, price, timeInForce, selfTradePrevention, postOnly)
947-
* (set at least 1) (responseRequired can be set as well, but does not update anything)
962+
* untriggered stopLoss/takeProfit:(amount, amountQuote, disableMarketProtection, triggerType, triggerReference, triggerAmount)
963+
* stopLossLimit/takeProfitLimit: (amount, price, postOnly, triggerType, triggerReference, triggerAmount)
948964
* @param msgHandler callback
949965
* @return JSONObject response, get order object through response.getJSONObject("response")
950966
*/
@@ -1029,6 +1045,18 @@ public void trades(String market, JSONObject options, WebsocketClientEndpoint.Me
10291045
doSendPrivate(options);
10301046
}
10311047

1048+
/**
1049+
* Returns the fee tier for an account
1050+
*
1051+
* @param msgHandler callback
1052+
* @return JSONObject response, get taker fee through response.getJSONObject("response").getJSONObject("fees").getString("taker")
1053+
*/
1054+
public void account(WebsocketClientEndpoint.MessageHandler msgHandler) {
1055+
ws.addAccountHandler(msgHandler);
1056+
JSONObject options = new JSONObject("{ action: privateGetAccount }");
1057+
doSendPrivate(options);
1058+
}
1059+
10321060
/**
10331061
* Returns the balance for an account
10341062
*

src/main/java/com/bitvavo/api/WebsocketClientEndpoint.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ public class WebsocketClientEndpoint {
4242
private MessageHandler getOrdersHandler;
4343
private MessageHandler getOrdersOpenHandler;
4444
private MessageHandler getTradesHandler;
45+
private MessageHandler getAccountHandler;
4546
private MessageHandler balanceHandler;
4647
private MessageHandler depositAssetsHandler;
4748
private MessageHandler withdrawAssetsHandler;
@@ -550,6 +551,11 @@ else if(response.getString("action").equals("privateGetTrades")) {
550551
this.getTradesHandler.handleMessage(response);
551552
}
552553
}
554+
else if(response.getString("action").equals("privateGetAccount")) {
555+
if (this.getAccountHandler != null) {
556+
this.getAccountHandler.handleMessage(response);
557+
}
558+
}
553559
else if(response.getString("action").equals("privateGetBalance")) {
554560
if(this.balanceHandler != null) {
555561
this.balanceHandler.handleMessage(response);
@@ -657,6 +663,10 @@ public void addGetTradesHandler(MessageHandler msgHandler) {
657663
this.getTradesHandler = msgHandler;
658664
}
659665

666+
public void addAccountHandler(MessageHandler msgHandler) {
667+
this.getAccountHandler = msgHandler;
668+
}
669+
660670
public void addBalanceHandler(MessageHandler msgHandler) {
661671
this.balanceHandler = msgHandler;
662672
}

src/main/java/com/bitvavo/api/example/example.java

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,7 @@ public static void testREST(Bitvavo bitvavo) {
3131
JSONArray response;
3232

3333
int remaining = bitvavo.getRemainingLimit();
34-
if (remaining > 0) {
35-
System.out.println("remaining limit is " + remaining);
36-
System.out.println(bitvavo.time().toString(2));
37-
}
34+
System.out.println("remaining limit is " + remaining);
3835

3936
// response = bitvavo.markets(new JSONObject());
4037
// for(int i = 0; i < response.length(); i ++) {
@@ -74,6 +71,8 @@ public static void testREST(Bitvavo bitvavo) {
7471
// }
7572

7673
// System.out.println(bitvavo.placeOrder("BTC-EUR", "sell", "limit", new JSONObject("{ amount: 0.1, price: 4000 }")).toString(2));
74+
75+
// System.out.println(bitvavo.placeOrder("BTC-EUR", "sell", "stopLoss", new JSONObject("{ amount: 0.1, triggerType: price, triggerReference: lastTrade, triggerAmount: 5000 }")).toString(2));
7776

7877
// System.out.println(bitvavo.getOrder("BTC-EUR", "afa9da1c-edb9-4245-9271-3549147845a1").toString(2));
7978

@@ -101,6 +100,8 @@ public static void testREST(Bitvavo bitvavo) {
101100
// System.out.println(response.getJSONObject(i).toString(2));
102101
// }
103102

103+
// System.out.println(bitvavo.account().toString(2));
104+
104105
// response = bitvavo.balance(new JSONObject());
105106
// for(int i = 0; i < response.length(); i ++) {
106107
// System.out.println(response.getJSONObject(i).toString(2));
@@ -265,6 +266,13 @@ public void handleMessage(JSONObject responseObject) {
265266
// }
266267
// });
267268

269+
// ws.account(new WebsocketClientEndpoint.MessageHandler() {
270+
// public void handleMessage(JSONObject responseObject) {
271+
// JSONObject response = responseObject.getJSONObject("response");
272+
// System.out.println(response.toString(2));
273+
// }
274+
// });
275+
268276
// ws.balance(new JSONObject(), new WebsocketClientEndpoint.MessageHandler() {
269277
// public void handleMessage(JSONObject responseObject) {
270278
// JSONArray response = responseObject.getJSONArray("response");

0 commit comments

Comments
 (0)