View Javadoc
1   package org.oxerr.okcoin.rest;
2   
3   import org.knowm.xchange.BaseExchange;
4   import org.knowm.xchange.Exchange;
5   import org.knowm.xchange.ExchangeSpecification;
6   import org.oxerr.okcoin.rest.service.OKCoinAccountService;
7   import org.oxerr.okcoin.rest.service.OKCoinMarketDataService;
8   import org.oxerr.okcoin.rest.service.OKCoinTradeService;
9   
10  import si.mazi.rescu.SynchronizedValueFactory;
11  
12  /**
13   * {@link Exchange} implementation for OKCoin.
14   */
15  public class OKCoinExchange extends BaseExchange {
16  
17  	/**
18  	 * Max count of retry in logging into via web form.
19  	 */
20  	public static final String LOGIN_MAX_RETRY_TIMES_PARAMETER = "login.max.retry.times";
21  
22  	public static final String SOCKET_TIMEOUT_PARAMETER = "socketTimeout";
23  	public static final String CONNECT_TIMEOUT_PARAMETER = "connectTimeout";
24  	public static final String CONNECTION_REQUEST_TIMEOUT_PARAMETER = "connectionRequestTimeout";
25  
26  	/**
27  	 * The parameter key of the trade password.
28  	 */
29  	public static final String TRADE_PASSWORD_PARAMETER = "trade_pwd";
30  
31  	/**
32  	 * {@inheritDoc}
33  	 */
34  	@Override
35  	protected void initServices() {
36  		this.marketDataService = new OKCoinMarketDataService(this);
37  
38  		if (exchangeSpecification.getApiKey() != null
39  			&& exchangeSpecification.getSecretKey() != null) {
40  			this.accountService = new OKCoinAccountService(this);
41  		}
42  
43  		if ((exchangeSpecification.getApiKey() != null
44  				&& exchangeSpecification.getSecretKey() != null)
45  			|| (exchangeSpecification.getUserName() != null
46  				&& exchangeSpecification.getPassword() != null)) {
47  			this.tradeService = new OKCoinTradeService(this);
48  		}
49  	}
50  
51  	/**
52  	 * {@inheritDoc}
53  	 */
54  	@Override
55  	public ExchangeSpecification getDefaultExchangeSpecification() {
56  		ExchangeSpecification exchangeSpecification = new ExchangeSpecification(
57  				this.getClass().getCanonicalName());
58  		exchangeSpecification.setSslUri("https://www.okcoin.cn");
59  		exchangeSpecification.setHost("www.okcoin.cn");
60  		exchangeSpecification.setExchangeName("OKCoin");
61  		exchangeSpecification
62  				.setExchangeDescription("OKCoin is a globally oriented crypto-currency trading platform.");
63  		return exchangeSpecification;
64  	}
65  
66  	/**
67  	 * {@inheritDoc}
68  	 */
69  	@Override
70  	public SynchronizedValueFactory<Long> getNonceFactory() {
71  		return null;
72  	}
73  
74  }