Skip to content

Commit 40e4d27

Browse files
committed
fix: order by in transaction history
1 parent bb09ef9 commit 40e4d27

File tree

5 files changed

+54
-2
lines changed

5 files changed

+54
-2
lines changed
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/test/java/com/cryptomarket/sdk/TestRestClientWalletManagement.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@
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;
13+
import com.cryptomarket.params.SortBy;
1114
import com.cryptomarket.sdk.exceptions.CryptomarketSDKException;
1215
import com.cryptomarket.sdk.models.Address;
1316
import com.cryptomarket.sdk.models.Balance;
@@ -163,6 +166,19 @@ public void testTransferBetweenWalletAndExchage() throws CryptomarketSDKExceptio
163166
@Test
164167
public void testGetTransactionHistory() throws CryptomarketSDKException {
165168
List<Transaction> transactions = client.getTransactionHistory(new ParamsBuilder());
169+
transactions.stream().forEach(System.out::println);
170+
transactions.forEach(Checker.checkTransaction);
171+
}
172+
173+
@Test
174+
public void testGetTransactionHistoryWithParams() throws CryptomarketSDKException {
175+
List<Transaction> transactions = client.getTransactionHistory(new ParamsBuilder()
176+
.orderBy(OrderBy.CREATED_AT)
177+
.sort(Sort.DESC)
178+
.limit(1000)
179+
.offset(0)
180+
.currencies(List.of())
181+
.from("1614815872000"));
166182
transactions.forEach(Checker.checkTransaction);
167183
}
168184

0 commit comments

Comments
 (0)