View Javadoc
1   package org.oxerr.huobi.xchange;
2   
3   import java.util.List;
4   
5   import org.oxerr.huobi.xchange.service.streaming.HuobiSocketIOService;
6   import org.oxerr.huobi.xchange.service.streaming.HuobiStreamingConfiguration;
7   
8   import com.xeiam.xchange.Exchange;
9   import com.xeiam.xchange.ExchangeSpecification;
10  import com.xeiam.xchange.currency.CurrencyPair;
11  import com.xeiam.xchange.service.streaming.ExchangeStreamingConfiguration;
12  import com.xeiam.xchange.service.streaming.StreamingExchangeService;
13  
14  /**
15   * Entry point to the XChange APIs.
16   */
17  public class HuobiExchange extends org.oxerr.huobi.rest.HuobiExchange implements
18  		Exchange {
19  
20  	public static final String WEBSOCKET_URI_KEY = "websocket.uri";
21  
22  	@Override
23  	public void applySpecification(ExchangeSpecification exchangeSpecification) {
24  		super.applySpecification(exchangeSpecification);
25  	}
26  
27  	/**
28  	 * {@inheritDoc}
29  	 */
30  	@Override
31  	public ExchangeSpecification getDefaultExchangeSpecification() {
32  		ExchangeSpecification spec = super.getDefaultExchangeSpecification();
33  		spec.setExchangeSpecificParametersItem(WEBSOCKET_URI_KEY,
34  				"http://hq.huobi.com:80");
35  		return spec;
36  	}
37  
38  	@Override
39  	public StreamingExchangeService getStreamingExchangeService(
40  			ExchangeStreamingConfiguration configuration) {
41  		final HuobiStreamingConfiguration huobiStreamingConfiguration;
42  
43  		if (configuration == null) {
44  			@SuppressWarnings("unchecked")
45  			List<CurrencyPair> currencyPairs = (List<CurrencyPair>) getExchangeSpecification()
46  					.getExchangeSpecificParametersItem(SYMBOLS_PARAMETER);
47  			huobiStreamingConfiguration = new HuobiStreamingConfiguration(
48  					currencyPairs);
49  		} else if (configuration instanceof HuobiStreamingConfiguration) {
50  			huobiStreamingConfiguration = (HuobiStreamingConfiguration) configuration;
51  		} else {
52  			throw new IllegalArgumentException(
53  					"Huobi only supports HuobiStreamingConfiguration");
54  		}
55  
56  		return new HuobiSocketIOService(getExchangeSpecification(),
57  				huobiStreamingConfiguration);
58  	}
59  
60  }