Search in sources :

Example 26 with Currency

use of org.knowm.xchange.currency.Currency in project XChange by knowm.

the class OkExManualExample method main.

public static void main(String[] args) {
    StreamingExchange exchange = StreamingExchangeFactory.INSTANCE.createExchange(OkExStreamingExchange.class);
    exchange.connect().blockingAwait();
    CurrencyPair btcUsdt = new CurrencyPair(new Currency("BTC"), new Currency("USDT"));
    exchange.getStreamingMarketDataService().getOrderBook(btcUsdt).subscribe(orderBook -> {
        LOG.info("First ask: {}", orderBook.getAsks().get(0));
        LOG.info("First bid: {}", orderBook.getBids().get(0));
    }, throwable -> LOG.error("ERROR in getting order book: ", throwable));
    exchange.getStreamingMarketDataService().getTicker(btcUsdt).subscribe(ticker -> {
        LOG.info("TICKER: {}", ticker);
    }, throwable -> LOG.error("ERROR in getting ticker: ", throwable));
    exchange.getStreamingMarketDataService().getTrades(btcUsdt).subscribe(trade -> {
        LOG.info("TRADE: {}", trade);
    }, throwable -> LOG.error("ERROR in getting trades: ", throwable));
    try {
        Thread.sleep(10000);
    } catch (InterruptedException e) {
        e.printStackTrace();
    }
}
Also used : StreamingExchange(info.bitrich.xchangestream.core.StreamingExchange) Currency(org.knowm.xchange.currency.Currency) CurrencyPair(org.knowm.xchange.currency.CurrencyPair)

Example 27 with Currency

use of org.knowm.xchange.currency.Currency in project XChange by knowm.

the class TheRockAccountService method getFundingHistory.

@Override
public List<FundingRecord> getFundingHistory(TradeHistoryParams params) throws IOException {
    Currency currency = null;
    Date after = null;
    Date before = null;
    FundingRecord.Type type = null;
    if (params instanceof TradeHistoryParamCurrency) {
        TradeHistoryParamCurrency tradeHistoryParamCurrency = (TradeHistoryParamCurrency) params;
        currency = tradeHistoryParamCurrency.getCurrency();
    }
    if (params instanceof TradeHistoryParamsTimeSpan) {
        TradeHistoryParamsTimeSpan tradeHistoryParamsTimeSpan = (TradeHistoryParamsTimeSpan) params;
        after = tradeHistoryParamsTimeSpan.getStartTime();
        before = tradeHistoryParamsTimeSpan.getEndTime();
    }
    if (params instanceof HistoryParamsFundingType) {
        HistoryParamsFundingType historyParamsFundingType = (HistoryParamsFundingType) params;
        type = historyParamsFundingType.getType();
    }
    List<FundingRecord> all = new ArrayList<>();
    if (type == null || type == FundingRecord.Type.DEPOSIT) {
        int page = 1;
        while (true) {
            TheRockTransactions txns = deposits(currency, after, before, page++);
            if (txns.getTransactions().length == 0)
                break;
            for (TheRockTransaction txn : txns.getTransactions()) {
                all.add(adapt(txn, FundingRecord.Type.DEPOSIT));
            }
        }
    }
    if (type == null || type == FundingRecord.Type.WITHDRAWAL) {
        int page = 1;
        while (true) {
            TheRockTransactions txns = withdrawls(currency, after, before, page++);
            if (txns.getTransactions().length == 0)
                break;
            for (TheRockTransaction txn : txns.getTransactions()) {
                all.add(adapt(txn, FundingRecord.Type.WITHDRAWAL));
            }
        }
    }
    return all;
}
Also used : TheRockTransactions(org.knowm.xchange.therock.dto.trade.TheRockTransactions) TradeHistoryParamsTimeSpan(org.knowm.xchange.service.trade.params.TradeHistoryParamsTimeSpan) TradeHistoryParamCurrency(org.knowm.xchange.service.trade.params.TradeHistoryParamCurrency) Currency(org.knowm.xchange.currency.Currency) FundingRecord(org.knowm.xchange.dto.account.FundingRecord) ArrayList(java.util.ArrayList) HistoryParamsFundingType(org.knowm.xchange.service.trade.params.HistoryParamsFundingType) TradeHistoryParamCurrency(org.knowm.xchange.service.trade.params.TradeHistoryParamCurrency) TheRockTransaction(org.knowm.xchange.therock.dto.trade.TheRockTransaction) Date(java.util.Date)

Example 28 with Currency

use of org.knowm.xchange.currency.Currency in project XChange by knowm.

the class AscendexAdapters method adaptAccountInfo.

public static AccountInfo adaptAccountInfo(List<AscendexCashAccountBalanceDto> ascendexCashAccountBalanceDtoList) {
    List<Balance> balances = new ArrayList<>(ascendexCashAccountBalanceDtoList.size());
    ascendexCashAccountBalanceDtoList.forEach(ascendexCashAccountBalanceDto -> balances.add(new Balance.Builder().currency(new Currency(ascendexCashAccountBalanceDto.getAsset())).available(ascendexCashAccountBalanceDto.getAvailableBalance()).total(ascendexCashAccountBalanceDto.getTotalBalance()).frozen(ascendexCashAccountBalanceDto.getTotalBalance().subtract(ascendexCashAccountBalanceDto.getAvailableBalance())).build()));
    return new AccountInfo(Wallet.Builder.from(balances).id("spot").features(new HashSet<>(Collections.singletonList(Wallet.WalletFeature.TRADING))).build());
}
Also used : Currency(org.knowm.xchange.currency.Currency) ArrayList(java.util.ArrayList) Balance(org.knowm.xchange.dto.account.Balance) AccountInfo(org.knowm.xchange.dto.account.AccountInfo)

Example 29 with Currency

use of org.knowm.xchange.currency.Currency in project XChange by knowm.

the class BleutradeAccountServiceIntegration method shouldGetAccountInfo.

@Test
public void shouldGetAccountInfo() throws IOException {
    // given
    BleutradeBalancesReturn balancesReturn = new BleutradeBalancesReturn();
    balancesReturn.setSuccess(true);
    balancesReturn.setMessage("test message");
    balancesReturn.setResult(expectedBleutradeAccountInfo());
    when(bleutrade.getBalances(eq(SPECIFICATION_API_KEY), any(ParamsDigest.class), any(SynchronizedValueFactory.class))).thenReturn(balancesReturn);
    final Balance[] expectedAccountBalances = expectedAccountBalances();
    // when
    AccountInfo accountInfo = accountService.getAccountInfo();
    // then
    assertThat(accountInfo.getWallets()).hasSize(1);
    Map<Currency, Balance> balances = accountInfo.getWallet().getBalances();
    assertThat(balances).hasSize(3);
    BleutradeAssert.assertEquals(balances.get(Currency.AUD), expectedAccountBalances[0]);
    BleutradeAssert.assertEquals(balances.get(Currency.BTC), expectedAccountBalances[1]);
    BleutradeAssert.assertEquals(balances.get(Currency.getInstance("BLEU")), expectedAccountBalances[2]);
}
Also used : BleutradeBalancesReturn(org.knowm.xchange.bleutrade.dto.account.BleutradeBalancesReturn) ParamsDigest(si.mazi.rescu.ParamsDigest) Currency(org.knowm.xchange.currency.Currency) BleutradeBalance(org.knowm.xchange.bleutrade.dto.account.BleutradeBalance) Balance(org.knowm.xchange.dto.account.Balance) AccountInfo(org.knowm.xchange.dto.account.AccountInfo) SynchronizedValueFactory(si.mazi.rescu.SynchronizedValueFactory) Test(org.junit.Test)

Example 30 with Currency

use of org.knowm.xchange.currency.Currency in project XChange by knowm.

the class BleutradeAdapters method adaptToExchangeMetaData.

public static ExchangeMetaData adaptToExchangeMetaData(List<BleutradeCurrency> bleutradeCurrencies, List<BleutradeMarket> bleutradeMarkets) {
    Map<CurrencyPair, CurrencyPairMetaData> marketMetaDataMap = new HashMap<>();
    Map<Currency, CurrencyMetaData> currencyMetaDataMap = new HashMap<>();
    for (BleutradeCurrency bleutradeCurrency : bleutradeCurrencies) {
        // the getTxFee parameter is the withdrawal charge in the currency in question
        currencyMetaDataMap.put(Currency.getInstance(bleutradeCurrency.getCurrency()), new CurrencyMetaData(8, null));
    }
    // https://bleutrade.com/help/fees_and_deadlines 11/25/2015 all == 0.25%
    BigDecimal txFee = new BigDecimal("0.0025");
    for (BleutradeMarket bleutradeMarket : bleutradeMarkets) {
        CurrencyPair currencyPair = CurrencyPairDeserializer.getCurrencyPairFromString(bleutradeMarket.getMarketName());
        CurrencyPairMetaData marketMetaData = new CurrencyPairMetaData(txFee, bleutradeMarket.getMinTradeSize(), null, 8, null);
        marketMetaDataMap.put(currencyPair, marketMetaData);
    }
    return new ExchangeMetaData(marketMetaDataMap, currencyMetaDataMap, null, null, null);
}
Also used : CurrencyPairMetaData(org.knowm.xchange.dto.meta.CurrencyPairMetaData) BleutradeCurrency(org.knowm.xchange.bleutrade.dto.marketdata.BleutradeCurrency) BleutradeMarket(org.knowm.xchange.bleutrade.dto.marketdata.BleutradeMarket) CurrencyMetaData(org.knowm.xchange.dto.meta.CurrencyMetaData) HashMap(java.util.HashMap) ExchangeMetaData(org.knowm.xchange.dto.meta.ExchangeMetaData) BleutradeCurrency(org.knowm.xchange.bleutrade.dto.marketdata.BleutradeCurrency) Currency(org.knowm.xchange.currency.Currency) BigDecimal(java.math.BigDecimal) CurrencyPair(org.knowm.xchange.currency.CurrencyPair)

Aggregations

Currency (org.knowm.xchange.currency.Currency)159 CurrencyPair (org.knowm.xchange.currency.CurrencyPair)75 BigDecimal (java.math.BigDecimal)67 ArrayList (java.util.ArrayList)60 Balance (org.knowm.xchange.dto.account.Balance)38 CurrencyMetaData (org.knowm.xchange.dto.meta.CurrencyMetaData)35 CurrencyPairMetaData (org.knowm.xchange.dto.meta.CurrencyPairMetaData)32 HashMap (java.util.HashMap)28 Test (org.junit.Test)27 Map (java.util.Map)22 Date (java.util.Date)21 AccountInfo (org.knowm.xchange.dto.account.AccountInfo)19 FundingRecord (org.knowm.xchange.dto.account.FundingRecord)19 IOException (java.io.IOException)18 ExchangeMetaData (org.knowm.xchange.dto.meta.ExchangeMetaData)18 List (java.util.List)17 ExchangeException (org.knowm.xchange.exceptions.ExchangeException)15 OrderType (org.knowm.xchange.dto.Order.OrderType)14 UserTrade (org.knowm.xchange.dto.trade.UserTrade)14 Collectors (java.util.stream.Collectors)11