-
Notifications
You must be signed in to change notification settings - Fork 14
/
TradeSite.java
251 lines (223 loc) · 8.47 KB
/
TradeSite.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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
/**
* Java implementation for cryptocoin trading.
*
* Copyright (c) 2014 the authors:
*
* @author Andreas Rueckert <mail@andreas-rueckert.de>
*
* 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 the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the Software
* is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 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 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.
*/
package de.andreas_rueckert.trade.site;
import de.andreas_rueckert.persistence.PersistentProperties;
import de.andreas_rueckert.trade.account.TradeSiteAccount;
import de.andreas_rueckert.trade.CryptoCoinTrade;
import de.andreas_rueckert.trade.currency.Currency;
import de.andreas_rueckert.trade.currency.CurrencyPair;
import de.andreas_rueckert.trade.Depth;
import de.andreas_rueckert.trade.order.OrderStatus;
import de.andreas_rueckert.trade.order.SiteOrder;
import de.andreas_rueckert.trade.Price;
import de.andreas_rueckert.trade.site.request.TradeSiteProxyInfo;
import de.andreas_rueckert.trade.Ticker;
import de.andreas_rueckert.trade.Trade;
import de.andreas_rueckert.trade.TradeDataNotAvailableException;
import java.math.BigDecimal;
import java.util.Collection;
import java.util.List;
import java.util.Map;
/**
* An API for trade sites.
*/
public interface TradeSite extends PersistentProperties {
// Methods
/**
* Add a listener to notify, when new trade data available. Mainly intended for
* websocket exchange API's, so the client can notify a trading app.
*
* @param listener A listener for new trade data.
*/
public void addTradeDataListener( TradeDataListener listener);
/**
* Cancel an order on the trade site.
*
* @param order The order to cancel.
*
* @return true, if the order was canceled. False otherwise.
*/
public boolean cancelOrder( SiteOrder order);
/**
* Execute an order on the trade site.
*
* @param order The order to execute.
*
* @return The new status of the order.
*/
public OrderStatus executeOrder( SiteOrder order);
/**
* Get the accounts of the user on this trading site.
*
* @param userAccount The account of the user on the exchange. Null, if the default account should be used.
*
* @return The accounts of the user on this trading site as a list of Account objects or null if no accounts were found.
*/
public Collection<TradeSiteAccount> getAccounts( TradeSiteUserAccount userAccount);
/**
* Get the current market depth (minimal data of the orders).
*
* @param currencyPair The currency pair to query.
*
* @return The current market depth.
*
* @throws TradeDataNotAvailableException if the depth is not available.
*/
public Depth getDepth( CurrencyPair currencyPair) throws TradeDataNotAvailableException;
/**
* Get the market depths for all supported currency pairs from the trade site.
*
* @return The current market depths for all supported currency pairs.
*
* @throws TradeDataNotAvailableException if the depth is not available.
*/
public List<Depth> getDepths() throws TradeDataNotAvailableException;
/**
* Get the current market depths (minimal data of the orders) for a given list of currency pairs.
*
* @param currencyPairs The currency pairs to query.
*
* @return The current market depths for the given currency pairs.
*
* @throws TradeDataNotAvailableException if the depth is not available.
*/
public List<Depth> getDepths( CurrencyPair [] currencyPairs) throws TradeDataNotAvailableException;
/**
* Get the fee for an order in the resulting currency.
*
* @param order The order to use for the fee computation.
*
* @return The fee in the resulting currency (currency value for buy, payment currency value for sell).
*/
public Price getFeeForOrder( SiteOrder order);
/**
* Get the shortest allowed requet interval in microseconds.
*
* @return The shortest allowed request interval in microseconds.
*/
public long getMinimumRequestInterval();
/**
* Get the name of the trading site.
*
* @return The name of the trading site.
*/
public String getName();
/**
* Get the open orders on this trade site.
*
* @param userAccount The account of the user on the exchange.
*
* @return The open orders as a collection.
*/
public Collection<SiteOrder> getOpenOrders( TradeSiteUserAccount userAccount);
/**
* Get some info, if proxies are allowed for requests to this trade site.
*
* @return Info if proxies are allowed for requests to this trade site or null. Null means no proxies are allowed.
*/
public TradeSiteProxyInfo getProxyInfo();
/**
* Get the supported currency pairs of this trading site.
*
* @return The supported currency pairs of this trading site.
*/
public CurrencyPair [] getSupportedCurrencyPairs();
/**
* Get a current bitcoin ticker from a trade site.
*
* @param currencyPair The currency pair to query.
*
* @return The bitcoin value in the passed currency or null, of the site cannot deliver this ticker.
*
* @throws TradeDataNotAvailableException if the ticker is not available.
*/
public Ticker getTicker( CurrencyPair currencyPair) throws TradeDataNotAvailableException;
/**
* Get a list of trades from the trading site.
*
* @param since_micros The GMT-relative epoch in microseconds.
* @param currencyPair The currency pair to use for the trades.
*
* @return The trades as an array.
*
* @throws TradeDataNotAvailableException if the depth is not available.
*/
public List<Trade> getTrades( long since_micros, CurrencyPair currencyPair) throws TradeDataNotAvailableException;
/**
* Get the interval, in which the trade site updates it's depth, ticker etc.
* in microseconds.
*
* @return The update interval in microseconds.
*/
public long getUpdateInterval();
/**
* Get the URL of the trading site.
*
* @return The URL of the trading site as a String object.
*/
public String getURL();
/**
* Get the hashcode for this trade site.
*
* @return The hash code for this trade site.
*/
public int hashCode();
/**
* Check, if a trade site supports a given feature.
*
* @param feature the feature to check for.
*
* @return true, if the feature is supported. False otherwise.
*/
public boolean isFeatureSupported( TradeSiteFeature feature);
/**
* Check, if some request type is allowed at the moment. Most
* trade site have limits on the number of request per time interval.
*
* @param requestType The type of request (trades, depth, ticker, order etc).
*
* @return true, if the given type of request is possible at the moment.
*/
public boolean isRequestAllowed( TradeSiteRequestType requestType);
/**
* Check, if a given currency pair is supported on this site.
*
* @param currencyPair The currency pair to check for this site.
*
* @return true, if the currency pair is supported. False otherwise.
*/
public boolean isSupportedCurrencyPair( CurrencyPair currencyPair);
/**
* Remove a listener from the list of trade data listeners.
*
* @param listener The listener to remove.
*/
public void removeTradeDataListener( TradeDataListener listener);
/**
* Get a string for the trading site. This is just used to display
* a name for the node in the JTree, so we don't need a cell renderer.
*/
public String toString();
}