Skip to content

Commit 0803acc

Browse files
committed
[coinmate] attempt to get transaction hash from the deposit description, fixed getFundingHistory, fixed getTradeHistory
1 parent bddcfde commit 0803acc

File tree

3 files changed

+119
-23
lines changed

3 files changed

+119
-23
lines changed

xchange-coinmate/src/main/java/org/knowm/xchange/coinmate/CoinmateAdapters.java

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -194,9 +194,27 @@ public static List<FundingRecord> adaptFundingHistory(CoinmateTransactionHistory
194194

195195
String transactionId = Long.toString(entry.getTransactionId());
196196

197-
FundingRecord funding = new FundingRecord(null,
198-
new Date(entry.getTimestamp()), Currency.getInstance(entry.getAmountCurrency()), entry.getAmount(),
199-
transactionId, transactionId , type, status, null, entry.getFee(), entry.getDescription());
197+
String description = entry.getDescription();
198+
199+
String feeCurrency = entry.getFeeCurrency();
200+
String externalId = null;
201+
if (entry.getTransactionType().equals("DEPOSIT") && description.startsWith(feeCurrency + ": ")) {
202+
externalId = description.replace(feeCurrency + ": ", "");//the transaction hash is in the description
203+
}
204+
205+
FundingRecord funding = new FundingRecord(
206+
null,
207+
new Date(entry.getTimestamp()),
208+
Currency.getInstance(entry.getAmountCurrency()),
209+
entry.getAmount(),
210+
transactionId,
211+
externalId,
212+
type,
213+
status,
214+
null,
215+
entry.getFee(),
216+
description
217+
);
200218

201219
fundings.add(funding);
202220
}

xchange-coinmate/src/main/java/org/knowm/xchange/coinmate/service/CoinmateAccountService.java

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,14 @@
3131
import org.knowm.xchange.coinmate.CoinmateAdapters;
3232
import org.knowm.xchange.coinmate.dto.account.CoinmateDepositAddresses;
3333
import org.knowm.xchange.coinmate.dto.trade.CoinmateTradeResponse;
34+
import org.knowm.xchange.coinmate.dto.trade.CoinmateTransactionHistory;
3435
import org.knowm.xchange.currency.Currency;
3536
import org.knowm.xchange.dto.account.AccountInfo;
3637
import org.knowm.xchange.dto.account.FundingRecord;
37-
import org.knowm.xchange.exceptions.NotAvailableFromExchangeException;
3838
import org.knowm.xchange.service.account.AccountService;
39-
import org.knowm.xchange.service.trade.params.DefaultTradeHistoryParamPagingSorted;
4039
import org.knowm.xchange.service.trade.params.DefaultWithdrawFundsParams;
40+
import org.knowm.xchange.service.trade.params.TradeHistoryParamLimit;
41+
import org.knowm.xchange.service.trade.params.TradeHistoryParamOffset;
4142
import org.knowm.xchange.service.trade.params.TradeHistoryParams;
4243
import org.knowm.xchange.service.trade.params.TradeHistoryParamsSorted;
4344
import org.knowm.xchange.service.trade.params.WithdrawFundsParams;
@@ -90,15 +91,33 @@ public String requestDepositAddress(Currency currency,
9091

9192
@Override
9293
public TradeHistoryParams createFundingHistoryParams() {
93-
return new DefaultTradeHistoryParamPagingSorted(DEFAULT_RESULT_LIMIT, TradeHistoryParamsSorted.Order.asc);
94+
return new CoinmateFundingHistoryParams();
9495
}
9596

9697
@Override
9798
public List<FundingRecord> getFundingHistory(
9899
TradeHistoryParams params) throws IOException {
99100

100-
DefaultTradeHistoryParamPagingSorted myParams = (DefaultTradeHistoryParamPagingSorted) params;
101-
return CoinmateAdapters.adaptFundingHistory(
102-
getCoinmateTransactionHistory(myParams.getPageNumber(), myParams.getPageLength(), CoinmateAdapters.adaptSortOrder(myParams.getOrder())));
101+
TradeHistoryParamsSorted.Order order = TradeHistoryParamsSorted.Order.asc;
102+
int limit = 1000;
103+
int offset = 0;
104+
105+
if (params instanceof TradeHistoryParamOffset) {
106+
offset = Math.toIntExact(((TradeHistoryParamOffset) params).getOffset());
107+
}
108+
109+
if (params instanceof TradeHistoryParamLimit) {
110+
limit = ((TradeHistoryParamLimit) params).getLimit();
111+
}
112+
113+
if (params instanceof TradeHistoryParamsSorted) {
114+
order = ((TradeHistoryParamsSorted) params).getOrder();
115+
}
116+
117+
CoinmateTransactionHistory coinmateTransactionHistory = getCoinmateTransactionHistory(offset, limit, CoinmateAdapters.adaptSortOrder(order));
118+
return CoinmateAdapters.adaptFundingHistory(coinmateTransactionHistory);
119+
}
120+
121+
public static class CoinmateFundingHistoryParams extends CoinmateTradeService.CoinmateTradeHistoryHistoryParams {
103122
}
104123
}

xchange-coinmate/src/main/java/org/knowm/xchange/coinmate/service/CoinmateTradeService.java

Lines changed: 73 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
/*
22
* The MIT License
3-
*
3+
*
44
* Copyright 2015-2016 Coinmate.
5-
*
5+
*
66
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in
77
* the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
88
* the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
9-
*
9+
*
1010
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
11-
*
11+
*
1212
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
1313
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
1414
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -27,6 +27,7 @@
2727
import org.knowm.xchange.coinmate.dto.trade.CoinmateCancelOrderResponse;
2828
import org.knowm.xchange.coinmate.dto.trade.CoinmateOpenOrders;
2929
import org.knowm.xchange.coinmate.dto.trade.CoinmateTradeResponse;
30+
import org.knowm.xchange.coinmate.dto.trade.CoinmateTransactionHistory;
3031
import org.knowm.xchange.currency.CurrencyPair;
3132
import org.knowm.xchange.dto.Order;
3233
import org.knowm.xchange.dto.trade.LimitOrder;
@@ -37,7 +38,8 @@
3738
import org.knowm.xchange.service.trade.TradeService;
3839
import org.knowm.xchange.service.trade.params.CancelOrderByIdParams;
3940
import org.knowm.xchange.service.trade.params.CancelOrderParams;
40-
import org.knowm.xchange.service.trade.params.DefaultTradeHistoryParamPagingSorted;
41+
import org.knowm.xchange.service.trade.params.TradeHistoryParamLimit;
42+
import org.knowm.xchange.service.trade.params.TradeHistoryParamOffset;
4143
import org.knowm.xchange.service.trade.params.TradeHistoryParams;
4244
import org.knowm.xchange.service.trade.params.TradeHistoryParamsSorted;
4345
import org.knowm.xchange.service.trade.params.orders.OpenOrdersParamCurrencyPair;
@@ -122,19 +124,29 @@ public boolean cancelOrder(CancelOrderParams orderParams) throws IOException {
122124

123125
@Override
124126
public UserTrades getTradeHistory(TradeHistoryParams params) throws IOException {
125-
// here we use the Transaction History call, which includes also withdrawals etc.
126-
// there is also Order History call, but this returns orders rather than trades
127-
DefaultTradeHistoryParamPagingSorted myParams = (DefaultTradeHistoryParamPagingSorted) params;
128-
return CoinmateAdapters.adaptTransactionHistory(
129-
getCoinmateTradeHistory(myParams.getPageNumber(), myParams.getPageLength(), CoinmateAdapters.adaptSortOrder(myParams.getOrder())));
127+
TradeHistoryParamsSorted.Order order = TradeHistoryParamsSorted.Order.asc;
128+
int limit = 1000;
129+
int offset = 0;
130+
131+
if (params instanceof TradeHistoryParamOffset) {
132+
offset = Math.toIntExact(((TradeHistoryParamOffset) params).getOffset());
133+
}
134+
135+
if (params instanceof TradeHistoryParamLimit) {
136+
limit = ((TradeHistoryParamLimit) params).getLimit();
137+
}
138+
139+
if (params instanceof TradeHistoryParamsSorted) {
140+
order = ((TradeHistoryParamsSorted) params).getOrder();
141+
}
142+
143+
CoinmateTransactionHistory coinmateTradeHistory = getCoinmateTradeHistory(offset, limit, CoinmateAdapters.adaptSortOrder(order));
144+
return CoinmateAdapters.adaptTransactionHistory(coinmateTradeHistory);
130145
}
131146

132147
@Override
133148
public TradeHistoryParams createTradeHistoryParams() {
134-
DefaultTradeHistoryParamPagingSorted params = new DefaultTradeHistoryParamPagingSorted(100);
135-
params.setPageNumber(0);
136-
params.setOrder(TradeHistoryParamsSorted.Order.asc);
137-
return params;
149+
return new CoinmateTradeHistoryHistoryParams();
138150
}
139151

140152
@Override
@@ -148,4 +160,51 @@ public Collection<Order> getOrder(
148160
throw new NotYetImplementedForExchangeException();
149161
}
150162

163+
public static class CoinmateTradeHistoryHistoryParams implements TradeHistoryParamOffset, TradeHistoryParamLimit, TradeHistoryParamsSorted {
164+
165+
private Integer limit;
166+
private Long offset;
167+
private Order order;
168+
169+
public CoinmateTradeHistoryHistoryParams(Integer limit, Long offset, Order order) {
170+
this.limit = limit;
171+
this.offset = offset;
172+
this.order = order;
173+
}
174+
175+
public CoinmateTradeHistoryHistoryParams() {
176+
this(100, 0L, Order.asc);
177+
}
178+
179+
@Override
180+
public void setLimit(Integer limit) {
181+
this.limit = limit;
182+
}
183+
184+
@Override
185+
public Integer getLimit() {
186+
return limit;
187+
}
188+
189+
@Override
190+
public void setOffset(Long offset) {
191+
this.offset = offset;
192+
}
193+
194+
@Override
195+
public Long getOffset() {
196+
return offset;
197+
}
198+
199+
@Override
200+
public Order getOrder() {
201+
return order;
202+
}
203+
204+
@Override
205+
public void setOrder(Order order) {
206+
this.order = order;
207+
}
208+
}
209+
151210
}

0 commit comments

Comments
 (0)