View Javadoc
1   package org.oxerr.okcoin.examples.rest;
2   
3   import static org.oxerr.okcoin.rest.OKCoinExchange.TRADE_PASSWORD_PARAMETER;
4   
5   import java.io.IOException;
6   import java.math.BigDecimal;
7   
8   import org.knowm.xchange.Exchange;
9   import org.knowm.xchange.ExchangeFactory;
10  import org.knowm.xchange.ExchangeSpecification;
11  import org.knowm.xchange.currency.Currency;
12  import org.knowm.xchange.service.account.AccountService;
13  import org.oxerr.okcoin.rest.OKCoinException;
14  import org.oxerr.okcoin.rest.dto.Withdrawal;
15  import org.oxerr.okcoin.rest.service.OKCoinAccountServiceRaw;
16  
17  /**
18   * Demonstration of withdrawing and canceling withdrawal.
19   */
20  public class WithdrawDemo {
21  
22  	private final AccountService accountService;
23  	private final OKCoinAccountServiceRaw rawAccountService;
24  	private final String tradePwd;
25  
26  	public WithdrawDemo(Exchange exchange, String tradePwd) {
27  		this.tradePwd = tradePwd;
28  		accountService = exchange.getAccountService();
29  		rawAccountService = (OKCoinAccountServiceRaw) accountService;
30  	}
31  
32  	public void demoWithdraw() throws IOException {
33  		String symbol = "BTC";
34  
35  		// request to withdraw
36  		String withdrawId = accountService.withdrawFunds(Currency.getInstance(symbol), new BigDecimal("1"), "yourAddress");
37  		// cancel the above withdrawal
38  		rawAccountService.cancelWithdraw(symbol, Long.valueOf(withdrawId));
39  
40  		// request to withdraw via raw service
41  		Withdrawal withdrawal = rawAccountService.withdraw(symbol, new BigDecimal("0.0001"), tradePwd, "yourAddress", new BigDecimal("1"));
42  		// cancel the above withdrawl
43  		rawAccountService.cancelWithdraw(symbol, withdrawal.getWithdrawId());
44  	}
45  
46  	public static void main(String[] args) throws IOException {
47  		String apiKey = args[0], secretKey = args[1], tradePwd = args[2];
48  
49  		ExchangeSpecification spec = new ExchangeSpecification(OKCoinException.class);
50  		spec.setApiKey(apiKey);
51  		spec.setSecretKey(secretKey);
52  		spec.setExchangeSpecificParametersItem(TRADE_PASSWORD_PARAMETER, tradePwd);
53  
54  		Exchange domesticExchange = ExchangeFactory.INSTANCE.createExchange(spec);
55  		WithdrawDemo withdrawDemo = new WithdrawDemo(domesticExchange, tradePwd);
56  		withdrawDemo.demoWithdraw();
57  	}
58  
59  }