forked from luno/luno-java
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLunoAPIImpl.java
190 lines (157 loc) · 6.9 KB
/
LunoAPIImpl.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
package com.luno;
import java.io.IOException;
import java.math.BigDecimal;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
import si.mazi.rescu.BasicAuthCredentials;
import si.mazi.rescu.RestProxyFactory;
import com.luno.dto.LunoBoolean;
import com.luno.dto.LunoException;
import com.luno.dto.account.LunoAccount;
import com.luno.dto.account.LunoAccountTransactions;
import com.luno.dto.account.LunoBalance;
import com.luno.dto.account.LunoFundingAddress;
import com.luno.dto.account.LunoPendingTransactions;
import com.luno.dto.account.LunoQuote;
import com.luno.dto.account.LunoWithdrawals;
import com.luno.dto.account.LunoWithdrawals.Withdrawal;
import com.luno.dto.marketdata.LunoOrderBook;
import com.luno.dto.marketdata.LunoTicker;
import com.luno.dto.marketdata.LunoTickers;
import com.luno.dto.marketdata.LunoTrades;
import com.luno.dto.trade.LunoFeeInfo;
import com.luno.dto.trade.LunoOrders;
import com.luno.dto.trade.LunoOrders.Order;
import com.luno.dto.trade.LunoPostOrder;
import com.luno.dto.trade.OrderType;
import com.luno.dto.trade.State;
public class LunoAPIImpl implements LunoAPI {
private final static String URI = "https://api.mybitx.com";
private final LunoAuthenticated luno;
private final BasicAuthCredentials auth;
public LunoAPIImpl(String key, String secret) {
this(key, secret, URI);
}
public LunoAPIImpl(String key, String secret, String uri) {
luno = RestProxyFactory.createProxy(LunoAuthenticated.class, uri);
auth = new BasicAuthCredentials(key, secret);
}
@Override
public LunoTicker ticker(String pair) throws IOException, LunoException {
return luno.ticker(pair);
}
@Override
public LunoTickers tickers() throws IOException, LunoException {
return luno.tickers();
}
@Override
public LunoOrderBook orderbook(String pair) throws IOException, LunoException {
return luno.orderbook(pair);
}
@Override
public LunoTrades trades(String pair, Long since) throws IOException, LunoException {
return luno.trades(pair, since);
}
@Override
public LunoAccount createAccount(String currency, String name) throws IOException, LunoException {
return luno.createAccount(this.auth, currency, name);
}
@Override
public LunoBalance balance() throws IOException, LunoException {
return luno.balance(this.auth);
}
@Override
public LunoAccountTransactions transactions(String id, int minRow, int maxRow) throws IOException,
LunoException {
return luno.transactions(this.auth, id, minRow, maxRow);
}
@Override
public LunoPendingTransactions pendingTransactions(String id) throws IOException, LunoException {
return luno.pendingTransactions(this.auth, id);
}
@Override
public LunoOrders listOrders(State state, String pair) throws IOException, LunoException {
return luno.listOrders(this.auth, state, pair);
}
@Override
public LunoPostOrder postLimitOrder(String pair, OrderType type, BigDecimal volume, BigDecimal price,
String baseAccountId, String counterAccountId) throws IOException, LunoException {
assert type == OrderType.ASK || type == OrderType.BID : "The order type for limit order must be ASK or BID.";
return luno.postLimitOrder(this.auth, pair, type, volume, price, baseAccountId, counterAccountId);
}
@Override
public LunoPostOrder postMarketOrder(String pair, OrderType type, BigDecimal counterVolume,
BigDecimal baseVolume, String baseAccountId, String counterAccountId) throws IOException, LunoException {
assert type == OrderType.BUY || type == OrderType.SELL : "The order type for limit order must be SELL or BUY.";
return luno.postMarketOrder(this.auth, pair, type, counterVolume, baseVolume, baseAccountId, counterAccountId);
}
@Override
public LunoBoolean stopOrder(String orderId) throws IOException, LunoException {
return luno.stopOrder(this.auth, orderId);
}
@Override
public Order getOrder(String orderId) throws IOException, LunoException {
return luno.getOrder(this.auth, orderId);
}
@Override
public com.luno.dto.trade.LunoUserTrades listTrades(String pair, Long since, Integer limit) throws IOException,
LunoException {
return luno.listTrades(this.auth, pair, since, limit);
}
@Override
public LunoFeeInfo feeInfo(String pair) throws IOException, LunoException {
return luno.feeInfo(this.auth, pair);
}
@Override
public LunoFundingAddress getFundingAddress(String asset, String address) throws IOException, LunoException {
return luno.getFundingAddress(this.auth, asset, address);
}
@Override
public LunoFundingAddress createFundingAddress(String asset) throws IOException, LunoException {
return luno.createFundingAddress(this.auth, asset);
}
@Override
public LunoWithdrawals withdrawals() throws IOException, LunoException {
return luno.withdrawals(this.auth);
}
private static final Set<String> VALID_TYPES = new HashSet<String>(Arrays.asList(
"ZAR_EFT", "NAD_EFT", "KES_MPESA", "MYR_IBG", "IDR_LLG"));
@Override
public Withdrawal requestWithdrawal(String type, BigDecimal amount, String beneficiaryId)
throws IOException, LunoException {
assert VALID_TYPES.contains(type) : "Valid withdrawal types are: " + VALID_TYPES;
return luno.requestWithdrawal(this.auth, type, amount, beneficiaryId);
}
@Override
public Withdrawal getWithdrawal(String withdrawalId) throws IOException, LunoException {
return luno.getWithdrawal(this.auth, withdrawalId);
}
@Override
public Withdrawal cancelWithdrawal(String withdrawalId) throws IOException, LunoException {
return luno.cancelWithdrawal(this.auth, withdrawalId);
}
@Override
public LunoBoolean send(BigDecimal amount, String currency, String address, String description,
String message) throws IOException, LunoException {
return luno.send(this.auth, amount, currency, address, description, message);
}
@Override
public LunoQuote createQuote(OrderType type, BigDecimal baseAmount, String pair) throws IOException,
LunoException {
assert type == OrderType.BUY || type == OrderType.SELL : "The type for quote must be SELL or BUY.";
return luno.createQuote(this.auth, type, baseAmount, pair);
}
@Override
public LunoQuote getQuote(String quoteId) throws IOException, LunoException {
return luno.getQuote(this.auth, quoteId);
}
@Override
public LunoQuote exerciseQuote(String quoteId) throws IOException, LunoException {
return luno.exerciseQuote(this.auth, quoteId);
}
@Override
public LunoQuote discardQuote(String quoteId) throws IOException, LunoException {
return luno.discardQuote(this.auth, quoteId);
}
}