Search in sources :

Example 11 with BinanceException

use of org.knowm.xchange.binance.dto.BinanceException in project XChange by knowm.

the class BinanceTradeService method getOpenOrders.

@Override
public OpenOrders getOpenOrders(OpenOrdersParams params) throws IOException {
    try {
        List<BinanceOrder> binanceOpenOrders;
        if (params instanceof OpenOrdersParamCurrencyPair) {
            OpenOrdersParamCurrencyPair pairParams = (OpenOrdersParamCurrencyPair) params;
            CurrencyPair pair = pairParams.getCurrencyPair();
            binanceOpenOrders = super.openOrders(pair);
        } else {
            binanceOpenOrders = super.openOrders();
        }
        List<LimitOrder> limitOrders = new ArrayList<>();
        List<Order> otherOrders = new ArrayList<>();
        binanceOpenOrders.forEach(binanceOrder -> {
            Order order = BinanceAdapters.adaptOrder(binanceOrder);
            if (order instanceof LimitOrder) {
                limitOrders.add((LimitOrder) order);
            } else {
                otherOrders.add(order);
            }
        });
        return new OpenOrders(limitOrders, otherOrders);
    } catch (BinanceException e) {
        throw BinanceErrorAdapter.adapt(e);
    }
}
Also used : BinanceOrder(org.knowm.xchange.binance.dto.trade.BinanceOrder) StopOrder(org.knowm.xchange.dto.trade.StopOrder) BinanceNewOrder(org.knowm.xchange.binance.dto.trade.BinanceNewOrder) BinanceOrder(org.knowm.xchange.binance.dto.trade.BinanceOrder) Order(org.knowm.xchange.dto.Order) LimitOrder(org.knowm.xchange.dto.trade.LimitOrder) MarketOrder(org.knowm.xchange.dto.trade.MarketOrder) BinanceException(org.knowm.xchange.binance.dto.BinanceException) ArrayList(java.util.ArrayList) LimitOrder(org.knowm.xchange.dto.trade.LimitOrder) OpenOrders(org.knowm.xchange.dto.trade.OpenOrders) OpenOrdersParamCurrencyPair(org.knowm.xchange.service.trade.params.orders.OpenOrdersParamCurrencyPair) DefaultOpenOrdersParamCurrencyPair(org.knowm.xchange.service.trade.params.orders.DefaultOpenOrdersParamCurrencyPair) CancelOrderByCurrencyPair(org.knowm.xchange.service.trade.params.CancelOrderByCurrencyPair) OpenOrdersParamCurrencyPair(org.knowm.xchange.service.trade.params.orders.OpenOrdersParamCurrencyPair) DefaultOpenOrdersParamCurrencyPair(org.knowm.xchange.service.trade.params.orders.DefaultOpenOrdersParamCurrencyPair) OrderQueryParamCurrencyPair(org.knowm.xchange.service.trade.params.orders.OrderQueryParamCurrencyPair) CurrencyPair(org.knowm.xchange.currency.CurrencyPair) TradeHistoryParamCurrencyPair(org.knowm.xchange.service.trade.params.TradeHistoryParamCurrencyPair)

Example 12 with BinanceException

use of org.knowm.xchange.binance.dto.BinanceException in project XChange by knowm.

the class BinanceTradeService method placeOrder.

private String placeOrder(OrderType type, Order order, BigDecimal limitPrice, BigDecimal stopPrice, TimeInForce tif) throws IOException {
    try {
        Long recvWindow = (Long) exchange.getExchangeSpecification().getExchangeSpecificParametersItem("recvWindow");
        BinanceNewOrder newOrder = newOrder(order.getCurrencyPair(), BinanceAdapters.convert(order.getType()), type, tif, order.getOriginalAmount(), limitPrice, getClientOrderId(order), stopPrice, null, null);
        return Long.toString(newOrder.orderId);
    } catch (BinanceException e) {
        throw BinanceErrorAdapter.adapt(e);
    }
}
Also used : BinanceException(org.knowm.xchange.binance.dto.BinanceException) BinanceNewOrder(org.knowm.xchange.binance.dto.trade.BinanceNewOrder)

Example 13 with BinanceException

use of org.knowm.xchange.binance.dto.BinanceException in project XChange by knowm.

the class BinanceAccountService method getAccountInfo.

@Override
public AccountInfo getAccountInfo() throws IOException {
    try {
        BinanceAccountInformation acc = account();
        List<Balance> balances = acc.balances.stream().map(b -> new Balance(b.getCurrency(), b.getTotal(), b.getAvailable())).collect(Collectors.toList());
        return new AccountInfo(new Date(acc.updateTime), Wallet.Builder.from(balances).build());
    } catch (BinanceException e) {
        throw BinanceErrorAdapter.adapt(e);
    }
}
Also used : HistoryParamsFundingType(org.knowm.xchange.service.trade.params.HistoryParamsFundingType) AccountService(org.knowm.xchange.service.account.AccountService) TradeHistoryParams(org.knowm.xchange.service.trade.params.TradeHistoryParams) Date(java.util.Date) TradeHistoryParamCurrency(org.knowm.xchange.service.trade.params.TradeHistoryParamCurrency) BinanceException(org.knowm.xchange.binance.dto.BinanceException) HashMap(java.util.HashMap) FundingRecord(org.knowm.xchange.dto.account.FundingRecord) Type(org.knowm.xchange.dto.account.FundingRecord.Type) Balance(org.knowm.xchange.dto.account.Balance) ArrayList(java.util.ArrayList) BigDecimal(java.math.BigDecimal) Status(org.knowm.xchange.dto.account.FundingRecord.Status) DefaultWithdrawFundsParams(org.knowm.xchange.service.trade.params.DefaultWithdrawFundsParams) Map(java.util.Map) BinanceAdapters(org.knowm.xchange.binance.BinanceAdapters) WithdrawResponse(org.knowm.xchange.binance.dto.account.WithdrawResponse) TradeHistoryParamLimit(org.knowm.xchange.service.trade.params.TradeHistoryParamLimit) RoundingMode(java.math.RoundingMode) BinanceAuthenticated(org.knowm.xchange.binance.BinanceAuthenticated) WithdrawFundsParams(org.knowm.xchange.service.trade.params.WithdrawFundsParams) AccountInfo(org.knowm.xchange.dto.account.AccountInfo) ResilienceRegistries(org.knowm.xchange.client.ResilienceRegistries) Fee(org.knowm.xchange.dto.account.Fee) Wallet(org.knowm.xchange.dto.account.Wallet) BinanceExchange(org.knowm.xchange.binance.BinanceExchange) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) TradeHistoryParamPaging(org.knowm.xchange.service.trade.params.TradeHistoryParamPaging) RippleWithdrawFundsParams(org.knowm.xchange.service.trade.params.RippleWithdrawFundsParams) List(java.util.List) Currency(org.knowm.xchange.currency.Currency) TradeHistoryParamsTimeSpan(org.knowm.xchange.service.trade.params.TradeHistoryParamsTimeSpan) BinanceAccountInformation(org.knowm.xchange.binance.dto.account.BinanceAccountInformation) BinanceErrorAdapter(org.knowm.xchange.binance.BinanceErrorAdapter) CurrencyPair(org.knowm.xchange.currency.CurrencyPair) AddressWithTag(org.knowm.xchange.dto.account.AddressWithTag) AssetDetail(org.knowm.xchange.binance.dto.account.AssetDetail) DepositAddress(org.knowm.xchange.binance.dto.account.DepositAddress) BinanceException(org.knowm.xchange.binance.dto.BinanceException) Balance(org.knowm.xchange.dto.account.Balance) BinanceAccountInformation(org.knowm.xchange.binance.dto.account.BinanceAccountInformation) AccountInfo(org.knowm.xchange.dto.account.AccountInfo) Date(java.util.Date)

Aggregations

BinanceException (org.knowm.xchange.binance.dto.BinanceException)13 ArrayList (java.util.ArrayList)5 ExchangeException (org.knowm.xchange.exceptions.ExchangeException)5 BinanceNewOrder (org.knowm.xchange.binance.dto.trade.BinanceNewOrder)4 CurrencyPair (org.knowm.xchange.currency.CurrencyPair)4 BigDecimal (java.math.BigDecimal)3 BinanceOrder (org.knowm.xchange.binance.dto.trade.BinanceOrder)3 Order (org.knowm.xchange.dto.Order)3 LimitOrder (org.knowm.xchange.dto.trade.LimitOrder)3 MarketOrder (org.knowm.xchange.dto.trade.MarketOrder)3 StopOrder (org.knowm.xchange.dto.trade.StopOrder)3 CancelOrderByCurrencyPair (org.knowm.xchange.service.trade.params.CancelOrderByCurrencyPair)3 TradeHistoryParamLimit (org.knowm.xchange.service.trade.params.TradeHistoryParamLimit)3 TradeHistoryParamsTimeSpan (org.knowm.xchange.service.trade.params.TradeHistoryParamsTimeSpan)3 OrderQueryParamCurrencyPair (org.knowm.xchange.service.trade.params.orders.OrderQueryParamCurrencyPair)3 IOException (java.io.IOException)2 Date (java.util.Date)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Collectors (java.util.stream.Collectors)2