-
Notifications
You must be signed in to change notification settings - Fork 1.9k
/
BitfinexMarketDataServiceRaw.java
111 lines (92 loc) · 3.58 KB
/
BitfinexMarketDataServiceRaw.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
package org.knowm.xchange.bitfinex.v1.service.polling;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import org.knowm.xchange.Exchange;
import org.knowm.xchange.bitfinex.v1.BitfinexAdapters;
import org.knowm.xchange.bitfinex.v1.dto.BitfinexException;
import org.knowm.xchange.bitfinex.v1.dto.marketdata.BitfinexDepth;
import org.knowm.xchange.bitfinex.v1.dto.marketdata.BitfinexLend;
import org.knowm.xchange.bitfinex.v1.dto.marketdata.BitfinexLendDepth;
import org.knowm.xchange.bitfinex.v1.dto.marketdata.BitfinexTicker;
import org.knowm.xchange.bitfinex.v1.dto.marketdata.BitfinexTrade;
import org.knowm.xchange.currency.CurrencyPair;
import org.knowm.xchange.exceptions.ExchangeException;
/**
* <p>
* Implementation of the market data service for Bitfinex
* </p>
* <ul>
* <li>Provides access to various market data values</li>
* </ul>
*/
public class BitfinexMarketDataServiceRaw extends BitfinexBasePollingService {
/**
* Constructor
*
* @param exchange
*/
public BitfinexMarketDataServiceRaw(Exchange exchange) {
super(exchange);
}
public BitfinexTicker getBitfinexTicker(String pair) throws IOException {
try {
BitfinexTicker bitfinexTicker = bitfinex.getTicker(pair);
return bitfinexTicker;
} catch (BitfinexException e) {
throw new ExchangeException(e.getMessage());
}
}
public BitfinexDepth getBitfinexOrderBook(String pair, Integer limitBids, Integer limitAsks) throws IOException {
try {
BitfinexDepth bitfinexDepth;
if (limitBids == null && limitAsks == null) {
bitfinexDepth = bitfinex.getBook(pair);
} else {
bitfinexDepth = bitfinex.getBook(pair, limitBids, limitAsks);
}
return bitfinexDepth;
} catch (BitfinexException e) {
throw new ExchangeException(e.getMessage());
}
}
public BitfinexLendDepth getBitfinexLendBook(String currency, int limitBids, int limitAsks) throws IOException {
try {
BitfinexLendDepth bitfinexLendDepth = bitfinex.getLendBook(currency, limitBids, limitAsks);
return bitfinexLendDepth;
} catch (BitfinexException e) {
throw new ExchangeException("Bitfinex returned an error: " + e.getMessage());
}
}
public BitfinexTrade[] getBitfinexTrades(String pair, long sinceTimestamp) throws IOException {
try {
BitfinexTrade[] bitfinexTrades = bitfinex.getTrades(pair, sinceTimestamp);
return bitfinexTrades;
} catch (BitfinexException e) {
throw new ExchangeException("Bitfinex returned an error: " + e.getMessage());
}
}
public BitfinexLend[] getBitfinexLends(String currency, long sinceTimestamp, int limitTrades) throws IOException {
try {
BitfinexLend[] bitfinexLends = bitfinex.getLends(currency, sinceTimestamp, limitTrades);
return bitfinexLends;
} catch (BitfinexException e) {
throw new ExchangeException("Bitfinex returned an error: " + e.getMessage());
}
}
public Collection<String> getBitfinexSymbols() throws IOException {
try {
return bitfinex.getSymbols();
} catch (BitfinexException e) {
throw new ExchangeException("Bitfinex returned an error: " + e.getMessage());
}
}
public List<CurrencyPair> getExchangeSymbols() throws IOException {
List<CurrencyPair> currencyPairs = new ArrayList<CurrencyPair>();
for (String symbol : bitfinex.getSymbols()) {
currencyPairs.add(BitfinexAdapters.adaptCurrencyPair(symbol));
}
return currencyPairs;
}
}