Package com.xeiam.xchange.examples.btctrade.account

Source Code of com.xeiam.xchange.examples.btctrade.account.AccountInfoDemo

package com.xeiam.xchange.examples.btctrade.account;

import java.io.IOException;

import com.xeiam.xchange.Exchange;
import com.xeiam.xchange.ExchangeFactory;
import com.xeiam.xchange.ExchangeSpecification;
import com.xeiam.xchange.btctrade.BTCTradeExchange;
import com.xeiam.xchange.btctrade.dto.account.BTCTradeBalance;
import com.xeiam.xchange.btctrade.dto.account.BTCTradeWallet;
import com.xeiam.xchange.btctrade.service.polling.BTCTradeAccountServiceRaw;
import com.xeiam.xchange.currency.Currencies;
import com.xeiam.xchange.dto.account.AccountInfo;
import com.xeiam.xchange.service.polling.PollingAccountService;

public class AccountInfoDemo {

  public static void main(String[] args) throws IOException {

    // API key with Read Only Permission or All Permissions.
    String publicKey = args[0];
    String privateKey = args[1];

    ExchangeSpecification spec = new ExchangeSpecification(BTCTradeExchange.class);
    spec.setApiKey(publicKey);
    spec.setSecretKey(privateKey);

    Exchange btcTrade = ExchangeFactory.INSTANCE.createExchange(spec);
    generic(btcTrade);
    raw(btcTrade);
  }

  private static void generic(Exchange exchange) throws IOException {

    PollingAccountService accountService = exchange.getPollingAccountService();
    AccountInfo accountInfo = accountService.getAccountInfo();
    System.out.println("Account info: " + accountInfo);

    String depositAddress = accountService.requestDepositAddress(Currencies.BTC);
    System.out.println("Deposit address: " + depositAddress);
  }

  private static void raw(Exchange exchange) {

    BTCTradeAccountServiceRaw accountService = (BTCTradeAccountServiceRaw) exchange.getPollingAccountService();
    BTCTradeBalance balance = accountService.getBTCTradeBalance();

    System.out.println("Balance result: " + balance.getResult());
    System.out.println("Balance message: " + balance.getMessage());
    System.out.println("Balance CNY balance: " + balance.getCnyBalance());
    System.out.println("Balance BTC balance: " + balance.getBtcBalance());
    System.out.println("Balance CNY reserved: " + balance.getCnyReserved());
    System.out.println("Balance BTC reserved: " + balance.getBtcReserved());

    BTCTradeWallet wallet = accountService.getBTCTradeWallet();
    System.out.println("Wallet address: " + wallet.getAddress());
  }

}
TOP

Related Classes of com.xeiam.xchange.examples.btctrade.account.AccountInfoDemo

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.