1 package org.oxerr.okcoin.rest.service;
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.currency.Currency;
10 import org.knowm.xchange.dto.account.AccountInfo;
11 import org.knowm.xchange.exceptions.ExchangeException;
12 import org.knowm.xchange.exceptions.NotAvailableFromExchangeException;
13 import org.knowm.xchange.exceptions.NotYetImplementedForExchangeException;
14 import org.knowm.xchange.service.account.AccountService;
15 import org.oxerr.okcoin.rest.OKCoinAdapters;
16 import org.oxerr.okcoin.rest.OKCoinException;
17 import org.oxerr.okcoin.rest.dto.Withdrawal;
18
19
20
21
22 public class OKCoinAccountService extends OKCoinAccountServiceRaw implements
23 AccountService {
24
25 private final Exchange exchange;
26
27 public OKCoinAccountService(Exchange exchange) {
28 super(exchange);
29 this.exchange = exchange;
30 }
31
32
33
34
35 @Override
36 public AccountInfo getAccountInfo() throws OKCoinException,
37 OKCoinException, IOException {
38 return OKCoinAdapters.adaptAccountInfo(getUserInfo());
39 }
40
41
42
43
44 @Override
45 public String withdrawFunds(Currency currency, BigDecimal amount,
46 String address) throws OKCoinException, IOException {
47 BigDecimal chargeFee = currency.equals("BTC") ? new BigDecimal("0.0001") : new BigDecimal("0.001");
48 String tradePassword = (String) exchange.getExchangeSpecification().getParameter(TRADE_PASSWORD_PARAMETER);
49 Withdrawal withdrawal = withdraw(currency.getCurrencyCode(), chargeFee, tradePassword, address, amount);
50 return String.valueOf(withdrawal.getWithdrawId());
51 }
52
53
54
55
56 @Override
57 public String requestDepositAddress(Currency currency, String... args)
58 throws ExchangeException, NotAvailableFromExchangeException,
59 NotYetImplementedForExchangeException, IOException {
60 throw new NotAvailableFromExchangeException();
61 }
62
63 }