<commit_before>package org.knowm.xchange.examples.blockchain.trade;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import org.knowm.xchange.Exchange;
import org.knowm.xchange.blockchain.params.BlockchainTradeHistoryParams;
import org.knowm.xchange.currency.Currency;
import org.knowm.xchange.currency.CurrencyPair;
import org.knowm.xchange.dto.Order;
import org.knowm.xchange.dto.trade.*;
import org.knowm.xchange.examples.blockchain.BlockchainDemoUtils;
import org.knowm.xchange.service.trade.TradeService;
import org.knowm.xchange.service.trade.params.CancelOrderByCurrencyPair;
import org.knowm.xchange.service.trade.params.TradeHistoryParamsTimeSpan;
import org.knowm.xchange.service.trade.params.orders.OpenOrdersParamCurrencyPair;

import java.io.IOException;
import java.util.Collection;
import java.util.Date;

import static org.knowm.xchange.examples.blockchain.BlockchainDemoUtils.*;

public class BlockchainTradeDemo {
    private static final Exchange BLOCKCHAIN_EXCHANGE = BlockchainDemoUtils.createExchange();
    private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper().enable(SerializationFeature.INDENT_OUTPUT);
    private static final CurrencyPair usdtUsd = new CurrencyPair(Currency.USDT, Currency.USD);
    private static final TradeService tradeService = BLOCKCHAIN_EXCHANGE.getTradeService();

    public static void main(String[] args) throws IOException, InterruptedException {
        System.out.println("===== TRADE SERVICE =====");
        tradeServiceDemo();
    }

    private static void tradeServiceDemo() throws InterruptedException, IOException {
        System.out.println("===== placeLimitOrder =====");
        String limitOrderId = limitOrder();
        System.out.println("===== placeMarketOrder =====");
        String marketOrderId = marketOrder();
        System.out.println("===== placeStopOrder =====");
        String stopOrderId = stopOrder();

        Thread.sleep(5000);

        System.out.println("===== getOpenOrders by symbol =====");
        final OpenOrdersParamCurrencyPair openOrdersParamsBtcUsd =
                (OpenOrdersParamCurrencyPair) tradeService.createOpenOrdersParams();
        openOrdersParamsBtcUsd.setCurrencyPair(CurrencyPair.BTC_USDT);
        OpenOrders openOrdersParams = tradeService.getOpenOrders(openOrdersParamsBtcUsd);
        System.out.println(OBJECT_MAPPER.writeValueAsString(openOrdersParams));

        System.out.println("===== getOpenOrders =====");
        OpenOrders openOrders = tradeService.getOpenOrders();
        System.out.println(OBJECT_MAPPER.writeValueAsString(openOrders));

        System.out.println("===== getTradeHistory =====");
        BlockchainTradeHistoryParams params = (BlockchainTradeHistoryParams) tradeService.createTradeHistoryParams();
        ((TradeHistoryParamsTimeSpan) params).setStartTime(
                new Date(System.currentTimeMillis() - END_TIME));

        params.setCurrencyPair(usdtUsd);

        UserTrades tradeHistory = tradeService.getTradeHistory(params);
        System.out.println(OBJECT_MAPPER.writeValueAsString(tradeHistory));

        System.out.println("===== getOrder =====");
        getOrderById(limitOrderId);
        getOrderById(marketOrderId);
        getOrderById(stopOrderId);

        System.out.println("===== cancelOrder by id =====");
        System.out.println("Canceling returned " + cancelOrderById(limitOrderId));
        System.out.println("Canceling returned " + cancelOrderById(marketOrderId));
        System.out.println("Canceling returned " + cancelOrderById(stopOrderId));

        System.out.println("===== cancelOrder by symbol =====");
        CancelOrderByCurrencyPair cancelOrderByCurrencyPair = () -> new CurrencyPair(SYMBOL);
        boolean cancelAllOrderByCurrency = tradeService.cancelOrder(cancelOrderByCurrencyPair);
        System.out.println("Canceling returned " + cancelAllOrderByCurrency);
    }


    public static String limitOrder() throws IOException {
        LimitOrder limitOrder =
                new LimitOrder.Builder(Order.OrderType.BID, CurrencyPair.BTC_USDT)
                        .originalAmount(AMOUNT)
                        .limitPrice(STOP_LIMIT)
                        .build();

        tradeService.verifyOrder(limitOrder);
        String tradeLimitOrder = tradeService.placeLimitOrder(limitOrder);
        System.out.println(OBJECT_MAPPER.writeValueAsString(tradeLimitOrder));

        return tradeLimitOrder;
    }

    public static String marketOrder() throws IOException {
        MarketOrder marketOrder =
                new MarketOrder.Builder(Order.OrderType.BID, CurrencyPair.BTC_USDT)
                        .originalAmount(AMOUNT)
                        .build();

        tradeService.verifyOrder(marketOrder);
        String tradeMarketOrder = tradeService.placeMarketOrder(marketOrder);
        System.out.println(OBJECT_MAPPER.writeValueAsString(tradeMarketOrder));

        return tradeMarketOrder;
    }

    public static String stopOrder() throws IOException {
        StopOrder stopOrder =
                new StopOrder.Builder(Order.OrderType.ASK, usdtUsd)
                        .originalAmount(AMOUNT_LIMIT)
                        .stopPrice(STOP_PRICE)
                        .limitPrice(STOP_LIMIT_PRICE)
                        .build();

        String tradeStopOrder = tradeService.placeStopOrder(stopOrder);
        System.out.println(OBJECT_MAPPER.writeValueAsString(tradeStopOrder));

        return tradeStopOrder;
    }

    public static void getOrderById(String idOrder) throws IOException {
        Collection<Order> getOrder = tradeService.getOrder(idOrder);
        System.out.println(OBJECT_MAPPER.writeValueAsString(getOrder));
    }

    public static Boolean cancelOrderById(String id) throws IOException {
        return tradeService.cancelOrder(id);
    }
}
<commit_msg>review version 3.6<commit_after>package org.knowm.xchange.examples.blockchain.trade;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import org.knowm.xchange.Exchange;
import org.knowm.xchange.blockchain.params.BlockchainTradeHistoryParams;
import org.knowm.xchange.currency.Currency;
import org.knowm.xchange.currency.CurrencyPair;
import org.knowm.xchange.dto.Order;
import org.knowm.xchange.dto.trade.*;
import org.knowm.xchange.examples.blockchain.BlockchainDemoUtils;
import org.knowm.xchange.service.trade.TradeService;
import org.knowm.xchange.service.trade.params.CancelOrderByCurrencyPair;
import org.knowm.xchange.service.trade.params.TradeHistoryParamsTimeSpan;
import org.knowm.xchange.service.trade.params.orders.OpenOrdersParamCurrencyPair;

import java.io.IOException;
import java.util.Collection;
import java.util.Date;

import static org.knowm.xchange.examples.blockchain.BlockchainDemoUtils.*;

public class BlockchainTradeDemo {
    private static final Exchange BLOCKCHAIN_EXCHANGE = BlockchainDemoUtils.createExchange();
    private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper().enable(SerializationFeature.INDENT_OUTPUT);
    private static final CurrencyPair usdtUsd = new CurrencyPair(Currency.USDT, Currency.USD);
    private static final TradeService tradeService = BLOCKCHAIN_EXCHANGE.getTradeService();

    public static void main(String[] args) throws IOException, InterruptedException {
        System.out.println("===== TRADE SERVICE =====");
        tradeServiceDemo();
    }

    private static void tradeServiceDemo() throws InterruptedException, IOException {
        System.out.println("===== placeLimitOrder =====");
        executeOrder(limitOrder());

        System.out.println("===== placeMarketOrder =====");
        executeOrder(marketOrder());

        System.out.println("===== placeStopOrder =====");
        executeOrder(stopOrder());
    }

    public static void executeOrder(String orderId) throws InterruptedException, IOException{
        Thread.sleep(5000);

        System.out.println("===== getOpenOrders by symbol =====");
        final OpenOrdersParamCurrencyPair openOrdersParamsBtcUsd =
                (OpenOrdersParamCurrencyPair) tradeService.createOpenOrdersParams();
        openOrdersParamsBtcUsd.setCurrencyPair(CurrencyPair.BTC_USDT);
        OpenOrders openOrdersParams = tradeService.getOpenOrders(openOrdersParamsBtcUsd);
        System.out.println(OBJECT_MAPPER.writeValueAsString(openOrdersParams));

        System.out.println("===== getOpenOrders =====");
        OpenOrders openOrders = tradeService.getOpenOrders();
        System.out.println(OBJECT_MAPPER.writeValueAsString(openOrders));

        System.out.println("===== getTradeHistory =====");
        BlockchainTradeHistoryParams params = (BlockchainTradeHistoryParams) tradeService.createTradeHistoryParams();
        ((TradeHistoryParamsTimeSpan) params).setStartTime(
                new Date(System.currentTimeMillis() - END_TIME));

        params.setCurrencyPair(usdtUsd);

        UserTrades tradeHistory = tradeService.getTradeHistory(params);
        System.out.println(OBJECT_MAPPER.writeValueAsString(tradeHistory));

        System.out.println("===== getOrder =====");
        Collection<Order> getOrder = tradeService.getOrder(orderId);
        System.out.println(OBJECT_MAPPER.writeValueAsString(getOrder));

        System.out.println("===== cancelOrder by id =====");
        System.out.println("Canceling returned " + tradeService.cancelOrder(orderId));

        System.out.println("===== cancelOrder by symbol =====");
        CancelOrderByCurrencyPair cancelOrderByCurrencyPair = () -> new CurrencyPair(SYMBOL);
        boolean cancelAllOrderByCurrency = tradeService.cancelOrder(cancelOrderByCurrencyPair);
        System.out.println("Canceling returned " + cancelAllOrderByCurrency);
    }

    public static String limitOrder() throws IOException {
        LimitOrder limitOrder =
                new LimitOrder.Builder(Order.OrderType.BID, CurrencyPair.BTC_USDT)
                        .originalAmount(AMOUNT)
                        .limitPrice(STOP_LIMIT)
                        .build();

        tradeService.verifyOrder(limitOrder);
        String tradeLimitOrder = tradeService.placeLimitOrder(limitOrder);
        System.out.println(OBJECT_MAPPER.writeValueAsString(tradeLimitOrder));

        return tradeLimitOrder;
    }

    public static String marketOrder() throws IOException {
        MarketOrder marketOrder =
                new MarketOrder.Builder(Order.OrderType.BID, CurrencyPair.BTC_USDT)
                        .originalAmount(AMOUNT)
                        .build();

        tradeService.verifyOrder(marketOrder);
        String tradeMarketOrder = tradeService.placeMarketOrder(marketOrder);
        System.out.println(OBJECT_MAPPER.writeValueAsString(tradeMarketOrder));

        return tradeMarketOrder;
    }

    public static String stopOrder() throws IOException {
        StopOrder stopOrder =
                new StopOrder.Builder(Order.OrderType.ASK, usdtUsd)
                        .originalAmount(AMOUNT_LIMIT)
                        .stopPrice(STOP_PRICE)
                        .limitPrice(STOP_LIMIT_PRICE)
                        .build();

        String tradeStopOrder = tradeService.placeStopOrder(stopOrder);
        System.out.println(OBJECT_MAPPER.writeValueAsString(tradeStopOrder));

        return tradeStopOrder;
    }
}

{'fraction_non_alphanumeric': 0.10374715461390299, 'fraction_numerical': 0.0008755034144633164, 'mean_word_length': 3.5655475619504395, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4269530', 'n_tokens_mistral': 3148, 'n_tokens_neox': 3023, 'n_words': 483}