Skip to content

Commit 359dee5

Browse files
authored
Merge pull request knowm#2605 from pogodin/exclude-livecoin-xbt
[Livecoin] Exclude currency Bricktox(XBT)
2 parents a00ae5f + 6ab31b0 commit 359dee5

2 files changed

Lines changed: 63 additions & 2 deletions

File tree

xchange-livecoin/src/main/java/org/knowm/xchange/livecoin/LivecoinAdapters.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -265,15 +265,22 @@ public static List<Wallet> adaptWallets(List<Map> data) {
265265
String ccy = balance.get("currency").toString();
266266
String value = balance.get("value").toString();
267267

268+
// Livecoin has a currency Bricktox (XBT) which is different from XChange Bitcoin (XBT). See Currency.XBT.
269+
// The "get all currencies" call to Livecoin returns all currencies including those with 0 balance.
270+
// As a result, XBT overrides BTC, so BTC becomes 0 (in most cases).
271+
// Excluding XBT.
272+
if (ccy.equals("XBT")) {
273+
continue;
274+
}
275+
268276
Currency curr = getInstance(ccy);
269277

270278
WalletBuilder builder = wallets.get(curr);
271279
if (builder == null) {
272280
builder = new WalletBuilder(curr);
281+
wallets.put(curr, builder);
273282
}
274283
builder.add(type, value);
275-
276-
wallets.put(curr, builder);
277284
}
278285

279286
List<Wallet> res = new ArrayList<>();
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package org.knowm.xchange.livecoin;
2+
3+
import static org.junit.Assert.assertTrue;
4+
5+
import java.math.BigDecimal;
6+
import java.util.Arrays;
7+
import java.util.HashMap;
8+
import java.util.List;
9+
import java.util.Map;
10+
import org.junit.Test;
11+
import org.knowm.xchange.currency.Currency;
12+
import org.knowm.xchange.dto.account.Balance;
13+
import org.knowm.xchange.dto.account.Wallet;
14+
15+
public class LivecoinAdaptersTest {
16+
@Test
17+
public void liveCoinAdapterTest() {
18+
List<Map> response = Arrays.asList(
19+
responseItem("total", "USD", "16.45759873"),
20+
responseItem("trade", "USD", "0.0"),
21+
responseItem("available", "USD", "16.45759873"),
22+
23+
responseItem("total", "BTC", "0.00671945"),
24+
responseItem("trade", "BTC", "0.1"),
25+
responseItem("available", "BTC", "0.00671945"),
26+
27+
responseItem("total", "XBT", "0.0"),
28+
responseItem("trade", "XBT", "0.0"),
29+
responseItem("available", "XBT", "0.0")
30+
);
31+
32+
List<Wallet> wallets = LivecoinAdapters.adaptWallets(response);
33+
34+
assertTrue(wallets.contains(wallet(Currency.USD, "16.45759873", "0.0", "16.45759873")));
35+
assertTrue(wallets.contains(wallet(Currency.BTC, "0.00671945", "0.1", "0.00671945")));
36+
}
37+
38+
private static Map<String, String> responseItem(String type, String currency, String balance) {
39+
HashMap<String, String> map = new HashMap<>();
40+
map.put("type", type);
41+
map.put("currency", currency);
42+
map.put("value", balance);
43+
return map;
44+
}
45+
46+
private static Wallet wallet(Currency currency, String total, String trade, String available) {
47+
return new Wallet(currency.getCurrencyCode(),
48+
new Balance.Builder().currency(currency)
49+
.total(new BigDecimal(total))
50+
.available(new BigDecimal(available))
51+
.frozen(new BigDecimal(trade))
52+
.build());
53+
}
54+
}

0 commit comments

Comments
 (0)