Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[bitstamp] fix for "None" fees and internal settlements #4993

Merged
Original file line number Diff line number Diff line change
Expand Up @@ -242,14 +242,25 @@ public static UserTrades adaptTradeHistory(BitstampUserTransaction[] bitstampUse
.timestamp(t.getDatetime())
.id(Long.toString(tradeId))
.orderId(Long.toString(t.getOrderId()))
.feeAmount(t.getFee())
.feeAmount(getFeeFromString(t.getFee()))
.feeCurrency(Currency.getInstance(t.getFeeCurrency().toUpperCase()))
.build();
trades.add(trade);
}
return new UserTrades(trades, lastTradeId, TradeSortType.SortByID);
}

private static BigDecimal getFeeFromString(String value) {
if ("None".equals(value)) {
return BigDecimal.ZERO;
}
try {
return new BigDecimal(value);
} catch (NumberFormatException e) {
return BigDecimal.ZERO;
}
}

public static Map.Entry<String, BigDecimal> findNonzeroAmount(BitstampUserTransaction transaction)
throws ExchangeException {
for (Map.Entry<String, BigDecimal> entry : transaction.getAmounts().entrySet()) {
Expand Down Expand Up @@ -294,7 +305,7 @@ public static List<FundingRecord> adaptFundingHistory(
type,
FundingRecord.Status.COMPLETE,
null,
trans.getFee(),
getFeeFromString(trans.getFee()),
null);
fundingRecords.add(record);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public final class BitstampUserTransaction {
private final long id;
private final long order_id;
private final TransactionType type;
private final BigDecimal fee;
private final String fee;
private final Map<String, BigDecimal> amounts = new HashMap<>();
// possible pairs at the moment: btcusd, btceur, eurusd, xrpusd, xrpeur, xrpbtc
private String base; // btc, eur, xrp
Expand All @@ -41,7 +41,7 @@ public BitstampUserTransaction(
@JsonProperty("id") long id,
@JsonProperty("order_id") long order_id,
@JsonProperty("type") TransactionType type,
@JsonProperty("fee") BigDecimal fee) {
@JsonProperty("fee") String fee) {

this.datetime = BitstampUtils.parseDate(datetime);
this.id = id;
Expand Down Expand Up @@ -88,19 +88,19 @@ public TransactionType getType() {
}

public boolean isDeposit() {
return type == TransactionType.deposit;
return type == TransactionType.deposit || type == TransactionType.rippleDeposit;
}

public boolean isWithdrawal() {
return type == TransactionType.withdrawal;
return type == TransactionType.withdrawal || type == TransactionType.rippleWithdrawal;
}

public boolean isMarketTrade() {
return type == TransactionType.trade;
}

public boolean isSubAccountTransfer() {
return type == TransactionType.subAccountTransfer;
return type == TransactionType.subAccountTransfer || type == TransactionType.settlementTransfer;
}

public BigDecimal getCounterAmount() {
Expand All @@ -123,7 +123,7 @@ public String getBaseCurrency() {
return base;
}

public BigDecimal getFee() {
public String getFee() {
return fee;
}

Expand Down Expand Up @@ -169,7 +169,9 @@ public enum TransactionType {
sentAssetsToStaking,
stakingReward,
referralReward,
interAccountTransfer;
interAccountTransfer,
settlementTransfer,
unknown;

@JsonCreator
public static TransactionType fromString(int type) {
Expand All @@ -194,10 +196,12 @@ public static TransactionType fromString(int type) {
return stakingReward;
case 32:
return referralReward;
case 33:
return settlementTransfer;
case 35:
return interAccountTransfer;
default:
throw new IllegalArgumentException(type + " has no corresponding value");
return unknown;
}
}
}
Expand Down