-
Notifications
You must be signed in to change notification settings - Fork 1.9k
/
BitstampTickerDemo.java
44 lines (32 loc) · 1.58 KB
/
BitstampTickerDemo.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
package org.knowm.xchange.examples.bitstamp.marketdata;
import java.io.IOException;
import org.knowm.xchange.Exchange;
import org.knowm.xchange.ExchangeFactory;
import org.knowm.xchange.bitstamp.BitstampExchange;
import org.knowm.xchange.bitstamp.dto.marketdata.BitstampTicker;
import org.knowm.xchange.bitstamp.service.BitstampMarketDataServiceRaw;
import org.knowm.xchange.currency.CurrencyPair;
import org.knowm.xchange.dto.marketdata.Ticker;
import org.knowm.xchange.service.marketdata.MarketDataService;
/**
* Demonstrate requesting Ticker at Bitstamp. You can access both the raw data from Bitstamp or the
* XChange generic DTO data format.
*/
public class BitstampTickerDemo {
public static void main(String[] args) throws IOException {
// Use the factory to get Bitstamp exchange API using default settings
Exchange bitstamp = ExchangeFactory.INSTANCE.createExchange(BitstampExchange.class);
// Interested in the public market data feed (no authentication)
MarketDataService marketDataService = bitstamp.getMarketDataService();
generic(marketDataService);
raw((BitstampMarketDataServiceRaw) marketDataService);
}
private static void generic(MarketDataService marketDataService) throws IOException {
Ticker ticker = marketDataService.getTicker(CurrencyPair.BTC_USD);
System.out.println(ticker.toString());
}
private static void raw(BitstampMarketDataServiceRaw marketDataService) throws IOException {
BitstampTicker bitstampTicker = marketDataService.getBitstampTicker(CurrencyPair.BTC_USD);
System.out.println(bitstampTicker.toString());
}
}