Skip to content

Commit 38a7e45

Browse files
authored
Merge pull request #5023 from mengyiren/feature/kraken_cancel_all_orders
Feature/kraken cancel all orders
2 parents beb5ddf + e3456c6 commit 38a7e45

File tree

5 files changed

+49
-7
lines changed

5 files changed

+49
-7
lines changed

.idea/codeStyles/Project.xml

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

xchange-kraken/src/main/java/org/knowm/xchange/kraken/KrakenAuthenticated.java

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,14 @@ KrakenCancelOrderResult cancelOrder(
152152
@FormParam("txid") String transactionId)
153153
throws IOException;
154154

155+
@POST
156+
@Path("private/CancelAll")
157+
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
158+
KrakenCancelOrderResult cancelAllOrders(
159+
@HeaderParam("API-Key") String apiKey,
160+
@HeaderParam("API-Sign") ParamsDigest signer,
161+
@FormParam("nonce") SynchronizedValueFactory<Long> nonce);
162+
155163
@POST
156164
@Path("private/OpenOrders")
157165
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
@@ -193,14 +201,15 @@ KrakenQueryOrderResult queryOrders(
193201
/**
194202
* Get trades history
195203
*
196-
* @param type ype = type of trade (optional) all = all types (default) any position = any
197-
* position (open or closed) closed position = positions that have been closed closing
198-
* position = any trade closing all or part of a position no position = non-positional trades
204+
* @param type ype = type of trade (optional) all = all types (default) any position =
205+
* any position (open or closed) closed position = positions that have been
206+
* closed closing position = any trade closing all or part of a position no
207+
* position = non-positional trades
199208
* @param includeTrades whether or not to include trades related to position in output (optional.
200-
* default = false)
201-
* @param start starting unix timestamp or trade tx id of results (optional. exclusive)
202-
* @param end ending unix timestamp or trade tx id of results (optional. inclusive)
203-
* @param offset result offset
209+
* default = false)
210+
* @param start starting unix timestamp or trade tx id of results (optional. exclusive)
211+
* @param end ending unix timestamp or trade tx id of results (optional. inclusive)
212+
* @param offset result offset
204213
*/
205214
@POST
206215
@Path("private/TradesHistory")

xchange-kraken/src/main/java/org/knowm/xchange/kraken/service/KrakenTradeService.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import java.io.IOException;
44
import java.util.Collection;
5+
import java.util.Collections;
56
import java.util.Map;
67
import org.knowm.xchange.Exchange;
78
import org.knowm.xchange.currency.CurrencyPair;
@@ -17,6 +18,7 @@
1718
import org.knowm.xchange.kraken.dto.trade.KrakenOrder;
1819
import org.knowm.xchange.kraken.dto.trade.KrakenTrade;
1920
import org.knowm.xchange.service.trade.TradeService;
21+
import org.knowm.xchange.service.trade.params.CancelAllOrders;
2022
import org.knowm.xchange.service.trade.params.CancelOrderByIdParams;
2123
import org.knowm.xchange.service.trade.params.CancelOrderByUserReferenceParams;
2224
import org.knowm.xchange.service.trade.params.CancelOrderParams;
@@ -97,6 +99,11 @@ public boolean cancelOrder(CancelOrderParams orderParams) throws IOException {
9799
return false;
98100
}
99101

102+
@Override
103+
public Collection<String> cancelAllOrders(CancelAllOrders orderParams) throws IOException {
104+
return Collections.singletonList(String.valueOf(super.cancelAllKrakenOrders().getCount()));
105+
}
106+
100107
@Override
101108
public Class[] getRequiredCancelOrderParamClasses() {
102109
return new Class[] {CancelOrderByIdParams.class, CancelOrderByUserReferenceParams.class};

xchange-kraken/src/main/java/org/knowm/xchange/kraken/service/KrakenTradeServiceRaw.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,15 @@ public KrakenCancelOrderResponse cancelKrakenOrder(String orderId) throws IOExce
318318
return checkResult(result);
319319
}
320320

321+
public KrakenCancelOrderResponse cancelAllKrakenOrders() {
322+
KrakenCancelOrderResult result =
323+
kraken.cancelAllOrders(
324+
exchange.getExchangeSpecification().getApiKey(),
325+
signatureCreator,
326+
exchange.getNonceFactory());
327+
return checkResult(result);
328+
}
329+
321330
protected KrakenTradeVolume getTradeVolume(CurrencyPair... currencyPairs) throws IOException {
322331

323332
KrakenTradeVolumeResult result =

xchange-kraken/src/test/java/org/knowm/xchange/kraken/service/KrakenTradeServiceTest.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,22 @@ public void placeOrderWithTimeInForceTest() throws Exception {
162162
assertThat(requestParams.get("timeinforce")).isEqualTo("IOC");
163163
}
164164

165+
@Test
166+
public void cancelAllOrdersTest() throws Exception {
167+
stubFor(
168+
post(urlPathEqualTo("/0/private/CancelAll"))
169+
.willReturn(
170+
aResponse()
171+
.withStatus(200)
172+
.withHeader("Content-Type", "application/json")
173+
.withBody(OPEN_ORDERS_BODY)));
174+
classUnderTest.cancelAllOrders(null);
175+
List<LoggedRequest> requests =
176+
wireMockRule.findAll(postRequestedFor(urlEqualTo("/0/private/CancelAll")));
177+
Map<String, String> requestParams = parseAddOrderRequestBody(requests.get(0));
178+
assertThat(requestParams.get("nonce")).isLessThan(String.valueOf(System.currentTimeMillis()));
179+
}
180+
165181
private void stubAddOrderApi() {
166182
stubFor(
167183
post(urlPathEqualTo("/0/private/AddOrder"))

0 commit comments

Comments
 (0)