Skip to content

Commit b221980

Browse files
authored
Merge pull request #16 from cryptomkt/fix/transaction-history-order-by
Fix/transaction history order by
2 parents 8af5c3b + 4a88891 commit b221980

File tree

9 files changed

+95
-21
lines changed

9 files changed

+95
-21
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<groupId>com.cryptomkt.api</groupId>
77
<artifactId>cryptomarket</artifactId>
88
<packaging>jar</packaging>
9-
<version>3.0.0</version>
9+
<version>3.0.1</version>
1010

1111
<licenses>
1212
<license>
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package com.cryptomarket.params;
2+
3+
/** Param to sort by */
4+
public enum OrderBy {
5+
/** sort by creation date */
6+
CREATED_AT("created_at"),
7+
/** sort by id */
8+
ID("id"),
9+
/** sort by update date */
10+
UPDATE_AT("updated_at");
11+
12+
private final String label;
13+
14+
private OrderBy(String label) {
15+
this.label = label;
16+
}
17+
18+
@Override
19+
public String toString() {
20+
return label;
21+
}
22+
}

src/main/java/com/cryptomarket/params/ParamsBuilder.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,17 @@ public ParamsBuilder by(@Nullable SortBy by) {
230230
return addArg(ArgNames.BY, by);
231231
}
232232

233+
234+
/**
235+
* Adds an order_by param to the ParamBuilder.
236+
*
237+
* @param by An OrderBy type
238+
* @return The ParamsBuilder
239+
*/
240+
public ParamsBuilder orderBy(@Nullable OrderBy by) {
241+
return addArg(ArgNames.ORDER_BY, by);
242+
}
243+
233244
/**
234245
* Adds a to param to the ParamBuilder.
235246
*

src/main/java/com/cryptomarket/sdk/ArgNames.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ public class ArgNames {
2222
/** */
2323
public static final String BY = "by";
2424
/** */
25+
public static final String ORDER_BY = "order_by";
26+
/** */
2527
public static final String TO = "to";
2628
/** */
2729
public static final String SINCE = "since";

src/main/java/com/cryptomarket/sdk/rest/CryptomarketRestClient.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import com.cryptomarket.params.ContingencyType;
1111
import com.cryptomarket.params.IdentifyBy;
1212
import com.cryptomarket.params.OrderBuilder;
13+
import com.cryptomarket.params.OrderBy;
1314
import com.cryptomarket.params.OrderType;
1415
import com.cryptomarket.params.ParamsBuilder;
1516
import com.cryptomarket.params.Period;
@@ -1525,7 +1526,7 @@ public String transferMoneyToAnotherUser(ParamsBuilder paramsBuilder)
15251526
* 'SUCCESS' and 'ROLLED_BACK'
15261527
* @param sort Optional. Sort direction. 'ASC' or 'DESC'. Default
15271528
* is 'DESC'
1528-
* @param sortBy Optional. sorting parameter.'created_at' or 'id'.
1529+
* @param orderBy Optional. sorting parameter.'created_at', 'updated_at' or 'id'.
15291530
* Default is 'created_at'
15301531
* @param from Optional. Interval initial value when ordering by
15311532
* 'created_at'. As Datetime
@@ -1549,7 +1550,7 @@ public List<Transaction> getTransactionHistory(
15491550
@Nullable List<TransactionSubtype> subtypes,
15501551
@Nullable List<TransactionStatus> statuses,
15511552
@Nullable Sort sort,
1552-
@Nullable SortBy sortBy,
1553+
@Nullable OrderBy orderBy,
15531554
@Nullable String from,
15541555
@Nullable String till,
15551556
@Nullable Integer idFrom,

src/main/java/com/cryptomarket/sdk/rest/CryptomarketRestClientImpl.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import com.cryptomarket.params.ContingencyType;
1313
import com.cryptomarket.params.IdentifyBy;
1414
import com.cryptomarket.params.OrderBuilder;
15+
import com.cryptomarket.params.OrderBy;
1516
import com.cryptomarket.params.OrderType;
1617
import com.cryptomarket.params.ParamsBuilder;
1718
import com.cryptomarket.params.Period;
@@ -1013,7 +1014,7 @@ public List<Transaction> getTransactionHistory(
10131014
List<TransactionSubtype> subtypes,
10141015
List<TransactionStatus> statuses,
10151016
Sort sort,
1016-
SortBy sortBy,
1017+
OrderBy orderBy,
10171018
String from,
10181019
String till,
10191020
Integer idFrom,
@@ -1028,7 +1029,7 @@ public List<Transaction> getTransactionHistory(
10281029
.subtypes(subtypes)
10291030
.statuses(statuses)
10301031
.sort(sort)
1031-
.by(sortBy)
1032+
.orderBy(orderBy)
10321033
.from(from)
10331034
.till(till)
10341035
.idFrom(idFrom)

src/test/java/com/cryptomarket/sdk/TestRestClientMarketData.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,6 @@ public void getConvertedCandles() throws CryptomarketSDKException {
209209
var targetCurrency = "BTC";
210210
var convertedCandles = client.getConvertedCandles(targetCurrency, symbols, Period._4_HOURS, Sort.ASC, null, null,
211211
null);
212-
System.out.println(convertedCandles);
213212
assertEquals(targetCurrency, convertedCandles.getTargetCurrency());
214213
assertTrue(convertedCandles.getData().keySet().size() == 3);
215214
convertedCandles.getData().forEach((key, candleList) -> {
@@ -222,7 +221,6 @@ public void getConvertedCandlesBySymbol() throws CryptomarketSDKException {
222221
var targetCurrency = "BTC";
223222
var convertedCandles = client.getConvertedCandlesBySymbol(targetCurrency, "EOSETH", Period._4_HOURS, Sort.ASC, null,
224223
null, null, null);
225-
System.out.println(convertedCandles);
226224
assertEquals(targetCurrency, convertedCandles.getTargetCurrency());
227225
convertedCandles.getData().forEach(Checker.checkCandle);
228226
}

src/test/java/com/cryptomarket/sdk/TestRestClientSpotTradingHistory.java

Lines changed: 39 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import java.util.List;
44

55
import com.cryptomarket.params.ParamsBuilder;
6+
import com.cryptomarket.params.Sort;
7+
import com.cryptomarket.params.SortBy;
68
import com.cryptomarket.sdk.exceptions.CryptomarketSDKException;
79
import com.cryptomarket.sdk.models.Order;
810
import com.cryptomarket.sdk.models.Trade;
@@ -12,18 +14,41 @@
1214
import org.junit.Test;
1315

1416
public class TestRestClientSpotTradingHistory {
15-
CryptomarketRestClient client = new CryptomarketRestClientImpl(KeyLoader.getApiKey(), KeyLoader.getApiSecret());
16-
17-
@Test
18-
public void testGetOrderHistoryAndGetOrders() throws CryptomarketSDKException {
19-
List<Order> orders = client.getSpotOrderHistory(new ParamsBuilder()
20-
.symbol("EOSETH"));
21-
orders.forEach(Checker.checkOrder);
22-
}
23-
24-
@Test
25-
public void testGetTradingHistory() throws CryptomarketSDKException {
26-
List<Trade> trades = client.getSpotTradesHistory(new ParamsBuilder().limit(12));
27-
trades.forEach(Checker.checkTrade);
28-
}
17+
CryptomarketRestClient client = new CryptomarketRestClientImpl(KeyLoader.getApiKey(), KeyLoader.getApiSecret());
18+
19+
@Test
20+
public void testGetOrderHistoryAndGetOrders() throws CryptomarketSDKException {
21+
List<Order> orders = client.getSpotOrderHistory(new ParamsBuilder()
22+
.symbol("EOSETH"));
23+
orders.forEach(Checker.checkOrder);
24+
}
25+
26+
@Test
27+
public void testGetOrderHistoryAndGetOrdersWithParams() throws CryptomarketSDKException {
28+
List<Order> orders = client.getSpotOrderHistory(new ParamsBuilder()
29+
.by(SortBy.TIMESTAMP)
30+
.sort(Sort.DESC)
31+
.limit(1000)
32+
.offset(0)
33+
.from("1610701510"));
34+
orders.forEach(Checker.checkOrder);
35+
}
36+
37+
@Test
38+
public void testGetTradingHistory() throws CryptomarketSDKException {
39+
List<Trade> trades = client.getSpotTradesHistory(new ParamsBuilder().limit(12));
40+
trades.forEach(Checker.checkTrade);
41+
}
42+
43+
44+
@Test
45+
public void testGetTradingHistoryWithParamsWithParams() throws CryptomarketSDKException {
46+
List<Trade> trades = client.getSpotTradesHistory(new ParamsBuilder()
47+
.by(SortBy.TIMESTAMP)
48+
.sort(Sort.DESC)
49+
.limit(1000)
50+
.offset(0)
51+
.from("1610701510"));
52+
trades.forEach(Checker.checkTrade);
53+
}
2954
}

src/test/java/com/cryptomarket/sdk/TestRestClientWalletManagement.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
import org.junit.Test;
88

99
import com.cryptomarket.params.AccountType;
10+
import com.cryptomarket.params.OrderBy;
1011
import com.cryptomarket.params.ParamsBuilder;
12+
import com.cryptomarket.params.Sort;
1113
import com.cryptomarket.sdk.exceptions.CryptomarketSDKException;
1214
import com.cryptomarket.sdk.models.Address;
1315
import com.cryptomarket.sdk.models.Balance;
@@ -166,6 +168,18 @@ public void testGetTransactionHistory() throws CryptomarketSDKException {
166168
transactions.forEach(Checker.checkTransaction);
167169
}
168170

171+
@Test
172+
public void testGetTransactionHistoryWithParams() throws CryptomarketSDKException {
173+
List<Transaction> transactions = client.getTransactionHistory(new ParamsBuilder()
174+
.orderBy(OrderBy.CREATED_AT)
175+
.sort(Sort.DESC)
176+
.limit(1000)
177+
.offset(0)
178+
.currencies(List.of())
179+
.from("1614815872000"));
180+
transactions.forEach(Checker.checkTransaction);
181+
}
182+
169183
@Test
170184
public void testGetTransaction() throws CryptomarketSDKException {
171185
List<Transaction> transactions = client.getTransactionHistory(new ParamsBuilder().limit(1));

0 commit comments

Comments
 (0)