Skip to content

Commit 96dd5d1

Browse files
authored
Merge pull request knowm#2744 from andre77/gateio-fundshistory
[gateio] Added support for funding history
2 parents bfe8ce9 + a8136e7 commit 96dd5d1

File tree

9 files changed

+303
-62
lines changed

9 files changed

+303
-62
lines changed

xchange-gateio/src/main/java/org/knowm/xchange/gateio/GateioAdapters.java

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
import org.knowm.xchange.currency.CurrencyPair;
1414
import org.knowm.xchange.dto.Order.OrderType;
1515
import org.knowm.xchange.dto.account.Balance;
16+
import org.knowm.xchange.dto.account.FundingRecord;
17+
import org.knowm.xchange.dto.account.FundingRecord.Status;
1618
import org.knowm.xchange.dto.account.Wallet;
1719
import org.knowm.xchange.dto.marketdata.OrderBook;
1820
import org.knowm.xchange.dto.marketdata.Ticker;
@@ -26,6 +28,7 @@
2628
import org.knowm.xchange.dto.trade.UserTrade;
2729
import org.knowm.xchange.dto.trade.UserTrades;
2830
import org.knowm.xchange.gateio.dto.GateioOrderType;
31+
import org.knowm.xchange.gateio.dto.account.GateioDepositsWithdrawals;
2932
import org.knowm.xchange.gateio.dto.account.GateioFunds;
3033
import org.knowm.xchange.gateio.dto.marketdata.GateioDepth;
3134
import org.knowm.xchange.gateio.dto.marketdata.GateioMarketInfoWrapper.GateioMarketInfo;
@@ -237,4 +240,59 @@ public static ExchangeMetaData adaptToExchangeMetaData(
237240

238241
return exchangeMetaData;
239242
}
243+
244+
public static List<FundingRecord> adaptDepositsWithdrawals(
245+
GateioDepositsWithdrawals depositsWithdrawals) {
246+
List<FundingRecord> result = new ArrayList<>();
247+
248+
depositsWithdrawals
249+
.getDeposits()
250+
.forEach(
251+
d -> {
252+
FundingRecord r =
253+
new FundingRecord(
254+
d.address,
255+
d.getTimestamp(),
256+
Currency.getInstance(d.currency),
257+
d.amount,
258+
d.id,
259+
d.txid,
260+
FundingRecord.Type.DEPOSIT,
261+
status(d.status),
262+
null,
263+
null,
264+
null);
265+
result.add(r);
266+
});
267+
depositsWithdrawals
268+
.getWithdraws()
269+
.forEach(
270+
w -> {
271+
FundingRecord r =
272+
new FundingRecord(
273+
w.address,
274+
w.getTimestamp(),
275+
Currency.getInstance(w.currency),
276+
w.amount,
277+
w.id,
278+
w.txid,
279+
FundingRecord.Type.WITHDRAWAL,
280+
status(w.status),
281+
null,
282+
null,
283+
null);
284+
result.add(r);
285+
});
286+
287+
return result;
288+
}
289+
290+
private static FundingRecord.Status status(String gateioStatus) {
291+
switch (gateioStatus) {
292+
case "DONE":
293+
return Status.COMPLETE;
294+
default:
295+
return Status.PROCESSING; // @TODO which statusses are possible at gate.io?
296+
}
297+
}
240298
}

xchange-gateio/src/main/java/org/knowm/xchange/gateio/GateioAuthenticated.java

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@
1111
import javax.ws.rs.core.MediaType;
1212
import org.knowm.xchange.gateio.dto.GateioBaseResponse;
1313
import org.knowm.xchange.gateio.dto.account.GateioDepositAddress;
14+
import org.knowm.xchange.gateio.dto.account.GateioDepositsWithdrawals;
1415
import org.knowm.xchange.gateio.dto.account.GateioFunds;
1516
import org.knowm.xchange.gateio.dto.trade.GateioOpenOrders;
1617
import org.knowm.xchange.gateio.dto.trade.GateioOrderStatus;
1718
import org.knowm.xchange.gateio.dto.trade.GateioPlaceOrderReturn;
1819
import org.knowm.xchange.gateio.dto.trade.GateioTradeHistoryReturn;
1920
import si.mazi.rescu.ParamsDigest;
20-
import si.mazi.rescu.SynchronizedValueFactory;
2121

2222
@Path("api2/1")
2323
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
@@ -26,10 +26,7 @@ public interface GateioAuthenticated extends Gateio {
2626

2727
@POST
2828
@Path("private/balances")
29-
GateioFunds getFunds(
30-
@HeaderParam("KEY") String apiKey,
31-
@HeaderParam("SIGN") ParamsDigest signer,
32-
@FormParam("nonce") SynchronizedValueFactory<Long> nonce)
29+
GateioFunds getFunds(@HeaderParam("KEY") String apiKey, @HeaderParam("SIGN") ParamsDigest signer)
3330
throws IOException;
3431

3532
@POST
@@ -46,7 +43,7 @@ GateioBaseResponse withdraw(
4643
@HeaderParam("KEY") String apiKey,
4744
@HeaderParam("SIGN") ParamsDigest signer,
4845
@FormParam("currency") String currency,
49-
@FormParam("amount") String amount,
46+
@FormParam("amount") BigDecimal amount,
5047
@FormParam("address") String address)
5148
throws IOException;
5249

@@ -56,8 +53,7 @@ GateioBaseResponse cancelOrder(
5653
@FormParam("orderNumber") String orderNumber,
5754
@FormParam("currencyPair") String currencyPair,
5855
@HeaderParam("KEY") String apiKey,
59-
@HeaderParam("SIGN") ParamsDigest signer,
60-
@FormParam("nonce") SynchronizedValueFactory<Long> nonce)
56+
@HeaderParam("SIGN") ParamsDigest signer)
6157
throws IOException;
6258

6359
@POST
@@ -66,8 +62,7 @@ GateioBaseResponse cancelAllOrders(
6662
@FormParam("type") String type,
6763
@FormParam("currencyPair") String currencyPair,
6864
@HeaderParam("KEY") String apiKey,
69-
@HeaderParam("SIGN") ParamsDigest signer,
70-
@FormParam("nonce") SynchronizedValueFactory<Long> nonce)
65+
@HeaderParam("SIGN") ParamsDigest signer)
7166
throws IOException;
7267

7368
@POST
@@ -77,8 +72,7 @@ GateioPlaceOrderReturn buy(
7772
@FormParam("rate") BigDecimal rate,
7873
@FormParam("amount") BigDecimal amount,
7974
@HeaderParam("KEY") String apiKey,
80-
@HeaderParam("SIGN") ParamsDigest signer,
81-
@FormParam("nonce") SynchronizedValueFactory<Long> nonce)
75+
@HeaderParam("SIGN") ParamsDigest signer)
8276
throws IOException;
8377

8478
@POST
@@ -88,33 +82,37 @@ GateioPlaceOrderReturn sell(
8882
@FormParam("rate") BigDecimal rate,
8983
@FormParam("amount") BigDecimal amount,
9084
@HeaderParam("KEY") String apiKey,
91-
@HeaderParam("SIGN") ParamsDigest signer,
92-
@FormParam("nonce") SynchronizedValueFactory<Long> nonce)
85+
@HeaderParam("SIGN") ParamsDigest signer)
9386
throws IOException;
9487

9588
@POST
9689
@Path("private/openOrders")
9790
GateioOpenOrders getOpenOrders(
98-
@HeaderParam("KEY") String apiKey,
99-
@HeaderParam("SIGN") ParamsDigest signer,
100-
@FormParam("nonce") SynchronizedValueFactory<Long> nonce)
91+
@HeaderParam("KEY") String apiKey, @HeaderParam("SIGN") ParamsDigest signer)
10192
throws IOException;
10293

10394
@POST
10495
@Path("private/tradeHistory")
10596
GateioTradeHistoryReturn getUserTradeHistory(
10697
@HeaderParam("KEY") String apiKey,
10798
@HeaderParam("SIGN") ParamsDigest signer,
108-
@FormParam("nonce") SynchronizedValueFactory<Long> nonce,
10999
@FormParam("currencyPair") String currencyPair)
110100
throws IOException;
111101

102+
@POST
103+
@Path("private/depositsWithdrawals")
104+
GateioDepositsWithdrawals getDepositsWithdrawals(
105+
@HeaderParam("KEY") String apiKey,
106+
@HeaderParam("SIGN") ParamsDigest signer,
107+
@FormParam("start") Long startUnixTime,
108+
@FormParam("end") Long endUnixTime)
109+
throws IOException;
110+
112111
@POST
113112
@Path("private/getorder")
114113
GateioOrderStatus getOrderStatus(
115114
@FormParam("order_id") String orderId,
116115
@HeaderParam("KEY") String apiKey,
117-
@HeaderParam("SIGN") ParamsDigest signer,
118-
@FormParam("nonce") SynchronizedValueFactory<Long> nonce)
116+
@HeaderParam("SIGN") ParamsDigest signer)
119117
throws IOException;
120118
}

xchange-gateio/src/main/java/org/knowm/xchange/gateio/GateioExchange.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,16 @@
66
import org.knowm.xchange.Exchange;
77
import org.knowm.xchange.ExchangeSpecification;
88
import org.knowm.xchange.currency.CurrencyPair;
9+
import org.knowm.xchange.exceptions.ExchangeException;
910
import org.knowm.xchange.gateio.dto.marketdata.GateioMarketInfoWrapper.GateioMarketInfo;
1011
import org.knowm.xchange.gateio.service.GateioAccountService;
1112
import org.knowm.xchange.gateio.service.GateioMarketDataService;
1213
import org.knowm.xchange.gateio.service.GateioMarketDataServiceRaw;
1314
import org.knowm.xchange.gateio.service.GateioTradeService;
14-
import org.knowm.xchange.utils.nonce.AtomicLongIncrementalTime2013NonceFactory;
1515
import si.mazi.rescu.SynchronizedValueFactory;
1616

1717
public class GateioExchange extends BaseExchange implements Exchange {
1818

19-
private SynchronizedValueFactory<Long> nonceFactory =
20-
new AtomicLongIncrementalTime2013NonceFactory();
21-
2219
@Override
2320
protected void initServices() {
2421
this.marketDataService = new GateioMarketDataService(this);
@@ -41,7 +38,7 @@ public ExchangeSpecification getDefaultExchangeSpecification() {
4138
@Override
4239
public SynchronizedValueFactory<Long> getNonceFactory() {
4340

44-
return nonceFactory;
41+
throw new ExchangeException("Gate.io does not require a nonce factory.");
4542
}
4643

4744
@Override
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
package org.knowm.xchange.gateio.dto.account;
2+
3+
import com.fasterxml.jackson.annotation.JsonProperty;
4+
import java.math.BigDecimal;
5+
import java.util.Date;
6+
7+
public class GateioDeposit {
8+
9+
public final String id;
10+
public final String currency;
11+
public final String address;
12+
public final BigDecimal amount;
13+
public final String txid;
14+
public final long timestamp;
15+
public final String status;
16+
17+
public GateioDeposit(
18+
@JsonProperty("id") String id,
19+
@JsonProperty("currency") String currency,
20+
@JsonProperty("address") String address,
21+
@JsonProperty("amount") BigDecimal amount,
22+
@JsonProperty("txid") String txid,
23+
@JsonProperty("timestamp") long timestamp,
24+
@JsonProperty("status") String status) {
25+
this.id = id;
26+
this.currency = currency;
27+
this.address = address;
28+
this.amount = amount;
29+
this.txid = txid;
30+
this.timestamp = timestamp;
31+
this.status = status;
32+
}
33+
34+
public Date getTimestamp() {
35+
return new Date(timestamp * 1000);
36+
}
37+
38+
@Override
39+
public String toString() {
40+
return "GateioDeposit [id="
41+
+ id
42+
+ ", currency="
43+
+ currency
44+
+ ", address="
45+
+ address
46+
+ ", amount="
47+
+ amount
48+
+ ", txid="
49+
+ txid
50+
+ ", status="
51+
+ status
52+
+ ", getTimestamp()="
53+
+ getTimestamp()
54+
+ "]";
55+
}
56+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package org.knowm.xchange.gateio.dto.account;
2+
3+
import com.fasterxml.jackson.annotation.JsonProperty;
4+
import java.util.List;
5+
import org.knowm.xchange.gateio.dto.GateioBaseResponse;
6+
7+
public class GateioDepositsWithdrawals extends GateioBaseResponse {
8+
9+
private final List<GateioDeposit> deposits;
10+
private final List<GateioWithdrawal> withdraws;
11+
12+
public GateioDepositsWithdrawals(
13+
@JsonProperty("result") boolean result,
14+
@JsonProperty("deposits") List<GateioDeposit> deposits,
15+
@JsonProperty("withdraws") List<GateioWithdrawal> withdraws,
16+
@JsonProperty("message") final String message) {
17+
super(result, message);
18+
this.deposits = deposits;
19+
this.withdraws = withdraws;
20+
}
21+
22+
public List<GateioDeposit> getDeposits() {
23+
return deposits;
24+
}
25+
26+
public List<GateioWithdrawal> getWithdraws() {
27+
return withdraws;
28+
}
29+
30+
@Override
31+
public String toString() {
32+
return "GateioDepositsWithdrawals [deposits=" + deposits + ", withdraws=" + withdraws + "]";
33+
}
34+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
package org.knowm.xchange.gateio.dto.account;
2+
3+
import com.fasterxml.jackson.annotation.JsonProperty;
4+
import java.math.BigDecimal;
5+
import java.util.Date;
6+
7+
public class GateioWithdrawal {
8+
9+
public final String id;
10+
public final String currency;
11+
public final String address;
12+
public final BigDecimal amount;
13+
public final String txid;
14+
public final long timestamp;
15+
public final String status;
16+
17+
public GateioWithdrawal(
18+
@JsonProperty("id") String id,
19+
@JsonProperty("currency") String currency,
20+
@JsonProperty("address") String address,
21+
@JsonProperty("amount") BigDecimal amount,
22+
@JsonProperty("txid") String txid,
23+
@JsonProperty("timestamp") long timestamp,
24+
@JsonProperty("status") String status) {
25+
this.id = id;
26+
this.currency = currency;
27+
this.address = address;
28+
this.amount = amount;
29+
this.txid = txid;
30+
this.timestamp = timestamp;
31+
this.status = status;
32+
}
33+
34+
public Date getTimestamp() {
35+
return new Date(timestamp * 1000);
36+
}
37+
38+
@Override
39+
public String toString() {
40+
return "GateioDeposit [id="
41+
+ id
42+
+ ", currency="
43+
+ currency
44+
+ ", address="
45+
+ address
46+
+ ", amount="
47+
+ amount
48+
+ ", txid="
49+
+ txid
50+
+ ", status="
51+
+ status
52+
+ ", getTimestamp()="
53+
+ getTimestamp()
54+
+ "]";
55+
}
56+
}

0 commit comments

Comments
 (0)