Skip to content

Commit 6fa9e64

Browse files
authored
Merge pull request #4993 from donald-jackson/fixes/20240925-bitstamp-internal
[bitstamp] fix for "None" fees and internal settlements
2 parents 624c31c + afa6297 commit 6fa9e64

File tree

2 files changed

+25
-10
lines changed

2 files changed

+25
-10
lines changed

xchange-bitstamp/src/main/java/org/knowm/xchange/bitstamp/BitstampAdapters.java

+13-2
Original file line numberDiff line numberDiff line change
@@ -242,14 +242,25 @@ public static UserTrades adaptTradeHistory(BitstampUserTransaction[] bitstampUse
242242
.timestamp(t.getDatetime())
243243
.id(Long.toString(tradeId))
244244
.orderId(Long.toString(t.getOrderId()))
245-
.feeAmount(t.getFee())
245+
.feeAmount(getFeeFromString(t.getFee()))
246246
.feeCurrency(Currency.getInstance(t.getFeeCurrency().toUpperCase()))
247247
.build();
248248
trades.add(trade);
249249
}
250250
return new UserTrades(trades, lastTradeId, TradeSortType.SortByID);
251251
}
252252

253+
private static BigDecimal getFeeFromString(String value) {
254+
if ("None".equals(value)) {
255+
return BigDecimal.ZERO;
256+
}
257+
try {
258+
return new BigDecimal(value);
259+
} catch (NumberFormatException e) {
260+
return BigDecimal.ZERO;
261+
}
262+
}
263+
253264
public static Map.Entry<String, BigDecimal> findNonzeroAmount(BitstampUserTransaction transaction)
254265
throws ExchangeException {
255266
for (Map.Entry<String, BigDecimal> entry : transaction.getAmounts().entrySet()) {
@@ -294,7 +305,7 @@ public static List<FundingRecord> adaptFundingHistory(
294305
type,
295306
FundingRecord.Status.COMPLETE,
296307
null,
297-
trans.getFee(),
308+
getFeeFromString(trans.getFee()),
298309
null);
299310
fundingRecords.add(record);
300311
}

xchange-bitstamp/src/main/java/org/knowm/xchange/bitstamp/dto/trade/BitstampUserTransaction.java

+12-8
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public final class BitstampUserTransaction {
2020
private final long id;
2121
private final long order_id;
2222
private final TransactionType type;
23-
private final BigDecimal fee;
23+
private final String fee;
2424
private final Map<String, BigDecimal> amounts = new HashMap<>();
2525
// possible pairs at the moment: btcusd, btceur, eurusd, xrpusd, xrpeur, xrpbtc
2626
private String base; // btc, eur, xrp
@@ -41,7 +41,7 @@ public BitstampUserTransaction(
4141
@JsonProperty("id") long id,
4242
@JsonProperty("order_id") long order_id,
4343
@JsonProperty("type") TransactionType type,
44-
@JsonProperty("fee") BigDecimal fee) {
44+
@JsonProperty("fee") String fee) {
4545

4646
this.datetime = BitstampUtils.parseDate(datetime);
4747
this.id = id;
@@ -88,19 +88,19 @@ public TransactionType getType() {
8888
}
8989

9090
public boolean isDeposit() {
91-
return type == TransactionType.deposit;
91+
return type == TransactionType.deposit || type == TransactionType.rippleDeposit;
9292
}
9393

9494
public boolean isWithdrawal() {
95-
return type == TransactionType.withdrawal;
95+
return type == TransactionType.withdrawal || type == TransactionType.rippleWithdrawal;
9696
}
9797

9898
public boolean isMarketTrade() {
9999
return type == TransactionType.trade;
100100
}
101101

102102
public boolean isSubAccountTransfer() {
103-
return type == TransactionType.subAccountTransfer;
103+
return type == TransactionType.subAccountTransfer || type == TransactionType.settlementTransfer;
104104
}
105105

106106
public BigDecimal getCounterAmount() {
@@ -123,7 +123,7 @@ public String getBaseCurrency() {
123123
return base;
124124
}
125125

126-
public BigDecimal getFee() {
126+
public String getFee() {
127127
return fee;
128128
}
129129

@@ -169,7 +169,9 @@ public enum TransactionType {
169169
sentAssetsToStaking,
170170
stakingReward,
171171
referralReward,
172-
interAccountTransfer;
172+
interAccountTransfer,
173+
settlementTransfer,
174+
unknown;
173175

174176
@JsonCreator
175177
public static TransactionType fromString(int type) {
@@ -194,10 +196,12 @@ public static TransactionType fromString(int type) {
194196
return stakingReward;
195197
case 32:
196198
return referralReward;
199+
case 33:
200+
return settlementTransfer;
197201
case 35:
198202
return interAccountTransfer;
199203
default:
200-
throw new IllegalArgumentException(type + " has no corresponding value");
204+
return unknown;
201205
}
202206
}
203207
}

0 commit comments

Comments
 (0)