Search in sources :

Example 26 with CurrencyPair

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

the class TradeServiceIntegration method sampleTakeProfitLimitOrder.

private StopOrder sampleTakeProfitLimitOrder() throws IOException {
    final CurrencyPair currencyPair = CurrencyPair.BTC_USDT;
    final BigDecimal amount = BigDecimal.ONE;
    final BigDecimal limitPrice = limitPriceForCurrencyPair(currencyPair);
    final BigDecimal takeProfitPrice = limitPrice.multiply(new BigDecimal("1.1")).setScale(2, RoundingMode.HALF_UP);
    return new StopOrder.Builder(BID, currencyPair).originalAmount(amount).stopPrice(takeProfitPrice).limitPrice(limitPrice).intention(StopOrder.Intention.TAKE_PROFIT).flag(TimeInForce.GTC).build();
}
Also used : BigDecimal(java.math.BigDecimal) CurrencyPair(org.knowm.xchange.currency.CurrencyPair)

Example 27 with CurrencyPair

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

the class TradeServiceIntegration method sampleLimitOrder.

private LimitOrder sampleLimitOrder() throws IOException {
    final CurrencyPair currencyPair = CurrencyPair.BTC_USDT;
    final BigDecimal amount = BigDecimal.ONE;
    final BigDecimal limitPrice = limitPriceForCurrencyPair(currencyPair);
    return new LimitOrder.Builder(BID, currencyPair).originalAmount(amount).limitPrice(limitPrice).flag(TimeInForce.GTC).build();
}
Also used : BigDecimal(java.math.BigDecimal) CurrencyPair(org.knowm.xchange.currency.CurrencyPair)

Example 28 with CurrencyPair

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

the class TradeServiceIntegration method sampleStopLimitOrder.

private StopOrder sampleStopLimitOrder() throws IOException {
    final CurrencyPair currencyPair = CurrencyPair.BTC_USDT;
    final BigDecimal amount = BigDecimal.ONE;
    final BigDecimal limitPrice = limitPriceForCurrencyPair(currencyPair);
    final BigDecimal stopPrice = limitPrice.multiply(new BigDecimal("0.9")).setScale(2, RoundingMode.HALF_UP);
    return new StopOrder.Builder(BID, currencyPair).originalAmount(amount).limitPrice(limitPrice).stopPrice(stopPrice).intention(StopOrder.Intention.STOP_LOSS).flag(TimeInForce.GTC).build();
}
Also used : BigDecimal(java.math.BigDecimal) CurrencyPair(org.knowm.xchange.currency.CurrencyPair)

Example 29 with CurrencyPair

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

the class BitbayAdapters method createUserTrade.

private static UserTrade createUserTrade(BitbayOrder bitbayOrder) {
    CurrencyPair currencyPair = new CurrencyPair(bitbayOrder.getCurrency(), bitbayOrder.getPaymentCurrency());
    OrderType type = "ask".equals(bitbayOrder.getType()) ? OrderType.ASK : OrderType.BID;
    DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    Date date;
    try {
        date = formatter.parse(bitbayOrder.getDate());
    } catch (ParseException e) {
        throw new IllegalArgumentException(e);
    }
    return new UserTrade.Builder().type(type).originalAmount(bitbayOrder.getAmount()).currencyPair(currencyPair).price(bitbayOrder.getCurrentPrice().divide(bitbayOrder.getStartAmount())).timestamp(date).id(String.valueOf(bitbayOrder.getId())).orderId(String.valueOf(bitbayOrder.getId())).build();
}
Also used : OrderType(org.knowm.xchange.dto.Order.OrderType) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) ParseException(java.text.ParseException) SimpleDateFormat(java.text.SimpleDateFormat) Date(java.util.Date) CurrencyPair(org.knowm.xchange.currency.CurrencyPair)

Example 30 with CurrencyPair

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

the class BitbayTradeService method getTradeHistory.

@Override
public UserTrades getTradeHistory(TradeHistoryParams params) throws IOException {
    final BitbayUserTradesQuery query = new BitbayUserTradesQuery();
    if (params instanceof TradeHistoryParamNextPageCursor) {
        query.setNextPageCursor(((TradeHistoryParamNextPageCursor) params).getNextPageCursor());
    }
    if (params instanceof TradeHistoryParamLimit) {
        Integer limit = ((TradeHistoryParamLimit) params).getLimit();
        query.setLimit(limit != null ? limit.toString() : null);
    }
    if (params instanceof TradeHistoryParamMultiCurrencyPair) {
        final Collection<CurrencyPair> currencyPairs = ((TradeHistoryParamMultiCurrencyPair) params).getCurrencyPairs();
        query.setMarkets(currencyPairs.stream().map(BitbayAdapters::adaptCurrencyPair).collect(Collectors.toList()));
    }
    final BitbayUserTrades response = getBitbayTransactions(query);
    return BitbayAdapters.adaptUserTrades(response);
}
Also used : BitbayAdapters(org.knowm.xchange.bitbay.v3.BitbayAdapters) TradeHistoryParamMultiCurrencyPair(org.knowm.xchange.service.trade.params.TradeHistoryParamMultiCurrencyPair) BitbayUserTrades(org.knowm.xchange.bitbay.v3.dto.trade.BitbayUserTrades) TradeHistoryParamNextPageCursor(org.knowm.xchange.service.trade.params.TradeHistoryParamNextPageCursor) BitbayUserTradesQuery(org.knowm.xchange.bitbay.v3.dto.trade.BitbayUserTradesQuery) TradeHistoryParamLimit(org.knowm.xchange.service.trade.params.TradeHistoryParamLimit) TradeHistoryParamMultiCurrencyPair(org.knowm.xchange.service.trade.params.TradeHistoryParamMultiCurrencyPair) CurrencyPair(org.knowm.xchange.currency.CurrencyPair)

Aggregations

CurrencyPair (org.knowm.xchange.currency.CurrencyPair)518 BigDecimal (java.math.BigDecimal)157 Test (org.junit.Test)125 LimitOrder (org.knowm.xchange.dto.trade.LimitOrder)121 Date (java.util.Date)108 ArrayList (java.util.ArrayList)107 Ticker (org.knowm.xchange.dto.marketdata.Ticker)91 Currency (org.knowm.xchange.currency.Currency)88 OrderType (org.knowm.xchange.dto.Order.OrderType)81 Exchange (org.knowm.xchange.Exchange)76 Order (org.knowm.xchange.dto.Order)70 TradeHistoryParamCurrencyPair (org.knowm.xchange.service.trade.params.TradeHistoryParamCurrencyPair)60 MarketDataService (org.knowm.xchange.service.marketdata.MarketDataService)58 OrderBook (org.knowm.xchange.dto.marketdata.OrderBook)57 UserTrade (org.knowm.xchange.dto.trade.UserTrade)57 List (java.util.List)54 HashMap (java.util.HashMap)53 CurrencyPairMetaData (org.knowm.xchange.dto.meta.CurrencyPairMetaData)53 UserTrades (org.knowm.xchange.dto.trade.UserTrades)51 IOException (java.io.IOException)43