├── .gitignore ├── src ├── main │ ├── java │ │ └── com │ │ │ └── binance │ │ │ └── client │ │ │ ├── model │ │ │ ├── enums │ │ │ │ ├── TransferType.java │ │ │ │ ├── MarginType.java │ │ │ │ ├── AutoCloseType.java │ │ │ │ ├── NewOrderRespType.java │ │ │ │ ├── TimeInForce.java │ │ │ │ ├── OrderRespType.java │ │ │ │ ├── WorkingType.java │ │ │ │ ├── ContractType.java │ │ │ │ ├── SideEffectType.java │ │ │ │ ├── CrossMarginTransferType.java │ │ │ │ ├── IncomeType.java │ │ │ │ ├── QuerySort.java │ │ │ │ ├── MarginTransferType.java │ │ │ │ ├── OrderSide.java │ │ │ │ ├── MBPLevelEnums.java │ │ │ │ ├── PositionSide.java │ │ │ │ ├── DepthStep.java │ │ │ │ ├── BalanceMode.java │ │ │ │ ├── DealRole.java │ │ │ │ ├── AccountChangeModeEnum.java │ │ │ │ ├── EtfSwapType.java │ │ │ │ ├── QueryDirection.java │ │ │ │ ├── AccountState.java │ │ │ │ ├── TradeDirection.java │ │ │ │ ├── SymbolState.java │ │ │ │ ├── EtfStatus.java │ │ │ │ ├── LoanOrderStates.java │ │ │ │ ├── DepositState.java │ │ │ │ ├── BalanceType.java │ │ │ │ ├── TransferFuturesDirection.java │ │ │ │ ├── CandlestickInterval.java │ │ │ │ ├── OrderStatus.java │ │ │ │ ├── TransferMasterType.java │ │ │ │ ├── AccountType.java │ │ │ │ ├── PeriodType.java │ │ │ │ ├── TransactType.java │ │ │ │ ├── OrderType.java │ │ │ │ ├── StopOrderOperator.java │ │ │ │ ├── WithdrawState.java │ │ │ │ ├── OrderSource.java │ │ │ │ └── AccountChangeType.java │ │ │ ├── market │ │ │ │ ├── OrderBookEntry.java │ │ │ │ ├── SymbolPrice.java │ │ │ │ ├── OrderBook.java │ │ │ │ ├── OpenInterest.java │ │ │ │ ├── FundingRate.java │ │ │ │ ├── ExchangeFilter.java │ │ │ │ ├── TakerLongShortStat.java │ │ │ │ ├── RateLimit.java │ │ │ │ ├── OpenInterestStat.java │ │ │ │ ├── CommonLongShortRatio.java │ │ │ │ ├── Trade.java │ │ │ │ ├── ExchangeInformation.java │ │ │ │ ├── SymbolOrderBook.java │ │ │ │ ├── AggregateTrade.java │ │ │ │ ├── MarkPrice.java │ │ │ │ ├── Candlestick.java │ │ │ │ ├── ExchangeInfoEntry.java │ │ │ │ ├── PriceChangeTicker.java │ │ │ │ └── LiquidationOrder.java │ │ │ ├── user │ │ │ │ ├── AccountUpdate.java │ │ │ │ ├── BalanceUpdate.java │ │ │ │ ├── UserDataUpdateEvent.java │ │ │ │ └── PositionUpdate.java │ │ │ ├── ResponseResult.java │ │ │ ├── trade │ │ │ │ ├── Leverage.java │ │ │ │ ├── WalletDeltaLog.java │ │ │ │ ├── Income.java │ │ │ │ ├── AccountBalance.java │ │ │ │ ├── PositionRisk.java │ │ │ │ ├── Position.java │ │ │ │ ├── MyTrade.java │ │ │ │ └── Asset.java │ │ │ └── event │ │ │ │ ├── MarkPriceEvent.java │ │ │ │ ├── SymbolBookTickerEvent.java │ │ │ │ ├── AggregateTradeEvent.java │ │ │ │ ├── SymbolMiniTickerEvent.java │ │ │ │ ├── OrderBookEvent.java │ │ │ │ ├── LiquidationOrderEvent.java │ │ │ │ ├── SymbolTickerEvent.java │ │ │ │ └── CandlestickEvent.java │ │ │ ├── impl │ │ │ ├── utils │ │ │ │ ├── Handler.java │ │ │ │ ├── EnumLookup.java │ │ │ │ ├── InternalUtils.java │ │ │ │ └── JsonWrapperArray.java │ │ │ ├── RestApiRequest.java │ │ │ ├── RestApiJsonParser.java │ │ │ ├── ChannelParser.java │ │ │ ├── WebsocketRequest.java │ │ │ ├── BinanceApiInternalFactory.java │ │ │ ├── ApiSignature.java │ │ │ ├── WebSocketWatchDog.java │ │ │ ├── RestApiInvoker.java │ │ │ └── InputChecker.java │ │ │ ├── SubscriptionErrorHandler.java │ │ │ ├── SubscriptionListener.java │ │ │ ├── ResponseCallback.java │ │ │ ├── RequestOptions.java │ │ │ ├── exception │ │ │ └── BinanceApiException.java │ │ │ ├── constant │ │ │ └── BinanceApiConstants.java │ │ │ └── SubscriptionOptions.java │ └── resources │ │ └── logback.xml └── test │ └── java │ └── com │ └── binance │ └── client │ └── examples │ ├── constants │ └── PrivateConfig.java │ ├── websocket │ ├── SubscribeAllBookTicker.java │ ├── SubscribeAllMiniTicker.java │ ├── SubscribeAllLiquidationOrder.java │ ├── SubscribeAllTicker.java │ ├── SubscribeBookDepth.java │ ├── SubscribeDiffDepth.java │ ├── SubscribeMarkPrice.java │ ├── SubscribeSymbolTicker.java │ ├── SubscribeAggregateTrade.java │ ├── SubscribeSymbolBookTicker.java │ ├── SubscribeSymbolMiniTicker.java │ ├── SubscribeSymbolLiquidationOrder.java │ └── SubscribeCandlestick.java │ ├── trade │ ├── GetBalance.java │ ├── GetOrder.java │ ├── CancelOrder.java │ ├── GetPositionRisk.java │ ├── GetAccountInformation.java │ ├── ChangeInitialLeverage.java │ ├── GetAccountTrades.java │ ├── GetIncomeHistory.java │ ├── GetOpenOrders.java │ ├── GetPositionSide.java │ ├── ChangePositionSide.java │ ├── CancelAllOpenOrders.java │ ├── GetAllOrders.java │ ├── ChangeMarginType.java │ ├── AddIsolatedPositionMargin.java │ ├── GetPositionMarginHistory.java │ ├── PostOrder.java │ ├── BatchCancelOrders.java │ └── BatchPlaceOrders.java │ ├── market │ ├── GetMarkPrice.java │ ├── GetOldTrades.java │ ├── GetOrderBook.java │ ├── GetRecentTrades.java │ ├── GetExchangeInformation.java │ ├── GetFundingRate.java │ ├── GetAggregateTrades.java │ ├── GetLiquidationOrders.java │ ├── GetSymbolPriceTicker.java │ ├── GetOpenInterestStat.java │ ├── GetGlobalAccountRatio.java │ ├── GetTakerLongShortStat.java │ ├── Get24hrTickerPriceChange.java │ ├── GetCandlestick.java │ ├── GetSymbolOrderBookTicker.java │ ├── GetTakerLongShortRatio.java │ ├── GetTopTraderAccountRatio.java │ └── GetTopTraderPositionRatio.java │ └── user │ └── SubscribeUserData.java ├── .github └── dependabot.yml └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | settings.xml -------------------------------------------------------------------------------- /src/main/java/com/binance/client/model/enums/TransferType.java: -------------------------------------------------------------------------------- 1 | package com.binance.client.model.enums; 2 | 3 | public enum TransferType { 4 | ROLL_IN, 5 | ROLL_OUT 6 | } -------------------------------------------------------------------------------- /src/main/java/com/binance/client/model/enums/MarginType.java: -------------------------------------------------------------------------------- 1 | package com.binance.client.model.enums; 2 | 3 | public enum MarginType { 4 | ISOLATED, 5 | CROSSED; 6 | } 7 | -------------------------------------------------------------------------------- /src/main/java/com/binance/client/model/enums/AutoCloseType.java: -------------------------------------------------------------------------------- 1 | package com.binance.client.model.enums; 2 | 3 | public enum AutoCloseType { 4 | LIQUIDATION, 5 | ADL; 6 | } 7 | -------------------------------------------------------------------------------- /src/main/java/com/binance/client/model/enums/NewOrderRespType.java: -------------------------------------------------------------------------------- 1 | package com.binance.client.model.enums; 2 | 3 | public enum NewOrderRespType { 4 | ACK, 5 | RESULT 6 | } 7 | -------------------------------------------------------------------------------- /src/main/java/com/binance/client/model/enums/TimeInForce.java: -------------------------------------------------------------------------------- 1 | package com.binance.client.model.enums; 2 | 3 | public enum TimeInForce { 4 | GTC, 5 | IOC, 6 | FOK 7 | } 8 | -------------------------------------------------------------------------------- /src/main/java/com/binance/client/model/enums/OrderRespType.java: -------------------------------------------------------------------------------- 1 | package com.binance.client.model.enums; 2 | 3 | public enum OrderRespType { 4 | ACK, 5 | RESULT, 6 | FULL 7 | } 8 | -------------------------------------------------------------------------------- /src/main/java/com/binance/client/impl/utils/Handler.java: -------------------------------------------------------------------------------- 1 | package com.binance.client.impl.utils; 2 | 3 | @FunctionalInterface 4 | public interface Handler { 5 | 6 | void handle(T t); 7 | } 8 | -------------------------------------------------------------------------------- /src/main/java/com/binance/client/model/enums/WorkingType.java: -------------------------------------------------------------------------------- 1 | package com.binance.client.model.enums; 2 | 3 | public enum WorkingType { 4 | 5 | MARK_PRICE, 6 | CONTRACT_PRICE; 7 | 8 | } -------------------------------------------------------------------------------- /src/main/java/com/binance/client/model/enums/ContractType.java: -------------------------------------------------------------------------------- 1 | package com.binance.client.model.enums; 2 | 3 | public enum ContractType { 4 | PERPETUAL, 5 | CURRENT_MONTH, 6 | NEXT_MONTH; 7 | } 8 | -------------------------------------------------------------------------------- /src/main/java/com/binance/client/model/enums/SideEffectType.java: -------------------------------------------------------------------------------- 1 | package com.binance.client.model.enums; 2 | 3 | 4 | public enum SideEffectType { 5 | NO_SIDE_EFFECT, 6 | MARGIN_BUY, 7 | AUTO_REPAY; 8 | } 9 | -------------------------------------------------------------------------------- /src/main/java/com/binance/client/model/enums/CrossMarginTransferType.java: -------------------------------------------------------------------------------- 1 | package com.binance.client.model.enums; 2 | 3 | public enum CrossMarginTransferType { 4 | 5 | SUPER_MARGIN_TO_SPOT, 6 | SPOT_TO_SUPER_MARGIN; 7 | 8 | } 9 | -------------------------------------------------------------------------------- /src/main/java/com/binance/client/impl/RestApiRequest.java: -------------------------------------------------------------------------------- 1 | package com.binance.client.impl; 2 | 3 | import okhttp3.Request; 4 | 5 | public class RestApiRequest { 6 | 7 | public Request request; 8 | RestApiJsonParser jsonParser; 9 | } 10 | -------------------------------------------------------------------------------- /src/main/java/com/binance/client/impl/RestApiJsonParser.java: -------------------------------------------------------------------------------- 1 | package com.binance.client.impl; 2 | 3 | import com.binance.client.impl.utils.JsonWrapper; 4 | 5 | @FunctionalInterface 6 | public interface RestApiJsonParser { 7 | 8 | T parseJson(JsonWrapper json); 9 | } 10 | -------------------------------------------------------------------------------- /src/test/java/com/binance/client/examples/constants/PrivateConfig.java: -------------------------------------------------------------------------------- 1 | package com.binance.client.examples.constants; 2 | 3 | public class PrivateConfig { 4 | 5 | public static final String API_KEY = "XXXXXX"; 6 | public static final String SECRET_KEY = "XXXXXX"; 7 | 8 | } 9 | -------------------------------------------------------------------------------- /src/main/java/com/binance/client/model/enums/IncomeType.java: -------------------------------------------------------------------------------- 1 | package com.binance.client.model.enums; 2 | 3 | 4 | public enum IncomeType { 5 | TRANSFER, 6 | WELCOME_BONUS, 7 | REALIZED_PNL, 8 | FUNDING_FEE, 9 | COMMISSION, 10 | INSURANCE_CLEAR; 11 | } 12 | -------------------------------------------------------------------------------- /src/main/java/com/binance/client/SubscriptionErrorHandler.java: -------------------------------------------------------------------------------- 1 | package com.binance.client; 2 | 3 | import com.binance.client.exception.BinanceApiException; 4 | 5 | /** 6 | * The error handler for the subscription. 7 | */ 8 | @FunctionalInterface 9 | public interface SubscriptionErrorHandler { 10 | 11 | void onError(BinanceApiException exception); 12 | } 13 | -------------------------------------------------------------------------------- /src/main/java/com/binance/client/model/enums/QuerySort.java: -------------------------------------------------------------------------------- 1 | package com.binance.client.model.enums; 2 | 3 | public enum QuerySort { 4 | 5 | ASC("asc"), 6 | DESC("desc"); 7 | 8 | private final String code; 9 | 10 | QuerySort(String code) { 11 | this.code = code; 12 | } 13 | 14 | public String getCode() { 15 | return code; 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/com/binance/client/model/enums/MarginTransferType.java: -------------------------------------------------------------------------------- 1 | package com.binance.client.model.enums; 2 | 3 | 4 | public enum MarginTransferType { 5 | IN("1"), 6 | OUT("2"); 7 | 8 | private final String code; 9 | 10 | MarginTransferType(String code) { 11 | this.code = code; 12 | } 13 | 14 | @Override 15 | public String toString() { 16 | return code; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/com/binance/client/model/enums/OrderSide.java: -------------------------------------------------------------------------------- 1 | package com.binance.client.model.enums; 2 | 3 | /** 4 | * buy, sell, both. 5 | */ 6 | 7 | public enum OrderSide { 8 | BUY("BUY"), 9 | SELL("SELL"); 10 | 11 | private final String code; 12 | 13 | OrderSide(String side) { 14 | this.code = side; 15 | } 16 | 17 | @Override 18 | public String toString() { 19 | return code; 20 | } 21 | 22 | 23 | } -------------------------------------------------------------------------------- /src/main/java/com/binance/client/model/enums/MBPLevelEnums.java: -------------------------------------------------------------------------------- 1 | package com.binance.client.model.enums; 2 | 3 | public enum MBPLevelEnums { 4 | 5 | 6 | LEVEL5(5), 7 | LEVEL10(10), 8 | LEVEL20(20), 9 | LEVEL150(150), 10 | 11 | ; 12 | 13 | private final int levels; 14 | 15 | MBPLevelEnums(int levels) { 16 | this.levels = levels; 17 | } 18 | 19 | public int getLevels() { 20 | return levels; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/test/java/com/binance/client/examples/websocket/SubscribeAllBookTicker.java: -------------------------------------------------------------------------------- 1 | package com.binance.client.examples.websocket; 2 | 3 | import com.binance.client.SubscriptionClient; 4 | 5 | public class SubscribeAllBookTicker { 6 | 7 | public static void main(String[] args) { 8 | 9 | SubscriptionClient client = SubscriptionClient.create(); 10 | 11 | client.subscribeAllBookTickerEvent(((event) -> { 12 | System.out.println(event); 13 | }), null); 14 | 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /src/test/java/com/binance/client/examples/websocket/SubscribeAllMiniTicker.java: -------------------------------------------------------------------------------- 1 | package com.binance.client.examples.websocket; 2 | 3 | import com.binance.client.SubscriptionClient; 4 | 5 | public class SubscribeAllMiniTicker { 6 | 7 | public static void main(String[] args) { 8 | 9 | SubscriptionClient client = SubscriptionClient.create(); 10 | 11 | client.subscribeAllMiniTickerEvent(((event) -> { 12 | System.out.println(event); 13 | }), null); 14 | 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/com/binance/client/model/enums/PositionSide.java: -------------------------------------------------------------------------------- 1 | package com.binance.client.model.enums; 2 | 3 | /** 4 | * @author : wangwanlu 5 | * @since : 2020/3/25, Wed 6 | **/ 7 | public enum PositionSide { 8 | 9 | BOTH("BOTH"), 10 | 11 | SHORT("SHORT"), 12 | 13 | LONG("LONG"), 14 | ; 15 | 16 | private final String code; 17 | 18 | PositionSide(String side) { 19 | this.code = side; 20 | } 21 | 22 | @Override 23 | public String toString() { 24 | return code; 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/test/java/com/binance/client/examples/websocket/SubscribeAllLiquidationOrder.java: -------------------------------------------------------------------------------- 1 | package com.binance.client.examples.websocket; 2 | 3 | import com.binance.client.SubscriptionClient; 4 | 5 | public class SubscribeAllLiquidationOrder { 6 | 7 | public static void main(String[] args) { 8 | 9 | SubscriptionClient client = SubscriptionClient.create(); 10 | 11 | client.subscribeAllLiquidationOrderEvent(((event) -> { 12 | System.out.println(event); 13 | }), null); 14 | 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /src/test/java/com/binance/client/examples/websocket/SubscribeAllTicker.java: -------------------------------------------------------------------------------- 1 | package com.binance.client.examples.websocket; 2 | 3 | import com.binance.client.SubscriptionClient; 4 | 5 | public class SubscribeAllTicker { 6 | 7 | public static void main(String[] args) { 8 | 9 | SubscriptionClient client = SubscriptionClient.create(); 10 | 11 | client.subscribeAllTickerEvent(((event) -> { 12 | System.out.println(event); 13 | client.unsubscribeAll(); 14 | }), null); 15 | 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /.github/dependabot.yml: -------------------------------------------------------------------------------- 1 | # To get started with Dependabot version updates, you'll need to specify which 2 | # package ecosystems to update and where the package manifests are located. 3 | # Please see the documentation for all configuration options: 4 | # https://help.github.com/github/administering-a-repository/configuration-options-for-dependency-updates 5 | 6 | version: 2 7 | updates: 8 | - package-ecosystem: "maven" # See documentation for possible values 9 | directory: "/" # Location of package manifests 10 | schedule: 11 | interval: "daily" 12 | -------------------------------------------------------------------------------- /src/main/java/com/binance/client/impl/ChannelParser.java: -------------------------------------------------------------------------------- 1 | package com.binance.client.impl; 2 | 3 | class ChannelParser { 4 | 5 | private String symbol = ""; 6 | 7 | ChannelParser(String input) { 8 | String[] fields = input.split("\\."); 9 | if (fields.length >= 2) { 10 | symbol = fields[1]; 11 | } 12 | String type = ""; 13 | if (fields.length > 3) { 14 | type = fields[2]; 15 | } 16 | if (type.equals("kline")) { 17 | 18 | } 19 | } 20 | 21 | public String getSymbol() { 22 | return symbol; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/test/java/com/binance/client/examples/websocket/SubscribeBookDepth.java: -------------------------------------------------------------------------------- 1 | package com.binance.client.examples.websocket; 2 | 3 | import com.binance.client.SubscriptionClient; 4 | 5 | public class SubscribeBookDepth { 6 | 7 | public static void main(String[] args) { 8 | 9 | SubscriptionClient client = SubscriptionClient.create(); 10 | 11 | client.subscribeBookDepthEvent("btcusdt", 5, ((event) -> { 12 | System.out.println(event); 13 | client.unsubscribeAll(); 14 | }), null); 15 | 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /src/test/java/com/binance/client/examples/websocket/SubscribeDiffDepth.java: -------------------------------------------------------------------------------- 1 | package com.binance.client.examples.websocket; 2 | 3 | import com.binance.client.SubscriptionClient; 4 | 5 | public class SubscribeDiffDepth { 6 | 7 | public static void main(String[] args) { 8 | 9 | SubscriptionClient client = SubscriptionClient.create(); 10 | 11 | client.subscribeDiffDepthEvent("btcusdt", ((event) -> { 12 | System.out.println(event); 13 | client.unsubscribeAll(); 14 | }), null); 15 | 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /src/test/java/com/binance/client/examples/websocket/SubscribeMarkPrice.java: -------------------------------------------------------------------------------- 1 | package com.binance.client.examples.websocket; 2 | 3 | import com.binance.client.SubscriptionClient; 4 | 5 | public class SubscribeMarkPrice { 6 | 7 | public static void main(String[] args) { 8 | 9 | SubscriptionClient client = SubscriptionClient.create(); 10 | 11 | client.subscribeMarkPriceEvent("btcusdt", ((event) -> { 12 | System.out.println(event); 13 | client.unsubscribeAll(); 14 | }), null); 15 | 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /src/test/java/com/binance/client/examples/websocket/SubscribeSymbolTicker.java: -------------------------------------------------------------------------------- 1 | package com.binance.client.examples.websocket; 2 | 3 | import com.binance.client.SubscriptionClient; 4 | 5 | public class SubscribeSymbolTicker { 6 | 7 | public static void main(String[] args) { 8 | 9 | SubscriptionClient client = SubscriptionClient.create(); 10 | 11 | client.subscribeSymbolTickerEvent("btcusdt", ((event) -> { 12 | System.out.println(event); 13 | client.unsubscribeAll(); 14 | }), null); 15 | 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /src/test/java/com/binance/client/examples/websocket/SubscribeAggregateTrade.java: -------------------------------------------------------------------------------- 1 | package com.binance.client.examples.websocket; 2 | 3 | import com.binance.client.SubscriptionClient; 4 | 5 | public class SubscribeAggregateTrade { 6 | 7 | public static void main(String[] args) { 8 | 9 | SubscriptionClient client = SubscriptionClient.create(); 10 | 11 | client.subscribeAggregateTradeEvent("btcusdt", ((event) -> { 12 | System.out.println(event); 13 | client.unsubscribeAll(); 14 | }), null); 15 | 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /src/test/java/com/binance/client/examples/websocket/SubscribeSymbolBookTicker.java: -------------------------------------------------------------------------------- 1 | package com.binance.client.examples.websocket; 2 | 3 | import com.binance.client.SubscriptionClient; 4 | 5 | public class SubscribeSymbolBookTicker { 6 | 7 | public static void main(String[] args) { 8 | 9 | SubscriptionClient client = SubscriptionClient.create(); 10 | 11 | client.subscribeSymbolBookTickerEvent("btcusdt", ((event) -> { 12 | System.out.println(event); 13 | client.unsubscribeAll(); 14 | }), null); 15 | 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /src/test/java/com/binance/client/examples/websocket/SubscribeSymbolMiniTicker.java: -------------------------------------------------------------------------------- 1 | package com.binance.client.examples.websocket; 2 | 3 | import com.binance.client.SubscriptionClient; 4 | 5 | public class SubscribeSymbolMiniTicker { 6 | 7 | public static void main(String[] args) { 8 | 9 | SubscriptionClient client = SubscriptionClient.create(); 10 | 11 | client.subscribeSymbolMiniTickerEvent("btcusdt", ((event) -> { 12 | System.out.println(event); 13 | client.unsubscribeAll(); 14 | }), null); 15 | 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/com/binance/client/model/enums/DepthStep.java: -------------------------------------------------------------------------------- 1 | package com.binance.client.model.enums; 2 | 3 | 4 | /** 5 | * The aggregation depth type. 6 | */ 7 | public enum DepthStep { 8 | 9 | /** 10 | * step0,step1,step2,step3,step4,step5 11 | */ 12 | STEP0("step0"), 13 | STEP1("step1"), 14 | STEP2("step2"), 15 | STEP3("step3"), 16 | STEP4("step4"), 17 | STEP5("step5"), 18 | ; 19 | 20 | private final String step; 21 | 22 | DepthStep(String step) { 23 | this.step = step; 24 | } 25 | 26 | public String getStep() { 27 | return step; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/com/binance/client/SubscriptionListener.java: -------------------------------------------------------------------------------- 1 | package com.binance.client; 2 | 3 | /** 4 | * You must implement the SubscriptionListener interface.
The server will push any update to 5 | * the client. if client get the update, the onReceive method will be called. 6 | * 7 | * @param The type of received data. 8 | */ 9 | @FunctionalInterface 10 | public interface SubscriptionListener { 11 | 12 | /** 13 | * onReceive will be called when get the data sent by server. 14 | * 15 | * @param data The data send by server. 16 | */ 17 | void onReceive(T data); 18 | } 19 | -------------------------------------------------------------------------------- /src/test/java/com/binance/client/examples/websocket/SubscribeSymbolLiquidationOrder.java: -------------------------------------------------------------------------------- 1 | package com.binance.client.examples.websocket; 2 | 3 | import com.binance.client.SubscriptionClient; 4 | 5 | public class SubscribeSymbolLiquidationOrder { 6 | 7 | public static void main(String[] args) { 8 | 9 | SubscriptionClient client = SubscriptionClient.create(); 10 | 11 | client.subscribeSymbolLiquidationOrderEvent("btcusdt", ((event) -> { 12 | System.out.println(event); 13 | client.unsubscribeAll(); 14 | }), null); 15 | 16 | } 17 | 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/com/binance/client/model/enums/BalanceMode.java: -------------------------------------------------------------------------------- 1 | package com.binance.client.model.enums; 2 | 3 | /** 4 | * The balance mode used for subscribing the balance notification. 5 | */ 6 | public enum BalanceMode { 7 | 8 | /** 9 | * Subscribe available balance 10 | */ 11 | AVAILABLE("0"), 12 | 13 | /** 14 | * Subscribe TOTAL balance, total balance is the sum of available and frozen 15 | */ 16 | TOTAL("1"); 17 | 18 | private final String code; 19 | 20 | BalanceMode(String code) { 21 | this.code = code; 22 | } 23 | 24 | public String getCode() { 25 | return code; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/com/binance/client/model/enums/DealRole.java: -------------------------------------------------------------------------------- 1 | package com.binance.client.model.enums; 2 | 3 | public enum DealRole { 4 | 5 | /** 6 | * TAKER,MAKER 7 | */ 8 | 9 | TAKER("taker"), 10 | MAKER("maker") 11 | ; 12 | 13 | private final String role; 14 | 15 | DealRole(String role) { 16 | this.role = role; 17 | } 18 | 19 | public String getRole() { 20 | return role; 21 | } 22 | 23 | public static DealRole find(String role) { 24 | for (DealRole fr : DealRole.values()) { 25 | if (fr.getRole().equals(role)) { 26 | return fr; 27 | } 28 | } 29 | return null; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/test/java/com/binance/client/examples/trade/GetBalance.java: -------------------------------------------------------------------------------- 1 | package com.binance.client.examples.trade; 2 | 3 | import com.binance.client.RequestOptions; 4 | import com.binance.client.SyncRequestClient; 5 | 6 | import com.binance.client.examples.constants.PrivateConfig; 7 | 8 | public class GetBalance { 9 | public static void main(String[] args) { 10 | RequestOptions options = new RequestOptions(); 11 | SyncRequestClient syncRequestClient = SyncRequestClient.create(PrivateConfig.API_KEY, PrivateConfig.SECRET_KEY, 12 | options); 13 | System.out.println(syncRequestClient.getBalance()); 14 | } 15 | } -------------------------------------------------------------------------------- /src/main/java/com/binance/client/model/enums/AccountChangeModeEnum.java: -------------------------------------------------------------------------------- 1 | package com.binance.client.model.enums; 2 | 3 | /** 4 | * The balance mode used for subscribing the balance notification. 5 | */ 6 | public enum AccountChangeModeEnum { 7 | 8 | /** 9 | * Subscribe balance change 10 | */ 11 | BALANCE("0"), 12 | 13 | /** 14 | * Subscribe TOTAL balance, total balance is the sum of available and frozen 15 | */ 16 | TOTAL("1"); 17 | 18 | private final String code; 19 | 20 | AccountChangeModeEnum(String code) { 21 | this.code = code; 22 | } 23 | 24 | public String getCode() { 25 | return code; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/com/binance/client/model/enums/EtfSwapType.java: -------------------------------------------------------------------------------- 1 | package com.binance.client.model.enums; 2 | 3 | import com.binance.client.impl.utils.EnumLookup; 4 | 5 | public enum EtfSwapType { 6 | ETF_SWAP_IN("1"), 7 | ETF_SWAP_OUT("2"); 8 | 9 | private final String code; 10 | 11 | EtfSwapType(String code) { 12 | this.code = code; 13 | } 14 | 15 | @Override 16 | public String toString() { 17 | return code; 18 | } 19 | 20 | private static final EnumLookup lookup = new EnumLookup<>(EtfSwapType.class); 21 | 22 | public static EtfSwapType lookup(String name) { 23 | return lookup.lookup(name); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/test/java/com/binance/client/examples/market/GetMarkPrice.java: -------------------------------------------------------------------------------- 1 | package com.binance.client.examples.market; 2 | 3 | import com.binance.client.RequestOptions; 4 | import com.binance.client.SyncRequestClient; 5 | 6 | import com.binance.client.examples.constants.PrivateConfig; 7 | 8 | public class GetMarkPrice { 9 | public static void main(String[] args) { 10 | RequestOptions options = new RequestOptions(); 11 | SyncRequestClient syncRequestClient = SyncRequestClient.create(PrivateConfig.API_KEY, PrivateConfig.SECRET_KEY, 12 | options); 13 | System.out.println(syncRequestClient.getMarkPrice("")); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/test/java/com/binance/client/examples/websocket/SubscribeCandlestick.java: -------------------------------------------------------------------------------- 1 | package com.binance.client.examples.websocket; 2 | 3 | import com.binance.client.SubscriptionClient; 4 | import com.binance.client.model.enums.CandlestickInterval; 5 | 6 | public class SubscribeCandlestick { 7 | 8 | public static void main(String[] args) { 9 | 10 | SubscriptionClient client = SubscriptionClient.create(); 11 | 12 | client.subscribeCandlestickEvent("btcusdt", CandlestickInterval.ONE_MINUTE, ((event) -> { 13 | System.out.println(event); 14 | client.unsubscribeAll(); 15 | }), null); 16 | 17 | } 18 | 19 | } 20 | -------------------------------------------------------------------------------- /src/main/java/com/binance/client/model/enums/QueryDirection.java: -------------------------------------------------------------------------------- 1 | package com.binance.client.model.enums; 2 | 3 | import com.binance.client.impl.utils.EnumLookup; 4 | 5 | public enum QueryDirection { 6 | PREV("prev"), 7 | NEXT("next"); 8 | 9 | private final String code; 10 | 11 | QueryDirection(String code) { 12 | this.code = code; 13 | } 14 | 15 | @Override 16 | public String toString() { 17 | return code; 18 | } 19 | 20 | private static final EnumLookup lookup = new EnumLookup<>(QueryDirection.class); 21 | 22 | public static QueryDirection lookup(String name) { 23 | return lookup.lookup(name); 24 | } 25 | } 26 | -------------------------------------------------------------------------------- /src/test/java/com/binance/client/examples/trade/GetOrder.java: -------------------------------------------------------------------------------- 1 | package com.binance.client.examples.trade; 2 | 3 | import com.binance.client.RequestOptions; 4 | import com.binance.client.SyncRequestClient; 5 | 6 | import com.binance.client.examples.constants.PrivateConfig; 7 | 8 | public class GetOrder { 9 | public static void main(String[] args) { 10 | RequestOptions options = new RequestOptions(); 11 | SyncRequestClient syncRequestClient = SyncRequestClient.create(PrivateConfig.API_KEY, PrivateConfig.SECRET_KEY, 12 | options); 13 | System.out.println(syncRequestClient.getOrder("BTCUSDT", 37886301L, null)); 14 | } 15 | } -------------------------------------------------------------------------------- /src/test/java/com/binance/client/examples/market/GetOldTrades.java: -------------------------------------------------------------------------------- 1 | package com.binance.client.examples.market; 2 | 3 | import com.binance.client.RequestOptions; 4 | import com.binance.client.SyncRequestClient; 5 | 6 | import com.binance.client.examples.constants.PrivateConfig; 7 | 8 | public class GetOldTrades { 9 | public static void main(String[] args) { 10 | RequestOptions options = new RequestOptions(); 11 | SyncRequestClient syncRequestClient = SyncRequestClient.create(PrivateConfig.API_KEY, PrivateConfig.SECRET_KEY, 12 | options); 13 | System.out.println(syncRequestClient.getOldTrades("BTCUSDT", 5, null)); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/test/java/com/binance/client/examples/market/GetOrderBook.java: -------------------------------------------------------------------------------- 1 | package com.binance.client.examples.market; 2 | 3 | import com.binance.client.RequestOptions; 4 | import com.binance.client.SyncRequestClient; 5 | 6 | import com.binance.client.examples.constants.PrivateConfig; 7 | 8 | public class GetOrderBook { 9 | public static void main(String[] args) { 10 | RequestOptions options = new RequestOptions(); 11 | SyncRequestClient syncRequestClient = SyncRequestClient.create(PrivateConfig.API_KEY, PrivateConfig.SECRET_KEY, 12 | options); 13 | System.out.println(syncRequestClient.getOrderBook("BTCUSDT", null)); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/test/java/com/binance/client/examples/trade/CancelOrder.java: -------------------------------------------------------------------------------- 1 | package com.binance.client.examples.trade; 2 | 3 | import com.binance.client.RequestOptions; 4 | import com.binance.client.SyncRequestClient; 5 | 6 | import com.binance.client.examples.constants.PrivateConfig; 7 | 8 | public class CancelOrder { 9 | public static void main(String[] args) { 10 | RequestOptions options = new RequestOptions(); 11 | SyncRequestClient syncRequestClient = SyncRequestClient.create(PrivateConfig.API_KEY, PrivateConfig.SECRET_KEY, 12 | options); 13 | System.out.println(syncRequestClient.cancelOrder("BTCUSDT", 37886301L, null)); 14 | } 15 | } -------------------------------------------------------------------------------- /src/test/java/com/binance/client/examples/trade/GetPositionRisk.java: -------------------------------------------------------------------------------- 1 | package com.binance.client.examples.trade; 2 | 3 | import com.binance.client.RequestOptions; 4 | import com.binance.client.SyncRequestClient; 5 | 6 | import com.binance.client.examples.constants.PrivateConfig; 7 | 8 | public class GetPositionRisk { 9 | public static void main(String[] args) { 10 | RequestOptions options = new RequestOptions(); 11 | SyncRequestClient syncRequestClient = SyncRequestClient.create(PrivateConfig.API_KEY, PrivateConfig.SECRET_KEY, 12 | options); 13 | System.out.println(syncRequestClient.getPositionRisk("btcusdt")); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/test/java/com/binance/client/examples/trade/GetAccountInformation.java: -------------------------------------------------------------------------------- 1 | package com.binance.client.examples.trade; 2 | 3 | import com.binance.client.RequestOptions; 4 | import com.binance.client.SyncRequestClient; 5 | 6 | import com.binance.client.examples.constants.PrivateConfig; 7 | 8 | public class GetAccountInformation { 9 | public static void main(String[] args) { 10 | RequestOptions options = new RequestOptions(); 11 | SyncRequestClient syncRequestClient = SyncRequestClient.create(PrivateConfig.API_KEY, PrivateConfig.SECRET_KEY, 12 | options); 13 | System.out.println(syncRequestClient.getAccountInformation()); 14 | } 15 | } -------------------------------------------------------------------------------- /src/test/java/com/binance/client/examples/market/GetRecentTrades.java: -------------------------------------------------------------------------------- 1 | package com.binance.client.examples.market; 2 | 3 | import com.binance.client.RequestOptions; 4 | import com.binance.client.SyncRequestClient; 5 | 6 | import com.binance.client.examples.constants.PrivateConfig; 7 | 8 | public class GetRecentTrades { 9 | public static void main(String[] args) { 10 | RequestOptions options = new RequestOptions(); 11 | SyncRequestClient syncRequestClient = SyncRequestClient.create(PrivateConfig.API_KEY, PrivateConfig.SECRET_KEY, 12 | options); 13 | System.out.println(syncRequestClient.getRecentTrades("BTCUSDT", null)); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/test/java/com/binance/client/examples/market/GetExchangeInformation.java: -------------------------------------------------------------------------------- 1 | package com.binance.client.examples.market; 2 | 3 | import com.binance.client.RequestOptions; 4 | import com.binance.client.SyncRequestClient; 5 | 6 | import com.binance.client.examples.constants.PrivateConfig; 7 | 8 | public class GetExchangeInformation { 9 | public static void main(String[] args) { 10 | RequestOptions options = new RequestOptions(); 11 | SyncRequestClient syncRequestClient = SyncRequestClient.create(PrivateConfig.API_KEY, PrivateConfig.SECRET_KEY, 12 | options); 13 | System.out.println(syncRequestClient.getExchangeInformation()); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/test/java/com/binance/client/examples/market/GetFundingRate.java: -------------------------------------------------------------------------------- 1 | package com.binance.client.examples.market; 2 | 3 | import com.binance.client.RequestOptions; 4 | import com.binance.client.SyncRequestClient; 5 | 6 | import com.binance.client.examples.constants.PrivateConfig; 7 | 8 | public class GetFundingRate { 9 | public static void main(String[] args) { 10 | RequestOptions options = new RequestOptions(); 11 | SyncRequestClient syncRequestClient = SyncRequestClient.create(PrivateConfig.API_KEY, PrivateConfig.SECRET_KEY, 12 | options); 13 | System.out.println(syncRequestClient.getFundingRate("BTCUSDT", null, null, null)); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/test/java/com/binance/client/examples/trade/ChangeInitialLeverage.java: -------------------------------------------------------------------------------- 1 | package com.binance.client.examples.trade; 2 | 3 | import com.binance.client.RequestOptions; 4 | import com.binance.client.SyncRequestClient; 5 | 6 | import com.binance.client.examples.constants.PrivateConfig; 7 | 8 | public class ChangeInitialLeverage { 9 | public static void main(String[] args) { 10 | RequestOptions options = new RequestOptions(); 11 | SyncRequestClient syncRequestClient = SyncRequestClient.create(PrivateConfig.API_KEY, PrivateConfig.SECRET_KEY, 12 | options); 13 | System.out.println(syncRequestClient.changeInitialLeverage("BTCUSDT", 1)); 14 | } 15 | } -------------------------------------------------------------------------------- /src/test/java/com/binance/client/examples/trade/GetAccountTrades.java: -------------------------------------------------------------------------------- 1 | package com.binance.client.examples.trade; 2 | 3 | import com.binance.client.RequestOptions; 4 | import com.binance.client.SyncRequestClient; 5 | 6 | import com.binance.client.examples.constants.PrivateConfig; 7 | 8 | public class GetAccountTrades { 9 | public static void main(String[] args) { 10 | RequestOptions options = new RequestOptions(); 11 | SyncRequestClient syncRequestClient = SyncRequestClient.create(PrivateConfig.API_KEY, PrivateConfig.SECRET_KEY, 12 | options); 13 | System.out.println(syncRequestClient.getAccountTrades("BTCUSDT", null, null, null, null)); 14 | } 15 | } -------------------------------------------------------------------------------- /src/test/java/com/binance/client/examples/trade/GetIncomeHistory.java: -------------------------------------------------------------------------------- 1 | package com.binance.client.examples.trade; 2 | 3 | import com.binance.client.RequestOptions; 4 | import com.binance.client.SyncRequestClient; 5 | 6 | import com.binance.client.examples.constants.PrivateConfig; 7 | 8 | public class GetIncomeHistory { 9 | public static void main(String[] args) { 10 | RequestOptions options = new RequestOptions(); 11 | SyncRequestClient syncRequestClient = SyncRequestClient.create(PrivateConfig.API_KEY, PrivateConfig.SECRET_KEY, 12 | options); 13 | System.out.println(syncRequestClient.getIncomeHistory("BTCUSDT", null, null, null, null)); 14 | } 15 | } -------------------------------------------------------------------------------- /src/main/java/com/binance/client/model/enums/AccountState.java: -------------------------------------------------------------------------------- 1 | package com.binance.client.model.enums; 2 | 3 | import com.binance.client.impl.utils.EnumLookup; 4 | 5 | /** 6 | * working, lock. 7 | */ 8 | public enum AccountState { 9 | WORKING("working"), 10 | LOCK("lock"); 11 | 12 | private final String code; 13 | 14 | AccountState(String code) { 15 | this.code = code; 16 | } 17 | 18 | @Override 19 | public String toString() { 20 | return code; 21 | } 22 | 23 | private static final EnumLookup lookup = new EnumLookup<>(AccountState.class); 24 | 25 | public static AccountState lookup(String name) { 26 | return lookup.lookup(name); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/com/binance/client/model/enums/TradeDirection.java: -------------------------------------------------------------------------------- 1 | package com.binance.client.model.enums; 2 | 3 | import com.binance.client.impl.utils.EnumLookup; 4 | 5 | /** 6 | * buy, sell. 7 | */ 8 | public enum TradeDirection { 9 | BUY("buy"), 10 | SELL("sell"); 11 | 12 | private final String code; 13 | 14 | TradeDirection(String side) { 15 | this.code = side; 16 | } 17 | 18 | @Override 19 | public String toString() { 20 | return code; 21 | } 22 | 23 | private static final EnumLookup lookup = new EnumLookup<>(TradeDirection.class); 24 | 25 | public static TradeDirection lookup(String name) { 26 | return lookup.lookup(name); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/test/java/com/binance/client/examples/market/GetAggregateTrades.java: -------------------------------------------------------------------------------- 1 | package com.binance.client.examples.market; 2 | 3 | import com.binance.client.RequestOptions; 4 | import com.binance.client.SyncRequestClient; 5 | 6 | import com.binance.client.examples.constants.PrivateConfig; 7 | 8 | public class GetAggregateTrades { 9 | public static void main(String[] args) { 10 | RequestOptions options = new RequestOptions(); 11 | SyncRequestClient syncRequestClient = SyncRequestClient.create(PrivateConfig.API_KEY, PrivateConfig.SECRET_KEY, 12 | options); 13 | System.out.println(syncRequestClient.getAggregateTrades("BTCUSDT", null, null, null, 5)); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/test/java/com/binance/client/examples/market/GetLiquidationOrders.java: -------------------------------------------------------------------------------- 1 | package com.binance.client.examples.market; 2 | 3 | import com.binance.client.RequestOptions; 4 | import com.binance.client.SyncRequestClient; 5 | 6 | import com.binance.client.examples.constants.PrivateConfig; 7 | 8 | public class GetLiquidationOrders { 9 | public static void main(String[] args) { 10 | RequestOptions options = new RequestOptions(); 11 | SyncRequestClient syncRequestClient = SyncRequestClient.create(PrivateConfig.API_KEY, PrivateConfig.SECRET_KEY, 12 | options); 13 | System.out.println(syncRequestClient.getLiquidationOrders("BTCUSDT", null, null, null, null)); 14 | } 15 | } -------------------------------------------------------------------------------- /src/main/java/com/binance/client/model/enums/SymbolState.java: -------------------------------------------------------------------------------- 1 | package com.binance.client.model.enums; 2 | 3 | public enum SymbolState { 4 | 5 | /** 6 | * ONLINE, OFFLINE, SUSPEND. 7 | */ 8 | ONLINE("online"), 9 | OFFLINE("offline"), 10 | SUSPEND("suspend") 11 | ; 12 | private final String state; 13 | 14 | SymbolState(String state) { 15 | this.state = state; 16 | } 17 | 18 | public String getState() { 19 | return state; 20 | } 21 | 22 | public static SymbolState find(String state) { 23 | for (SymbolState st : SymbolState.values()) { 24 | if (st.getState().equals(state)) { 25 | return st; 26 | } 27 | } 28 | return null; 29 | } 30 | 31 | } 32 | -------------------------------------------------------------------------------- /src/test/java/com/binance/client/examples/trade/GetOpenOrders.java: -------------------------------------------------------------------------------- 1 | package com.binance.client.examples.trade; 2 | 3 | import com.binance.client.RequestOptions; 4 | import com.binance.client.SyncRequestClient; 5 | 6 | import com.binance.client.examples.constants.PrivateConfig; 7 | 8 | public class GetOpenOrders { 9 | public static void main(String[] args) { 10 | RequestOptions options = new RequestOptions(); 11 | SyncRequestClient syncRequestClient = SyncRequestClient.create(PrivateConfig.API_KEY, PrivateConfig.SECRET_KEY, 12 | options); 13 | System.out.println(syncRequestClient.getOpenOrders("BTCUSDT")); 14 | // System.out.println(syncRequestClient.getOpenOrders(null)); 15 | } 16 | } -------------------------------------------------------------------------------- /src/test/java/com/binance/client/examples/trade/GetPositionSide.java: -------------------------------------------------------------------------------- 1 | package com.binance.client.examples.trade; 2 | 3 | import com.binance.client.RequestOptions; 4 | import com.binance.client.SyncRequestClient; 5 | import com.binance.client.examples.constants.PrivateConfig; 6 | 7 | /** 8 | * @author : wangwanlu 9 | * @since : 2020/4/7, Tue 10 | **/ 11 | public class GetPositionSide { 12 | 13 | public static void main(String[] args) { 14 | RequestOptions options = new RequestOptions(); 15 | SyncRequestClient syncRequestClient = SyncRequestClient.create(PrivateConfig.API_KEY, PrivateConfig.SECRET_KEY, 16 | options); 17 | System.out.println(syncRequestClient.getPositionSide()); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/main/java/com/binance/client/model/enums/EtfStatus.java: -------------------------------------------------------------------------------- 1 | package com.binance.client.model.enums; 2 | 3 | import com.binance.client.impl.utils.EnumLookup; 4 | 5 | public enum EtfStatus { 6 | NORMAL("1"), 7 | REBALANCING_START("2"), 8 | CREATION_AND_REDEMPTION_SUSPEND("3"), 9 | CREATION_SUSPEND("4"), 10 | REDEMPTION_SUSPEND("5"); 11 | 12 | private final String code; 13 | 14 | EtfStatus(String code) { 15 | this.code = code; 16 | } 17 | 18 | @Override 19 | public String toString() { 20 | return code; 21 | } 22 | 23 | private static final EnumLookup lookup = new EnumLookup<>(EtfStatus.class); 24 | 25 | public static EtfStatus lookup(String name) { 26 | return lookup.lookup(name); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/test/java/com/binance/client/examples/trade/ChangePositionSide.java: -------------------------------------------------------------------------------- 1 | package com.binance.client.examples.trade; 2 | 3 | import com.binance.client.RequestOptions; 4 | import com.binance.client.SyncRequestClient; 5 | import com.binance.client.examples.constants.PrivateConfig; 6 | 7 | /** 8 | * @author : wangwanlu 9 | * @since : 2020/3/25, Wed 10 | **/ 11 | public class ChangePositionSide { 12 | public static void main(String[] args) { 13 | RequestOptions options = new RequestOptions(); 14 | SyncRequestClient syncRequestClient = SyncRequestClient.create(PrivateConfig.API_KEY, PrivateConfig.SECRET_KEY, 15 | options); 16 | System.out.println(syncRequestClient.changePositionSide("true")); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/test/java/com/binance/client/examples/trade/CancelAllOpenOrders.java: -------------------------------------------------------------------------------- 1 | package com.binance.client.examples.trade; 2 | 3 | import com.binance.client.RequestOptions; 4 | import com.binance.client.SyncRequestClient; 5 | import com.binance.client.examples.constants.PrivateConfig; 6 | 7 | /** 8 | * @author : wangwanlu 9 | * @since : 2020/4/7, Tue 10 | **/ 11 | public class CancelAllOpenOrders { 12 | 13 | public static void main(String[] args) { 14 | RequestOptions options = new RequestOptions(); 15 | SyncRequestClient syncRequestClient = SyncRequestClient.create(PrivateConfig.API_KEY, PrivateConfig.SECRET_KEY, 16 | options); 17 | System.out.println(syncRequestClient.cancelAllOpenOrder("BTCUSDT")); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/test/java/com/binance/client/examples/market/GetSymbolPriceTicker.java: -------------------------------------------------------------------------------- 1 | package com.binance.client.examples.market; 2 | 3 | import com.binance.client.RequestOptions; 4 | import com.binance.client.SyncRequestClient; 5 | 6 | import com.binance.client.examples.constants.PrivateConfig; 7 | 8 | public class GetSymbolPriceTicker { 9 | public static void main(String[] args) { 10 | RequestOptions options = new RequestOptions(); 11 | SyncRequestClient syncRequestClient = SyncRequestClient.create(PrivateConfig.API_KEY, PrivateConfig.SECRET_KEY, 12 | options); 13 | System.out.println(syncRequestClient.getSymbolPriceTicker("BTCUSDT")); 14 | // System.out.println(syncRequestClient.getSymbolPriceTicker(null)); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/test/java/com/binance/client/examples/market/GetOpenInterestStat.java: -------------------------------------------------------------------------------- 1 | package com.binance.client.examples.market; 2 | 3 | import com.binance.client.RequestOptions; 4 | import com.binance.client.SyncRequestClient; 5 | import com.binance.client.examples.constants.PrivateConfig; 6 | import com.binance.client.model.enums.PeriodType; 7 | 8 | public class GetOpenInterestStat { 9 | public static void main(String[] args) { 10 | RequestOptions options = new RequestOptions(); 11 | SyncRequestClient syncRequestClient = SyncRequestClient.create(PrivateConfig.API_KEY, PrivateConfig.SECRET_KEY, 12 | options); 13 | System.out.println(syncRequestClient.getOpenInterestStat("BTCUSDT", PeriodType._5m,null,null,10L)); 14 | 15 | 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/test/java/com/binance/client/examples/market/GetGlobalAccountRatio.java: -------------------------------------------------------------------------------- 1 | package com.binance.client.examples.market; 2 | 3 | import com.binance.client.RequestOptions; 4 | import com.binance.client.SyncRequestClient; 5 | import com.binance.client.examples.constants.PrivateConfig; 6 | import com.binance.client.model.enums.PeriodType; 7 | 8 | public class GetGlobalAccountRatio { 9 | public static void main(String[] args) { 10 | RequestOptions options = new RequestOptions(); 11 | SyncRequestClient syncRequestClient = SyncRequestClient.create(PrivateConfig.API_KEY, PrivateConfig.SECRET_KEY, 12 | options); 13 | System.out.println(syncRequestClient.getGlobalAccountRatio("BTCUSDT", PeriodType._5m,null,null,10L)); 14 | 15 | 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/test/java/com/binance/client/examples/market/GetTakerLongShortStat.java: -------------------------------------------------------------------------------- 1 | package com.binance.client.examples.market; 2 | 3 | import com.binance.client.RequestOptions; 4 | import com.binance.client.SyncRequestClient; 5 | import com.binance.client.examples.constants.PrivateConfig; 6 | import com.binance.client.model.enums.PeriodType; 7 | 8 | public class GetTakerLongShortStat { 9 | public static void main(String[] args) { 10 | RequestOptions options = new RequestOptions(); 11 | SyncRequestClient syncRequestClient = SyncRequestClient.create(PrivateConfig.API_KEY, PrivateConfig.SECRET_KEY, 12 | options); 13 | System.out.println(syncRequestClient.getOpenInterestStat("BTCUSDT", PeriodType._5m,null,null,10L)); 14 | 15 | 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/test/java/com/binance/client/examples/trade/GetAllOrders.java: -------------------------------------------------------------------------------- 1 | package com.binance.client.examples.trade; 2 | 3 | import com.binance.client.RequestOptions; 4 | import com.binance.client.SyncRequestClient; 5 | 6 | import com.binance.client.examples.constants.PrivateConfig; 7 | 8 | public class GetAllOrders { 9 | public static void main(String[] args) { 10 | RequestOptions options = new RequestOptions(); 11 | SyncRequestClient syncRequestClient = SyncRequestClient.create(PrivateConfig.API_KEY, PrivateConfig.SECRET_KEY, 12 | options); 13 | System.out.println(syncRequestClient.getAllOrders("BTCUSDT", null, null, null, 10)); 14 | // System.out.println(syncRequestClient.getAllOrders("BTCUSDT", null, null, null, null)); 15 | } 16 | } -------------------------------------------------------------------------------- /src/test/java/com/binance/client/examples/market/Get24hrTickerPriceChange.java: -------------------------------------------------------------------------------- 1 | package com.binance.client.examples.market; 2 | 3 | import com.binance.client.RequestOptions; 4 | import com.binance.client.SyncRequestClient; 5 | 6 | import com.binance.client.examples.constants.PrivateConfig; 7 | 8 | public class Get24hrTickerPriceChange { 9 | public static void main(String[] args) { 10 | RequestOptions options = new RequestOptions(); 11 | SyncRequestClient syncRequestClient = SyncRequestClient.create(PrivateConfig.API_KEY, PrivateConfig.SECRET_KEY, 12 | options); 13 | System.out.println(syncRequestClient.get24hrTickerPriceChange("BTCUSDT")); 14 | // System.out.println(syncRequestClient.get24hrTickerPriceChange(null)); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/test/java/com/binance/client/examples/market/GetCandlestick.java: -------------------------------------------------------------------------------- 1 | package com.binance.client.examples.market; 2 | 3 | import com.binance.client.model.enums.CandlestickInterval; 4 | 5 | import com.binance.client.RequestOptions; 6 | import com.binance.client.SyncRequestClient; 7 | 8 | import com.binance.client.examples.constants.PrivateConfig; 9 | 10 | public class GetCandlestick { 11 | public static void main(String[] args) { 12 | RequestOptions options = new RequestOptions(); 13 | SyncRequestClient syncRequestClient = SyncRequestClient.create(PrivateConfig.API_KEY, PrivateConfig.SECRET_KEY, 14 | options); 15 | System.out.println(syncRequestClient.getCandlestick("BTCUSDT", CandlestickInterval.ONE_MINUTE, null, null, 5)); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/test/java/com/binance/client/examples/market/GetSymbolOrderBookTicker.java: -------------------------------------------------------------------------------- 1 | package com.binance.client.examples.market; 2 | 3 | import com.binance.client.RequestOptions; 4 | import com.binance.client.SyncRequestClient; 5 | 6 | import com.binance.client.examples.constants.PrivateConfig; 7 | 8 | public class GetSymbolOrderBookTicker { 9 | public static void main(String[] args) { 10 | RequestOptions options = new RequestOptions(); 11 | SyncRequestClient syncRequestClient = SyncRequestClient.create(PrivateConfig.API_KEY, PrivateConfig.SECRET_KEY, 12 | options); 13 | System.out.println(syncRequestClient.getSymbolOrderBookTicker("BTCUSDT")); 14 | // System.out.println(syncRequestClient.getSymbolOrderBookTicker(null)); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/test/java/com/binance/client/examples/market/GetTakerLongShortRatio.java: -------------------------------------------------------------------------------- 1 | package com.binance.client.examples.market; 2 | 3 | import com.binance.client.RequestOptions; 4 | import com.binance.client.SyncRequestClient; 5 | import com.binance.client.examples.constants.PrivateConfig; 6 | import com.binance.client.model.enums.PeriodType; 7 | 8 | public class GetTakerLongShortRatio { 9 | public static void main(String[] args) { 10 | RequestOptions options = new RequestOptions(); 11 | SyncRequestClient syncRequestClient = SyncRequestClient.create(PrivateConfig.API_KEY, PrivateConfig.SECRET_KEY, 12 | options); 13 | System.out.println(syncRequestClient.getTakerLongShortRatio("BTCUSDT", PeriodType._5m,null,null,10L)); 14 | 15 | 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/test/java/com/binance/client/examples/market/GetTopTraderAccountRatio.java: -------------------------------------------------------------------------------- 1 | package com.binance.client.examples.market; 2 | 3 | import com.binance.client.RequestOptions; 4 | import com.binance.client.SyncRequestClient; 5 | import com.binance.client.examples.constants.PrivateConfig; 6 | import com.binance.client.model.enums.PeriodType; 7 | 8 | public class GetTopTraderAccountRatio { 9 | public static void main(String[] args) { 10 | RequestOptions options = new RequestOptions(); 11 | SyncRequestClient syncRequestClient = SyncRequestClient.create(PrivateConfig.API_KEY, PrivateConfig.SECRET_KEY, 12 | options); 13 | System.out.println(syncRequestClient.getTopTraderAccountRatio("BTCUSDT", PeriodType._5m,null,null,10L)); 14 | 15 | 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/test/java/com/binance/client/examples/market/GetTopTraderPositionRatio.java: -------------------------------------------------------------------------------- 1 | package com.binance.client.examples.market; 2 | 3 | import com.binance.client.RequestOptions; 4 | import com.binance.client.SyncRequestClient; 5 | import com.binance.client.examples.constants.PrivateConfig; 6 | import com.binance.client.model.enums.PeriodType; 7 | 8 | public class GetTopTraderPositionRatio { 9 | public static void main(String[] args) { 10 | RequestOptions options = new RequestOptions(); 11 | SyncRequestClient syncRequestClient = SyncRequestClient.create(PrivateConfig.API_KEY, PrivateConfig.SECRET_KEY, 12 | options); 13 | System.out.println(syncRequestClient.getTopTraderPositionRatio("BTCUSDT", PeriodType._5m,null,null,10L)); 14 | 15 | 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/com/binance/client/model/enums/LoanOrderStates.java: -------------------------------------------------------------------------------- 1 | package com.binance.client.model.enums; 2 | 3 | import com.binance.client.impl.utils.EnumLookup; 4 | 5 | /** 6 | * created, accrual, cleared, invalid. 7 | */ 8 | public enum LoanOrderStates { 9 | 10 | CREATED("created"), 11 | ACCRUAL("accrual"), 12 | CLEARED("cleared"), 13 | INVALID("invalid"); 14 | 15 | private final String code; 16 | 17 | LoanOrderStates(String state) { 18 | this.code = state; 19 | } 20 | 21 | @Override 22 | public String toString() { 23 | return code; 24 | } 25 | 26 | private static final EnumLookup lookup = new EnumLookup<>(LoanOrderStates.class); 27 | 28 | public static LoanOrderStates lookup(String name) { 29 | return lookup.lookup(name); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/com/binance/client/model/enums/DepositState.java: -------------------------------------------------------------------------------- 1 | package com.binance.client.model.enums; 2 | 3 | import com.binance.client.impl.utils.EnumLookup; 4 | 5 | 6 | /** 7 | * withdraw, deposit. 8 | */ 9 | public enum DepositState { 10 | 11 | UNKNOWN("unknown"), 12 | CONFIRMING("confirming"), 13 | SAFE("safe"), 14 | CONFIRMED("confirmed"), 15 | ORPHAN("orphan"); 16 | 17 | 18 | private final String code; 19 | 20 | DepositState(String code) { 21 | this.code = code; 22 | } 23 | 24 | @Override 25 | public String toString() { 26 | return code; 27 | } 28 | 29 | private static final EnumLookup lookup = new EnumLookup<>(DepositState.class); 30 | 31 | public static DepositState lookup(String name) { 32 | return lookup.lookup(name); 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/com/binance/client/model/enums/BalanceType.java: -------------------------------------------------------------------------------- 1 | package com.binance.client.model.enums; 2 | 3 | import com.binance.client.impl.utils.EnumLookup; 4 | 5 | public enum BalanceType { 6 | TRADE("trade"), 7 | FROZEN("frozen"), 8 | LOAN("loan"), 9 | INTEREST("interest"), 10 | LOAN_AVAILABLE("loan-available"), 11 | TRANSFER_OUT_AVAILABLE("transfer-out-available"); 12 | 13 | 14 | 15 | private final String code; 16 | 17 | BalanceType(String code) { 18 | this.code = code; 19 | } 20 | 21 | @Override 22 | public String toString() { 23 | return code; 24 | } 25 | 26 | private static final EnumLookup lookup = new EnumLookup<>(BalanceType.class); 27 | 28 | public static BalanceType lookup(String name) { 29 | return lookup.lookup(name); 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/com/binance/client/ResponseCallback.java: -------------------------------------------------------------------------------- 1 | package com.binance.client; 2 | 3 | /** 4 | * The interface for define asynchronous invoking callback.
If you want to ues the asynchronous 5 | * invoking, you must implement the ResponseCallback yourself.
The onResponse method is 6 | * mandatory, when the asynchronous invoking completed, this method will be called.
You should 7 | * check the AsyncResult to know whether the asynchronous invoking is successful or not, and get the 8 | * response data from AsyncResult. 9 | */ 10 | @FunctionalInterface 11 | public interface ResponseCallback { 12 | 13 | /** 14 | * Be called when the request successful. 15 | * 16 | * @param response The {@link AsyncResult} of the asynchronous invoking. 17 | */ 18 | void onResponse(T response); 19 | } 20 | -------------------------------------------------------------------------------- /src/main/java/com/binance/client/model/enums/TransferFuturesDirection.java: -------------------------------------------------------------------------------- 1 | package com.binance.client.model.enums; 2 | 3 | 4 | public enum TransferFuturesDirection { 5 | 6 | /** 7 | * FUTURES_TO_PRO,PRO_TO_FUTURES 8 | */ 9 | FUTURES_TO_PRO("futures-to-pro"), 10 | PRO_TO_FUTURES("pro-to-futures") 11 | ; 12 | 13 | private String direction; 14 | 15 | TransferFuturesDirection(String direction) { 16 | this.direction = direction; 17 | } 18 | 19 | public String getDirection() { 20 | return direction; 21 | } 22 | 23 | public static TransferFuturesDirection find(String direction){ 24 | for (TransferFuturesDirection d : TransferFuturesDirection.values()) { 25 | if (d.getDirection().equals(direction)) { 26 | return d; 27 | } 28 | } 29 | return null; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/com/binance/client/impl/WebsocketRequest.java: -------------------------------------------------------------------------------- 1 | package com.binance.client.impl; 2 | 3 | import com.binance.client.SubscriptionErrorHandler; 4 | import com.binance.client.SubscriptionListener; 5 | import com.binance.client.impl.utils.Handler; 6 | 7 | class WebsocketRequest { 8 | 9 | WebsocketRequest(SubscriptionListener listener, SubscriptionErrorHandler errorHandler) { 10 | this.updateCallback = listener; 11 | this.errorHandler = errorHandler; 12 | } 13 | 14 | String signatureVersion = "2"; 15 | String name; 16 | Handler connectionHandler; 17 | Handler authHandler = null; 18 | final SubscriptionListener updateCallback; 19 | RestApiJsonParser jsonParser; 20 | final SubscriptionErrorHandler errorHandler; 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/com/binance/client/model/enums/CandlestickInterval.java: -------------------------------------------------------------------------------- 1 | package com.binance.client.model.enums; 2 | 3 | /** 4 | * 1min, 5min, 15min, 30min, 60min, 1day, 1mon, 1week, 1year 5 | */ 6 | public enum CandlestickInterval { 7 | ONE_MINUTE("1m"), 8 | THREE_MINUTES("3m"), 9 | FIVE_MINUTES("5m"), 10 | FIFTEEN_MINUTES("15m"), 11 | HALF_HOURLY("30m"), 12 | HOURLY("1h"), 13 | TWO_HOURLY("2h"), 14 | FOUR_HOURLY("4h"), 15 | SIX_HOURLY("6h"), 16 | EIGHT_HOURLY("8h"), 17 | TWELVE_HOURLY("12h"), 18 | DAILY("1d"), 19 | THREE_DAILY("3d"), 20 | WEEKLY("1w"), 21 | MONTHLY("1M"); 22 | 23 | private final String code; 24 | 25 | CandlestickInterval(String code) { 26 | this.code = code; 27 | } 28 | 29 | @Override 30 | public String toString() { 31 | return code; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/com/binance/client/model/enums/OrderStatus.java: -------------------------------------------------------------------------------- 1 | package com.binance.client.model.enums; 2 | 3 | import com.binance.client.impl.utils.EnumLookup; 4 | 5 | /** 6 | * NEW, PARTIALLY_FILLED, FILLED. CANCELED, REJECTED EXPIRED. 7 | */ 8 | public enum OrderStatus { 9 | NEW("NEW"), 10 | PARTIALLY_FILLED("PARTIALLY_FILLED"), 11 | FILLED("FILLED"), 12 | CANCELED("CANCELED"), 13 | REJECTED("REJECTED"), 14 | EXPIRED("EXPIRED"); 15 | 16 | 17 | private final String code; 18 | 19 | OrderStatus(String code) { 20 | this.code = code; 21 | } 22 | 23 | @Override 24 | public String toString() { 25 | return code; 26 | } 27 | 28 | private static final EnumLookup lookup = new EnumLookup<>(OrderStatus.class); 29 | 30 | public static OrderStatus lookup(String name) { 31 | return lookup.lookup(name); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/com/binance/client/model/enums/TransferMasterType.java: -------------------------------------------------------------------------------- 1 | package com.binance.client.model.enums; 2 | 3 | import com.binance.client.impl.utils.EnumLookup; 4 | 5 | public enum TransferMasterType { 6 | 7 | 8 | MASTER_TRANSFER_IN("master-transfer-in"), 9 | MASTER_TRANSFER_OUT("master-transfer-out"), 10 | MASTER_POINT_TRANSFER_IN("master-point-transfer-in"), 11 | MASTER_POINT_TRANSFER_OUT("master-point-transfer-out"); 12 | private final String code; 13 | 14 | TransferMasterType(String side) { 15 | this.code = side; 16 | } 17 | 18 | @Override 19 | public String toString() { 20 | return code; 21 | } 22 | 23 | private static final EnumLookup lookup = new EnumLookup<>(TransferMasterType.class); 24 | 25 | public static TransferMasterType lookup(String name) { 26 | return lookup.lookup(name); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/test/java/com/binance/client/examples/trade/ChangeMarginType.java: -------------------------------------------------------------------------------- 1 | package com.binance.client.examples.trade; 2 | 3 | import com.binance.client.RequestOptions; 4 | import com.binance.client.SyncRequestClient; 5 | import com.binance.client.examples.constants.PrivateConfig; 6 | import com.binance.client.model.enums.MarginType; 7 | 8 | /** 9 | * @author : wangwanlu 10 | * @since : 2020/4/23, Thu 11 | **/ 12 | public class ChangeMarginType { 13 | 14 | public static void main(String[] args) { 15 | RequestOptions options = new RequestOptions(); 16 | SyncRequestClient syncRequestClient = SyncRequestClient.create(PrivateConfig.API_KEY, PrivateConfig.SECRET_KEY, 17 | options); 18 | 19 | // margin type: ISOLATED, CROSSED 20 | System.out.println(syncRequestClient.changeMarginType("BTCUSDT", MarginType.ISOLATED)); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/com/binance/client/model/enums/AccountType.java: -------------------------------------------------------------------------------- 1 | package com.binance.client.model.enums; 2 | 3 | import com.binance.client.impl.utils.EnumLookup; 4 | 5 | /** 6 | * SPOT, MARGIN, OTC, POINT, UNKNOWN. 7 | */ 8 | public enum AccountType { 9 | SPOT("spot"), 10 | MARGIN("margin"), 11 | OTC("otc"), 12 | POINT("point"), 13 | SUPER_MARGIN("super-margin"), 14 | MINEPOOL("minepool"), 15 | ETF( "etf"), 16 | AGENCY( "agency"), 17 | UNKNOWN("unknown"); 18 | 19 | private final String code; 20 | 21 | AccountType(String code) { 22 | this.code = code; 23 | } 24 | 25 | @Override 26 | public String toString() { 27 | return code; 28 | } 29 | 30 | private static final EnumLookup lookup = new EnumLookup<>(AccountType.class); 31 | 32 | public static AccountType lookup(String name) { 33 | return lookup.lookup(name); 34 | } 35 | 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/com/binance/client/model/enums/PeriodType.java: -------------------------------------------------------------------------------- 1 | package com.binance.client.model.enums; 2 | 3 | import com.binance.client.impl.utils.EnumLookup; 4 | 5 | public enum PeriodType { 6 | _5m("5m"), 7 | _15m("15m"), 8 | _30m("30m"), 9 | _1h("1h"), 10 | _2h("2h"), 11 | _4h("4h"), 12 | _6h("6h"), 13 | _12h("12h"), 14 | _1d("1d"); 15 | 16 | private final String code; 17 | 18 | PeriodType(String code) { 19 | this.code = code; 20 | } 21 | 22 | 23 | public String getCode() { 24 | return code; 25 | } 26 | 27 | @Override 28 | public String toString() { 29 | return code; 30 | } 31 | 32 | private static final EnumLookup lookup = new EnumLookup<>(PeriodType.class); 33 | 34 | public static PeriodType lookup(String name) { 35 | return lookup.lookup(name); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/com/binance/client/impl/utils/EnumLookup.java: -------------------------------------------------------------------------------- 1 | package com.binance.client.impl.utils; 2 | 3 | import java.util.EnumSet; 4 | import java.util.HashMap; 5 | import java.util.Map; 6 | 7 | import org.slf4j.Logger; 8 | import org.slf4j.LoggerFactory; 9 | 10 | public class EnumLookup> { 11 | 12 | 13 | Logger logger = LoggerFactory.getLogger(EnumLookup.class); 14 | 15 | private final Map map = new HashMap<>(); 16 | private final String enumName; 17 | 18 | public EnumLookup(Class clazz) { 19 | enumName = clazz.getName(); 20 | for (T item : EnumSet.allOf(clazz)) { 21 | map.put(item.toString(), item); 22 | } 23 | } 24 | 25 | public T lookup(String name) { 26 | if (!map.containsKey(name)) { 27 | logger.error("[Enum] Cannot found " + name + " in Enum " + enumName); 28 | return null; 29 | } 30 | return map.get(name); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/com/binance/client/model/market/OrderBookEntry.java: -------------------------------------------------------------------------------- 1 | package com.binance.client.model.market; 2 | 3 | import com.binance.client.constant.BinanceApiConstants; 4 | import org.apache.commons.lang3.builder.ToStringBuilder; 5 | 6 | import java.math.BigDecimal; 7 | 8 | public class OrderBookEntry { 9 | 10 | private BigDecimal price; 11 | 12 | private BigDecimal qty; 13 | 14 | public BigDecimal getPrice() { 15 | return price; 16 | } 17 | 18 | public void setPrice(BigDecimal price) { 19 | this.price = price; 20 | } 21 | 22 | public BigDecimal getQty() { 23 | return qty; 24 | } 25 | 26 | public void setQty(BigDecimal qty) { 27 | this.qty = qty; 28 | } 29 | 30 | @Override 31 | public String toString() { 32 | return new ToStringBuilder(this, BinanceApiConstants.TO_STRING_BUILDER_STYLE).append("price", price) 33 | .append("qty", qty).toString(); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/test/java/com/binance/client/examples/trade/AddIsolatedPositionMargin.java: -------------------------------------------------------------------------------- 1 | package com.binance.client.examples.trade; 2 | 3 | import com.binance.client.RequestOptions; 4 | import com.binance.client.SyncRequestClient; 5 | import com.binance.client.examples.constants.PrivateConfig; 6 | import com.binance.client.model.enums.PositionSide; 7 | 8 | /** 9 | * @author : wangwanlu 10 | * @since : 2020/4/23, Thu 11 | **/ 12 | public class AddIsolatedPositionMargin { 13 | 14 | static int INCREASE_MARGIN_TYPE = 1; 15 | static int DECREASE_MARGIN_TYPE = 2; 16 | 17 | public static void main(String[] args) { 18 | RequestOptions options = new RequestOptions(); 19 | SyncRequestClient syncRequestClient = SyncRequestClient.create(PrivateConfig.API_KEY, PrivateConfig.SECRET_KEY, 20 | options); 21 | 22 | System.out.println(syncRequestClient.addIsolatedPositionMargin("BTCUSDT", INCREASE_MARGIN_TYPE, "100", PositionSide.BOTH)); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/com/binance/client/model/enums/TransactType.java: -------------------------------------------------------------------------------- 1 | package com.binance.client.model.enums; 2 | 3 | public enum TransactType { 4 | 5 | TRADE("trade"), 6 | ETF("etf"), 7 | TRANSACT_FEE("transact-fee"), 8 | FEE_DEDUCTION("fee-deduction"), 9 | TRANSFER("transfer"), 10 | CREDIT("credit"), 11 | LIQUIDATION("liquidation"), 12 | INTEREST("interest"), 13 | DEPOSIT("deposit"), 14 | WITHDRAW("withdraw"), 15 | WITHDRAW_FEE("withdraw-fee"), 16 | EXCHANGE("exchange"), 17 | OTHER_TYPES("other-types") 18 | 19 | ; 20 | private final String code; 21 | 22 | TransactType(String code) { 23 | this.code = code; 24 | } 25 | 26 | public String getCode() { 27 | return code; 28 | } 29 | 30 | public static TransactType find(String code) { 31 | for (TransactType transactType : TransactType.values()) { 32 | if (transactType.getCode().equals(code)) { 33 | return transactType; 34 | } 35 | } 36 | return null; 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/com/binance/client/model/enums/OrderType.java: -------------------------------------------------------------------------------- 1 | package com.binance.client.model.enums; 2 | 3 | import com.binance.client.impl.utils.EnumLookup; 4 | 5 | /** 6 | * buy-market, sell-market, buy-limit, buy-ioc, sell-ioc, 7 | * buy-limit-maker, sell-limit-maker, buy-stop-limit, sell-stop-limit. 8 | */ 9 | public enum OrderType { 10 | LIMIT("LIMIT"), 11 | MARKET("MARKET"), 12 | STOP("STOP"), 13 | STOP_MARKET("STOP_MARKET"), 14 | TAKE_PROFIT("TAKE_PROFIT"), 15 | TAKE_PROFIT_MARKET("TAKE_PROFIT_MARKET"), 16 | TRAILING_STOP_MARKET("TAKE_PROFIT_MARKET"); 17 | 18 | private final String code; 19 | 20 | OrderType(String code) { 21 | this.code = code; 22 | } 23 | 24 | @Override 25 | public String toString() { 26 | return code; 27 | } 28 | 29 | private static final EnumLookup lookup = new EnumLookup<>(OrderType.class); 30 | 31 | public static OrderType lookup(String name) { 32 | return lookup.lookup(name); 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/com/binance/client/model/enums/StopOrderOperator.java: -------------------------------------------------------------------------------- 1 | package com.binance.client.model.enums; 2 | 3 | public enum StopOrderOperator { 4 | /** 5 | * GTE,greater than and equal (>=) ,LTE less than and equal (<=) 6 | */ 7 | GTE("gte", "greater than and equal (>=)"), LTE("lte", "less than and equal (<=)"); 8 | 9 | private String operator; 10 | 11 | private String desc; 12 | 13 | StopOrderOperator(String operator, String desc) { 14 | this.operator = operator; 15 | this.desc = desc; 16 | } 17 | 18 | public String getOperator() { 19 | return operator; 20 | } 21 | 22 | public String getDesc() { 23 | return desc; 24 | } 25 | 26 | public static StopOrderOperator find(String operator) { 27 | for (StopOrderOperator op : StopOrderOperator.values()) { 28 | if (op.getOperator().equals(operator)) { 29 | return op; 30 | } 31 | } 32 | return null; 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/com/binance/client/model/enums/WithdrawState.java: -------------------------------------------------------------------------------- 1 | package com.binance.client.model.enums; 2 | 3 | import com.binance.client.impl.utils.EnumLookup; 4 | 5 | 6 | /** 7 | * withdraw, deposit. 8 | */ 9 | public enum WithdrawState { 10 | 11 | 12 | SUBMITTED("submitted"), 13 | REEXAMINE("reexamine"), 14 | CANCELED("canceled"), 15 | PASS("pass"), 16 | REJECT("reject"), 17 | PRETRANSFER("pre-transfer"), 18 | WALLETTRANSFER("wallet-transfer"), 19 | WALEETREJECT("wallet-reject"), 20 | CONFIRMED("confirmed"), 21 | CONFIRMERROR("confirm-error"), 22 | REPEALED("repealed"); 23 | 24 | 25 | private final String code; 26 | 27 | WithdrawState(String code) { 28 | this.code = code; 29 | } 30 | 31 | @Override 32 | public String toString() { 33 | return code; 34 | } 35 | 36 | private static final EnumLookup lookup = new EnumLookup<>(WithdrawState.class); 37 | 38 | public static WithdrawState lookup(String name) { 39 | return lookup.lookup(name); 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /src/test/java/com/binance/client/examples/trade/GetPositionMarginHistory.java: -------------------------------------------------------------------------------- 1 | package com.binance.client.examples.trade; 2 | 3 | import com.binance.client.RequestOptions; 4 | import com.binance.client.SyncRequestClient; 5 | import com.binance.client.examples.constants.PrivateConfig; 6 | 7 | /** 8 | * @author : wangwanlu 9 | * @since : 2020/4/23, Thu 10 | **/ 11 | public class GetPositionMarginHistory { 12 | 13 | static int INCREASE_MARGIN_TYPE = 1; 14 | static int DECREASE_MARGIN_TYPE = 2; 15 | 16 | public static void main(String[] args) { 17 | RequestOptions options = new RequestOptions(); 18 | SyncRequestClient syncRequestClient = SyncRequestClient.create(PrivateConfig.API_KEY, PrivateConfig.SECRET_KEY, 19 | options); 20 | 21 | long endTime = System.currentTimeMillis(); 22 | long startTime = endTime - (24 * 60 * 60 * 1000); 23 | int limit = 500; 24 | System.out.println(syncRequestClient.getPositionMarginHistory("BTCUSDT", INCREASE_MARGIN_TYPE, startTime, endTime, limit)); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/com/binance/client/model/user/AccountUpdate.java: -------------------------------------------------------------------------------- 1 | package com.binance.client.model.user; 2 | 3 | import com.binance.client.constant.BinanceApiConstants; 4 | import org.apache.commons.lang3.builder.ToStringBuilder; 5 | 6 | import java.util.List; 7 | 8 | public class AccountUpdate { 9 | 10 | private List balances; 11 | 12 | private List positions; 13 | 14 | public List getBalances() { 15 | return balances; 16 | } 17 | 18 | public void setBalances(List balances) { 19 | this.balances = balances; 20 | } 21 | 22 | public List getPositions() { 23 | return positions; 24 | } 25 | 26 | public void setPositions(List positions) { 27 | this.positions = positions; 28 | } 29 | 30 | @Override 31 | public String toString() { 32 | return new ToStringBuilder(this, BinanceApiConstants.TO_STRING_BUILDER_STYLE).append("balances", balances) 33 | .append("positions", positions).toString(); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/com/binance/client/RequestOptions.java: -------------------------------------------------------------------------------- 1 | package com.binance.client; 2 | 3 | import com.binance.client.constant.BinanceApiConstants; 4 | import com.binance.client.exception.BinanceApiException; 5 | import java.net.URL; 6 | 7 | /** 8 | * The configuration for the request APIs 9 | */ 10 | public class RequestOptions { 11 | 12 | private String url = BinanceApiConstants.API_BASE_URL; 13 | 14 | public RequestOptions() { 15 | } 16 | 17 | public RequestOptions(RequestOptions option) { 18 | this.url = option.url; 19 | } 20 | 21 | /** 22 | * Set the URL for request. 23 | * 24 | * @param url The URL name like "https://fapi.binance.com". 25 | */ 26 | public void setUrl(String url) { 27 | try { 28 | URL u = new URL(url); 29 | this.url = u.toString(); 30 | } catch (Exception e) { 31 | throw new BinanceApiException(BinanceApiException.INPUT_ERROR, "The URI is incorrect: " + e.getMessage()); 32 | } 33 | this.url = url; 34 | } 35 | 36 | public String getUrl() { 37 | return url; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/com/binance/client/model/ResponseResult.java: -------------------------------------------------------------------------------- 1 | package com.binance.client.model; 2 | 3 | import com.binance.client.constant.BinanceApiConstants; 4 | import org.apache.commons.lang3.builder.ToStringBuilder; 5 | 6 | /** 7 | * @author : wangwanlu 8 | * @since : 2020/3/25, Wed 9 | **/ 10 | public class ResponseResult { 11 | 12 | private int code; 13 | 14 | private String msg; 15 | 16 | public ResponseResult() { 17 | } 18 | 19 | public ResponseResult(int code, String msg) { 20 | this.code = code; 21 | this.msg = msg; 22 | } 23 | 24 | public int getCode() { 25 | return code; 26 | } 27 | 28 | public void setCode(int code) { 29 | this.code = code; 30 | } 31 | 32 | public String getMsg() { 33 | return msg; 34 | } 35 | 36 | public void setMsg(String msg) { 37 | this.msg = msg; 38 | } 39 | 40 | @Override 41 | public String toString() { 42 | return new ToStringBuilder(this, BinanceApiConstants.TO_STRING_BUILDER_STYLE).append("code", code) 43 | .append("msg", msg).toString(); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Binance Java SDK 2 | 3 | This is Binance Java SDK, This is a lightweight Java library to handle Binance futures, you can import to your Java project and use this SDK to query all market data, trading and manage your account. 4 | 5 | The SDK supports both synchronous and asynchronous RESTful API invoking, and subscribe the market data from the Websocket connection. 6 | 7 | 8 | ## Table of Contents 9 | 10 | - [Maven configuration](#Beginning) 11 | 12 | ### Maven configuration 13 | 14 | Binance Java Sdk is available on [Maven Central](http://search.maven.org/#search). You just have to follow the following steps: 15 | 16 | Install 1/2: Add this to pom.xml: 17 | 18 | ```xml 19 | 20 | com.github.yonathan95 21 | binance-java-sdk 22 | 1.2.3 23 | 24 | ``` 25 | 26 | Install 2/2: Run via command line 27 | 28 | ```xml 29 | $ mvn install 30 | ``` 31 | *The SDK is compiled by Java8* 32 | 33 | ## Creators 34 | [Yonathan Wolloch](https://github.com/yonathan95) 35 | 36 | [Uri Bek](https://github.com/urib94) 37 | 38 | [Omri Attal](https://github.com/omriattal) 39 | -------------------------------------------------------------------------------- /src/main/java/com/binance/client/model/enums/OrderSource.java: -------------------------------------------------------------------------------- 1 | package com.binance.client.model.enums; 2 | 3 | import com.binance.client.impl.utils.EnumLookup; 4 | 5 | /** 6 | * sys, web, api, app. 7 | */ 8 | public enum OrderSource { 9 | SYS("sys"), 10 | WEB("web"), 11 | API("api"), 12 | APP("app"), 13 | FLSYS("fl-sys"), 14 | FLMGT("fl-mgt"), 15 | SPOTWEB("spot-web"), 16 | SPOTAPI("spot-api"), 17 | SPOTAPP("spot-app"), 18 | MARGINAPI("margin-api"), 19 | MARGINWEB("margin-web"), 20 | MARGINAPP("margin-app"), 21 | SUPERMARGINAPI("super_margin_api"), 22 | SUPERMARGINAPP("super_margin_app"), 23 | SUPERMARGINWEB("super_margin_web"), 24 | SUPERMARGINFLSYS("super_margin_fl_sys"), 25 | SUPERMARGINFLMGT("super_margin_fl_mgt"); 26 | 27 | private final String code; 28 | 29 | OrderSource(String code) { 30 | this.code = code; 31 | } 32 | 33 | @Override 34 | public String toString() { 35 | return code; 36 | } 37 | 38 | private static final EnumLookup lookup = new EnumLookup<>(OrderSource.class); 39 | 40 | public static OrderSource lookup(String name) { 41 | return lookup.lookup(name); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/com/binance/client/exception/BinanceApiException.java: -------------------------------------------------------------------------------- 1 | package com.binance.client.exception; 2 | 3 | public class BinanceApiException extends RuntimeException { 4 | 5 | /** 6 | * 7 | */ 8 | private static final long serialVersionUID = 4360108982268949009L; 9 | public static final String RUNTIME_ERROR = "RuntimeError"; 10 | public static final String INPUT_ERROR = "InputError"; 11 | public static final String KEY_MISSING = "KeyMissing"; 12 | public static final String SYS_ERROR = "SysError"; 13 | public static final String SUBSCRIPTION_ERROR = "SubscriptionError"; 14 | public static final String ENV_ERROR = "EnvironmentError"; 15 | public static final String EXEC_ERROR = "ExecuteError"; 16 | private final String errCode; 17 | 18 | public BinanceApiException(String errType, String errMsg) { 19 | super(errMsg); 20 | this.errCode = errType; 21 | } 22 | 23 | public BinanceApiException(String errType, String errMsg, Throwable e) { 24 | super(errMsg, e); 25 | this.errCode = errType; 26 | } 27 | 28 | public String getErrType() { 29 | return this.errCode; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/com/binance/client/model/market/SymbolPrice.java: -------------------------------------------------------------------------------- 1 | package com.binance.client.model.market; 2 | 3 | import com.binance.client.constant.BinanceApiConstants; 4 | import org.apache.commons.lang3.builder.ToStringBuilder; 5 | 6 | import java.math.BigDecimal; 7 | 8 | public class SymbolPrice { 9 | 10 | private String symbol; 11 | 12 | private BigDecimal price; 13 | 14 | private Long time; 15 | 16 | public Long getTime() { 17 | return time; 18 | } 19 | 20 | public void setTime(Long time) { 21 | this.time = time; 22 | } 23 | 24 | public String getSymbol() { 25 | return symbol; 26 | } 27 | 28 | public void setSymbol(String symbol) { 29 | this.symbol = symbol; 30 | } 31 | 32 | public BigDecimal getPrice() { 33 | return price; 34 | } 35 | 36 | public void setPrice(BigDecimal price) { 37 | this.price = price; 38 | } 39 | 40 | @Override 41 | public String toString() { 42 | return new ToStringBuilder(this, BinanceApiConstants.TO_STRING_BUILDER_STYLE).append("symbol", symbol) 43 | .append("price", price).append("time", time).toString(); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/main/resources/logback.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | %d{yyyy-MM-dd HH:mm:ss} [%level] - %m%n 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | logs/%d{yyyy-MM-dd}.log 17 | 18 | 19 | 20 | 30 21 | 22 | 23 | %d{yyyy-MM-dd HH:mm:ss} [%level] - %m%n 24 | 25 | 26 | 28 | 5MB 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /src/test/java/com/binance/client/examples/trade/PostOrder.java: -------------------------------------------------------------------------------- 1 | package com.binance.client.examples.trade; 2 | 3 | import com.binance.client.RequestOptions; 4 | import com.binance.client.SyncRequestClient; 5 | 6 | import com.binance.client.examples.constants.PrivateConfig; 7 | import com.binance.client.model.enums.*; 8 | 9 | public class PostOrder { 10 | public static void main(String[] args) { 11 | RequestOptions options = new RequestOptions(); 12 | SyncRequestClient syncRequestClient = SyncRequestClient.create(PrivateConfig.API_KEY, PrivateConfig.SECRET_KEY, 13 | options); 14 | // System.out.println(syncRequestClient.postOrder("BTCUSDT", OrderSide.SELL, PositionSide.BOTH, OrderType.LIMIT, TimeInForce.GTC, 15 | // "1", "1", null, null, null, null)); 16 | 17 | // place dual position side order. 18 | // Switch between dual or both position side, call: com.binance.client.examples.trade.ChangePositionSide 19 | System.out.println(syncRequestClient.postOrder("BTCUSDT", OrderSide.SELL, PositionSide.SHORT, OrderType.LIMIT, TimeInForce.GTC, 20 | "1", "9000", null, null,null, null, null, null, null, null, NewOrderRespType.RESULT)); 21 | } 22 | } -------------------------------------------------------------------------------- /src/test/java/com/binance/client/examples/user/SubscribeUserData.java: -------------------------------------------------------------------------------- 1 | package com.binance.client.examples.user; 2 | 3 | import com.binance.client.RequestOptions; 4 | import com.binance.client.SyncRequestClient; 5 | import com.binance.client.SubscriptionClient; 6 | import com.binance.client.examples.constants.PrivateConfig; 7 | 8 | public class SubscribeUserData { 9 | 10 | public static void main(String[] args) { 11 | 12 | RequestOptions options = new RequestOptions(); 13 | SyncRequestClient syncRequestClient = SyncRequestClient.create(PrivateConfig.API_KEY, PrivateConfig.SECRET_KEY, 14 | options); 15 | 16 | // Start user data stream 17 | String listenKey = syncRequestClient.startUserDataStream(); 18 | System.out.println("listenKey: " + listenKey); 19 | 20 | // Keep user data stream 21 | syncRequestClient.keepUserDataStream(listenKey); 22 | 23 | // Close user data stream 24 | syncRequestClient.closeUserDataStream(listenKey); 25 | 26 | SubscriptionClient client = SubscriptionClient.create(); 27 | 28 | 29 | client.subscribeUserDataEvent(listenKey, ((event) -> { 30 | System.out.println(event); 31 | }), null); 32 | 33 | } 34 | 35 | } -------------------------------------------------------------------------------- /src/main/java/com/binance/client/model/market/OrderBook.java: -------------------------------------------------------------------------------- 1 | package com.binance.client.model.market; 2 | 3 | import com.binance.client.constant.BinanceApiConstants; 4 | import org.apache.commons.lang3.builder.ToStringBuilder; 5 | 6 | import java.util.List; 7 | 8 | public class OrderBook { 9 | 10 | private Long lastUpdateId; 11 | 12 | private List bids; 13 | 14 | private List asks; 15 | 16 | public Long getLastUpdateId() { 17 | return lastUpdateId; 18 | } 19 | 20 | public void setLastUpdateId(Long lastUpdateId) { 21 | this.lastUpdateId = lastUpdateId; 22 | } 23 | 24 | public List getBids() { 25 | return bids; 26 | } 27 | 28 | public void setBids(List bids) { 29 | this.bids = bids; 30 | } 31 | 32 | public List getAsks() { 33 | return asks; 34 | } 35 | 36 | public void setAsks(List asks) { 37 | this.asks = asks; 38 | } 39 | 40 | @Override 41 | public String toString() { 42 | return new ToStringBuilder(this, BinanceApiConstants.TO_STRING_BUILDER_STYLE) 43 | .append("lastUpdateId", lastUpdateId).append("bids", bids).append("asks", asks).toString(); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/com/binance/client/model/market/OpenInterest.java: -------------------------------------------------------------------------------- 1 | package com.binance.client.model.market; 2 | 3 | import com.binance.client.constant.BinanceApiConstants; 4 | import org.apache.commons.lang3.builder.ToStringBuilder; 5 | 6 | import java.math.BigDecimal; 7 | 8 | public class OpenInterest { 9 | 10 | private BigDecimal openInterest; 11 | 12 | private String symbol; 13 | 14 | private Long timestamp; 15 | 16 | public String getSymbol() { 17 | return symbol; 18 | } 19 | 20 | public BigDecimal getOpenInterest() { 21 | return openInterest; 22 | } 23 | 24 | public void setOpenInterest(BigDecimal openInterest) { 25 | this.openInterest = openInterest; 26 | } 27 | 28 | public void setSymbol(String symbol) { 29 | this.symbol = symbol; 30 | } 31 | 32 | public Long getTimestamp() { 33 | return timestamp; 34 | } 35 | 36 | public void setTimestamp(Long timestamp) { 37 | this.timestamp = timestamp; 38 | } 39 | 40 | @Override 41 | public String toString() { 42 | return new ToStringBuilder(this, BinanceApiConstants.TO_STRING_BUILDER_STYLE).append("openInterest", openInterest) 43 | .append("symbol", symbol).append("timestamp", timestamp).toString(); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/com/binance/client/model/market/FundingRate.java: -------------------------------------------------------------------------------- 1 | package com.binance.client.model.market; 2 | 3 | import com.binance.client.constant.BinanceApiConstants; 4 | import org.apache.commons.lang3.builder.ToStringBuilder; 5 | 6 | import java.math.BigDecimal; 7 | 8 | public class FundingRate { 9 | 10 | private String symbol; 11 | 12 | private BigDecimal fundingRate; 13 | 14 | private Long fundingTime; 15 | 16 | public String getSymbol() { 17 | return symbol; 18 | } 19 | 20 | public void setSymbol(String symbol) { 21 | this.symbol = symbol; 22 | } 23 | 24 | public BigDecimal getFundingRate() { 25 | return fundingRate; 26 | } 27 | 28 | public void setFundingRate(BigDecimal fundingRate) { 29 | this.fundingRate = fundingRate; 30 | } 31 | 32 | public Long getFundingTime() { 33 | return fundingTime; 34 | } 35 | 36 | public void setFundingTime(Long fundingTime) { 37 | this.fundingTime = fundingTime; 38 | } 39 | 40 | @Override 41 | public String toString() { 42 | return new ToStringBuilder(this, BinanceApiConstants.TO_STRING_BUILDER_STYLE).append("symbol", symbol) 43 | .append("fundingRate", fundingRate).append("fundingTime", fundingTime).toString(); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/com/binance/client/model/trade/Leverage.java: -------------------------------------------------------------------------------- 1 | package com.binance.client.model.trade; 2 | 3 | import com.binance.client.constant.BinanceApiConstants; 4 | import org.apache.commons.lang3.builder.ToStringBuilder; 5 | 6 | import java.math.BigDecimal; 7 | 8 | public class Leverage { 9 | 10 | private BigDecimal leverage; 11 | 12 | private Double maxNotionalValue; 13 | 14 | private String symbol; 15 | 16 | public BigDecimal getLeverage() { 17 | return leverage; 18 | } 19 | 20 | public void setLeverage(BigDecimal leverage) { 21 | this.leverage = leverage; 22 | } 23 | 24 | public Double getMaxNotionalValue() { 25 | return maxNotionalValue; 26 | } 27 | 28 | public void setMaxNotionalValue(Double maxNotionalValue) { 29 | this.maxNotionalValue = maxNotionalValue; 30 | } 31 | 32 | public String getSymbol() { 33 | return symbol; 34 | } 35 | 36 | public void setSymbol(String symbol) { 37 | this.symbol = symbol; 38 | } 39 | 40 | @Override 41 | public String toString() { 42 | return new ToStringBuilder(this, BinanceApiConstants.TO_STRING_BUILDER_STYLE).append("leverage", leverage) 43 | .append("maxNotionalValue", maxNotionalValue).append("symbol", symbol).toString(); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/test/java/com/binance/client/examples/trade/BatchCancelOrders.java: -------------------------------------------------------------------------------- 1 | package com.binance.client.examples.trade; 2 | 3 | import com.alibaba.fastjson.JSONArray; 4 | import com.binance.client.RequestOptions; 5 | import com.binance.client.SyncRequestClient; 6 | import com.binance.client.examples.constants.PrivateConfig; 7 | 8 | 9 | /** 10 | * @author : wangwanlu 11 | * @since : 2020/4/7, Tue 12 | **/ 13 | public class BatchCancelOrders { 14 | 15 | public static void main(String[] args) { 16 | RequestOptions options = new RequestOptions(); 17 | SyncRequestClient syncRequestClient = SyncRequestClient.create(PrivateConfig.API_KEY, PrivateConfig.SECRET_KEY, 18 | options); 19 | 20 | // batch cancel by order ids 21 | JSONArray orderIds = new JSONArray(); 22 | orderIds.add(180L); 23 | orderIds.add(181L); 24 | System.out.println(syncRequestClient.batchCancelOrders("BTCUSDT", orderIds.toJSONString(), null)); 25 | 26 | // batch cancel by client order ids 27 | // JSONArray origClientOrderIds = new JSONArray(); 28 | // origClientOrderIds.add("cli_order_001"); 29 | // origClientOrderIds.add("cli_order_002"); 30 | // System.out.println(syncRequestClient.batchCancelOrders("BTCUSDT", null, origClientOrderIds.toJSONString())); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/com/binance/client/model/market/ExchangeFilter.java: -------------------------------------------------------------------------------- 1 | package com.binance.client.model.market; 2 | 3 | import com.binance.client.constant.BinanceApiConstants; 4 | import org.apache.commons.lang3.builder.ToStringBuilder; 5 | 6 | public class ExchangeFilter { 7 | 8 | private String filterType; 9 | 10 | private Long maxNumOrders; 11 | 12 | private Long maxNumAlgoOrders; 13 | 14 | public String getFilterType() { 15 | return filterType; 16 | } 17 | 18 | public void setFilterType(String filterType) { 19 | this.filterType = filterType; 20 | } 21 | 22 | public Long getMaxNumOrders() { 23 | return maxNumOrders; 24 | } 25 | 26 | public void setMaxNumOrders(Long maxNumOrders) { 27 | this.maxNumOrders = maxNumOrders; 28 | } 29 | 30 | public Long getMaxNumAlgoOrders() { 31 | return maxNumAlgoOrders; 32 | } 33 | 34 | public void setMaxNumAlgoOrders(Long maxNumAlgoOrders) { 35 | this.maxNumAlgoOrders = maxNumAlgoOrders; 36 | } 37 | 38 | @Override 39 | public String toString() { 40 | return new ToStringBuilder(this, BinanceApiConstants.TO_STRING_BUILDER_STYLE).append("filterType", filterType) 41 | .append("maxNumOrders", maxNumOrders).append("maxNumAlgoOrders", maxNumAlgoOrders).toString(); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/com/binance/client/model/user/BalanceUpdate.java: -------------------------------------------------------------------------------- 1 | package com.binance.client.model.user; 2 | 3 | import com.binance.client.constant.BinanceApiConstants; 4 | import org.apache.commons.lang3.builder.ToStringBuilder; 5 | 6 | import java.math.BigDecimal; 7 | 8 | public class BalanceUpdate { 9 | 10 | private String asset; 11 | 12 | private BigDecimal walletBalance; 13 | 14 | private BigDecimal crossWalletBalance; 15 | 16 | public String getAsset() { 17 | return asset; 18 | } 19 | 20 | public void setAsset(String asset) { 21 | this.asset = asset; 22 | } 23 | 24 | public BigDecimal getWalletBalance() { 25 | return walletBalance; 26 | } 27 | 28 | public void setWalletBalance(BigDecimal walletBalance) { 29 | this.walletBalance = walletBalance; 30 | } 31 | 32 | public BigDecimal getCrossWalletBalance() { 33 | return crossWalletBalance; 34 | } 35 | 36 | public void setCrossWalletBalance(BigDecimal crossWalletBalance) { 37 | this.crossWalletBalance = crossWalletBalance; 38 | } 39 | 40 | @Override 41 | public String toString() { 42 | return new ToStringBuilder(this, BinanceApiConstants.TO_STRING_BUILDER_STYLE).append("asset", asset) 43 | .append("walletBalance", walletBalance).append("crossWalletBalance", crossWalletBalance).toString(); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/com/binance/client/impl/utils/InternalUtils.java: -------------------------------------------------------------------------------- 1 | package com.binance.client.impl.utils; 2 | 3 | import com.binance.client.exception.BinanceApiException; 4 | import java.io.ByteArrayInputStream; 5 | import java.io.ByteArrayOutputStream; 6 | import java.io.IOException; 7 | import java.io.InputStream; 8 | import java.io.OutputStream; 9 | import java.util.zip.GZIPInputStream; 10 | 11 | public abstract class InternalUtils { 12 | 13 | public static byte[] decode(byte[] data) throws IOException { 14 | ByteArrayInputStream bais = new ByteArrayInputStream(data); 15 | ByteArrayOutputStream baos = new ByteArrayOutputStream(); 16 | decompress(bais, baos); 17 | baos.flush(); 18 | baos.close(); 19 | bais.close(); 20 | return baos.toByteArray(); 21 | } 22 | 23 | private static void decompress(InputStream is, OutputStream os) throws IOException { 24 | GZIPInputStream gis = new GZIPInputStream(is); 25 | int count; 26 | byte[] data = new byte[1024]; 27 | while ((count = gis.read(data, 0, 1024)) != -1) { 28 | os.write(data, 0, count); 29 | } 30 | gis.close(); 31 | } 32 | 33 | public static void await(long n) throws BinanceApiException { 34 | try { 35 | Thread.sleep(n); 36 | } catch (InterruptedException e) { 37 | throw new BinanceApiException(BinanceApiException.SYS_ERROR, "Error when sleep", e); 38 | } 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/com/binance/client/model/market/TakerLongShortStat.java: -------------------------------------------------------------------------------- 1 | package com.binance.client.model.market; 2 | 3 | import java.math.BigDecimal; 4 | 5 | public class TakerLongShortStat { 6 | 7 | private BigDecimal buySellRatio; 8 | private BigDecimal sellVol; 9 | private BigDecimal buyVol; 10 | private Long timestamp; 11 | 12 | public BigDecimal getBuySellRatio() { 13 | return buySellRatio; 14 | } 15 | 16 | public void setBuySellRatio(BigDecimal buySellRatio) { 17 | this.buySellRatio = buySellRatio; 18 | } 19 | 20 | public BigDecimal getSellVol() { 21 | return sellVol; 22 | } 23 | 24 | public void setSellVol(BigDecimal sellVol) { 25 | this.sellVol = sellVol; 26 | } 27 | 28 | public BigDecimal getBuyVol() { 29 | return buyVol; 30 | } 31 | 32 | public void setBuyVol(BigDecimal buyVol) { 33 | this.buyVol = buyVol; 34 | } 35 | 36 | public Long getTimestamp() { 37 | return timestamp; 38 | } 39 | 40 | public void setTimestamp(Long timestamp) { 41 | this.timestamp = timestamp; 42 | } 43 | 44 | @Override 45 | public String toString() { 46 | return "TakerLongShortStat{" + 47 | "buySellRatio=" + buySellRatio + 48 | ", sellVol=" + sellVol + 49 | ", buyVol=" + buyVol + 50 | ", timestamp=" + timestamp + 51 | '}'; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/com/binance/client/model/enums/AccountChangeType.java: -------------------------------------------------------------------------------- 1 | package com.binance.client.model.enums; 2 | 3 | import com.binance.client.impl.utils.EnumLookup; 4 | 5 | /** 6 | * The event that Asset Change Notification Related ,for example : create order (order.place) , 7 | * commit order (order.match),order refunds(order.refund),order canceled (order.cancel) ,card 8 | * deducts transaction fee (order.fee-refund),lever account transfer(margin.transfer),loan 9 | * principal(margin.loan),loan interest (margin.interest),return loan interest(margin.repay),other 10 | * asset change(other) 11 | */ 12 | public enum AccountChangeType { 13 | 14 | 15 | NEWORDER("order.place"), 16 | 17 | TRADE("order.match"), 18 | 19 | REFUND("order.refund"), 20 | 21 | CANCELORDER("order.cancel"), 22 | 23 | FEE("order.fee-refund"), 24 | 25 | TRANSFER("margin.transfer"), 26 | 27 | LOAN("margin.loan"), 28 | 29 | INTEREST("margin.interest"), 30 | 31 | REPAY("margin.repay"), 32 | 33 | OTHER("other"), 34 | 35 | INVALID("INVALID"); 36 | 37 | private final String code; 38 | 39 | AccountChangeType(String code) { 40 | this.code = code; 41 | } 42 | 43 | @Override 44 | public String toString() { 45 | return code; 46 | } 47 | 48 | private static final EnumLookup lookup = new EnumLookup<>( 49 | AccountChangeType.class); 50 | 51 | public static AccountChangeType lookup(String name) { 52 | return lookup.lookup(name); 53 | } 54 | 55 | 56 | } 57 | -------------------------------------------------------------------------------- /src/main/java/com/binance/client/model/market/RateLimit.java: -------------------------------------------------------------------------------- 1 | package com.binance.client.model.market; 2 | 3 | import com.binance.client.constant.BinanceApiConstants; 4 | import org.apache.commons.lang3.builder.ToStringBuilder; 5 | 6 | public class RateLimit { 7 | 8 | private String rateLimitType; 9 | 10 | private String interval; 11 | 12 | private Long intervalNum; 13 | 14 | private Long limit; 15 | 16 | public String getRateLimitType() { 17 | return rateLimitType; 18 | } 19 | 20 | public void setRateLimitType(String rateLimitType) { 21 | this.rateLimitType = rateLimitType; 22 | } 23 | 24 | public String getInterval() { 25 | return interval; 26 | } 27 | 28 | public void setInterval(String interval) { 29 | this.interval = interval; 30 | } 31 | 32 | public Long getIntervalNum() { 33 | return intervalNum; 34 | } 35 | 36 | public void setIntervalNum(Long intervalNum) { 37 | this.intervalNum = intervalNum; 38 | } 39 | 40 | public Long getLimit() { 41 | return limit; 42 | } 43 | 44 | public void setLimit(Long limit) { 45 | this.limit = limit; 46 | } 47 | 48 | @Override 49 | public String toString() { 50 | return new ToStringBuilder(this, BinanceApiConstants.TO_STRING_BUILDER_STYLE) 51 | .append("rateLimitType", rateLimitType).append("interval", interval).append("intervalNum", intervalNum) 52 | .append("limit", limit).toString(); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/test/java/com/binance/client/examples/trade/BatchPlaceOrders.java: -------------------------------------------------------------------------------- 1 | package com.binance.client.examples.trade; 2 | 3 | import com.binance.client.RequestOptions; 4 | import com.binance.client.SyncRequestClient; 5 | import com.binance.client.examples.constants.PrivateConfig; 6 | 7 | /** 8 | * @author : wangwanlu 9 | * @since : 2020/3/26, Thu 10 | **/ 11 | public class BatchPlaceOrders { 12 | public static void main(String[] args) { 13 | RequestOptions options = new RequestOptions(); 14 | SyncRequestClient syncRequestClient = SyncRequestClient.create(PrivateConfig.API_KEY, PrivateConfig.SECRET_KEY, 15 | options); 16 | 17 | // place dual position side orders. 18 | // Switch between dual or both position side, call: com.binance.client.examples.trade.ChangePositionSide 19 | System.out.println(syncRequestClient.postBatchOrders( 20 | "[{\"symbol\": \"BTCUSDT\",\"side\":\"BUY\",\"positionSide\":\"LONG\",\"type\":\"LIMIT\",\"newClientOrderId\":\"wanlu_dev_0324\",\"quantity\":\"1\",\"price\": \"8000\",\"timeInForce\":\"GTC\"},\n" + 21 | "{\"symbol\": \"BTCUSDT\",\"side\":\"BUY\",\"positionSide\":\"SHORT\",\"type\":\"LIMIT\",\"newClientOrderId\":\"wanlu_dev_0325\",\"quantity\":\"1\",\"price\": \"8000\",\"timeInForce\":\"GTC\"},\n" + 22 | "{\"symbol\": \"BTCUSDT\",\"side\":\"BUY\",\"type\":\"LIMIT\",\"newClientOrderId\":\"wanlu_dev_0320\",\"quantity\":\"1\",\"price\": \"8000\",\"timeInForce\":\"GTC\"}]" 23 | 24 | )); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/com/binance/client/model/market/OpenInterestStat.java: -------------------------------------------------------------------------------- 1 | package com.binance.client.model.market; 2 | 3 | import java.math.BigDecimal; 4 | 5 | public class OpenInterestStat { 6 | 7 | private String symbol; 8 | private BigDecimal sumOpenInterest; 9 | private BigDecimal sumOpenInterestValue; 10 | private Long timestamp; 11 | 12 | public String getSymbol() { 13 | return symbol; 14 | } 15 | 16 | public void setSymbol(String symbol) { 17 | this.symbol = symbol; 18 | } 19 | 20 | public BigDecimal getSumOpenInterest() { 21 | return sumOpenInterest; 22 | } 23 | 24 | public void setSumOpenInterest(BigDecimal sumOpenInterest) { 25 | this.sumOpenInterest = sumOpenInterest; 26 | } 27 | 28 | public BigDecimal getSumOpenInterestValue() { 29 | return sumOpenInterestValue; 30 | } 31 | 32 | public void setSumOpenInterestValue(BigDecimal sumOpenInterestValue) { 33 | this.sumOpenInterestValue = sumOpenInterestValue; 34 | } 35 | 36 | public Long getTimestamp() { 37 | return timestamp; 38 | } 39 | 40 | public void setTimestamp(Long timestamp) { 41 | this.timestamp = timestamp; 42 | } 43 | 44 | @Override 45 | public String toString() { 46 | return "OpenInterestStat{" + 47 | "symbol='" + symbol + '\'' + 48 | ", sumOpenInterest=" + sumOpenInterest + 49 | ", sumOpenInterestValue=" + sumOpenInterestValue + 50 | ", timestamp=" + timestamp + 51 | '}'; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/com/binance/client/impl/BinanceApiInternalFactory.java: -------------------------------------------------------------------------------- 1 | package com.binance.client.impl; 2 | 3 | import com.binance.client.RequestOptions; 4 | import com.binance.client.SubscriptionClient; 5 | import com.binance.client.SubscriptionOptions; 6 | import com.binance.client.SyncRequestClient; 7 | import java.net.URI; 8 | 9 | public final class BinanceApiInternalFactory { 10 | 11 | private static final BinanceApiInternalFactory instance = new BinanceApiInternalFactory(); 12 | 13 | public static BinanceApiInternalFactory getInstance() { 14 | return instance; 15 | } 16 | 17 | private BinanceApiInternalFactory() { 18 | } 19 | 20 | public SyncRequestClient createSyncRequestClient(String apiKey, String secretKey, RequestOptions options) { 21 | RequestOptions requestOptions = new RequestOptions(options); 22 | RestApiRequestImpl requestImpl = new RestApiRequestImpl(apiKey, secretKey, requestOptions); 23 | return new SyncRequestImpl(requestImpl); 24 | } 25 | 26 | public SubscriptionClient createSubscriptionClient(SubscriptionOptions options) { 27 | SubscriptionOptions subscriptionOptions = new SubscriptionOptions(options); 28 | RequestOptions requestOptions = new RequestOptions(); 29 | try { 30 | String host = new URI(options.getUri()).getHost(); 31 | requestOptions.setUrl("https://" + host); 32 | } catch (Exception e) { 33 | 34 | } 35 | SubscriptionClient webSocketStreamClient = new WebSocketStreamClientImpl(subscriptionOptions); 36 | return webSocketStreamClient; 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/com/binance/client/constant/BinanceApiConstants.java: -------------------------------------------------------------------------------- 1 | package com.binance.client.constant; 2 | 3 | import org.apache.commons.lang3.builder.ToStringStyle; 4 | 5 | /** 6 | * Constants used throughout Binance's API. 7 | */ 8 | public class BinanceApiConstants { 9 | 10 | /** 11 | * REST API base URL. 12 | */ 13 | public static final String API_BASE_URL = "https://fapi.binance.com"; 14 | 15 | /** 16 | * Streaming API base URL. 17 | */ 18 | public static final String WS_API_BASE_URL = "wss://fstream.binance.com/ws"; 19 | 20 | /** 21 | * HTTP Header to be used for API-KEY authentication. 22 | */ 23 | public static final String API_KEY_HEADER = "X-MBX-APIKEY"; 24 | 25 | /** 26 | * Decorator to indicate that an endpoint requires an API key. 27 | */ 28 | public static final String ENDPOINT_SECURITY_TYPE_APIKEY = "APIKEY"; 29 | public static final String ENDPOINT_SECURITY_TYPE_APIKEY_HEADER = ENDPOINT_SECURITY_TYPE_APIKEY + ": #"; 30 | 31 | /** 32 | * Decorator to indicate that an endpoint requires a signature. 33 | */ 34 | public static final String ENDPOINT_SECURITY_TYPE_SIGNED = "SIGNED"; 35 | public static final String ENDPOINT_SECURITY_TYPE_SIGNED_HEADER = ENDPOINT_SECURITY_TYPE_SIGNED + ": #"; 36 | 37 | /** 38 | * Default receiving window. 39 | */ 40 | public static final long DEFAULT_RECEIVING_WINDOW = 80_000L; 41 | 42 | /** 43 | * Default ToStringStyle used by toString methods. Override this to change the 44 | * output format of the overridden toString methods. - Example 45 | * ToStringStyle.JSON_STYLE 46 | */ 47 | public static ToStringStyle TO_STRING_BUILDER_STYLE = ToStringStyle.SHORT_PREFIX_STYLE; 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/com/binance/client/model/market/CommonLongShortRatio.java: -------------------------------------------------------------------------------- 1 | package com.binance.client.model.market; 2 | 3 | import java.math.BigDecimal; 4 | 5 | public class CommonLongShortRatio { 6 | 7 | private String symbol; 8 | private BigDecimal longAccount; 9 | private BigDecimal longShortRatio; 10 | private BigDecimal shortAccount; 11 | private Long timestamp; 12 | 13 | public String getSymbol() { 14 | return symbol; 15 | } 16 | 17 | public void setSymbol(String symbol) { 18 | this.symbol = symbol; 19 | } 20 | 21 | public BigDecimal getLongAccount() { 22 | return longAccount; 23 | } 24 | 25 | public void setLongAccount(BigDecimal longAccount) { 26 | this.longAccount = longAccount; 27 | } 28 | 29 | public BigDecimal getLongShortRatio() { 30 | return longShortRatio; 31 | } 32 | 33 | public void setLongShortRatio(BigDecimal longShortRatio) { 34 | this.longShortRatio = longShortRatio; 35 | } 36 | 37 | public BigDecimal getShortAccount() { 38 | return shortAccount; 39 | } 40 | 41 | public void setShortAccount(BigDecimal shortAccount) { 42 | this.shortAccount = shortAccount; 43 | } 44 | 45 | public Long getTimestamp() { 46 | return timestamp; 47 | } 48 | 49 | public void setTimestamp(Long timestamp) { 50 | this.timestamp = timestamp; 51 | } 52 | 53 | @Override 54 | public String toString() { 55 | return "CommonLongShortRatio{" + 56 | "symbol='" + symbol + '\'' + 57 | ", longAccount=" + longAccount + 58 | ", longShortRatio=" + longShortRatio + 59 | ", shortAccount=" + shortAccount + 60 | ", timestamp=" + timestamp + 61 | '}'; 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/main/java/com/binance/client/model/market/Trade.java: -------------------------------------------------------------------------------- 1 | package com.binance.client.model.market; 2 | 3 | import com.binance.client.constant.BinanceApiConstants; 4 | import org.apache.commons.lang3.builder.ToStringBuilder; 5 | 6 | import java.math.BigDecimal; 7 | 8 | public class Trade { 9 | 10 | private Long id; 11 | 12 | private BigDecimal price; 13 | 14 | private BigDecimal qty; 15 | 16 | private BigDecimal quoteQty; 17 | 18 | private Long time; 19 | 20 | private Boolean isBuyerMaker; 21 | 22 | public Long getId() { 23 | return id; 24 | } 25 | 26 | public void setId(Long id) { 27 | this.id = id; 28 | } 29 | 30 | public BigDecimal getPrice() { 31 | return price; 32 | } 33 | 34 | public void setPrice(BigDecimal price) { 35 | this.price = price; 36 | } 37 | 38 | public BigDecimal getQty() { 39 | return qty; 40 | } 41 | 42 | public void setQty(BigDecimal qty) { 43 | this.qty = qty; 44 | } 45 | 46 | public BigDecimal getQuoteQty() { 47 | return quoteQty; 48 | } 49 | 50 | public void setQuoteQty(BigDecimal quoteQty) { 51 | this.quoteQty = quoteQty; 52 | } 53 | 54 | public Long getTime() { 55 | return time; 56 | } 57 | 58 | public void setTime(Long time) { 59 | this.time = time; 60 | } 61 | 62 | public Boolean getIsBuyerMaker() { 63 | return isBuyerMaker; 64 | } 65 | 66 | public void setIsBuyerMaker(Boolean isBuyerMaker) { 67 | this.isBuyerMaker = isBuyerMaker; 68 | } 69 | 70 | @Override 71 | public String toString() { 72 | return new ToStringBuilder(this, BinanceApiConstants.TO_STRING_BUILDER_STYLE).append("id", id) 73 | .append("price", price).append("qty", qty).append("quoteQty", quoteQty).append("time", time) 74 | .append("isBuyerMaker", isBuyerMaker).toString(); 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /src/main/java/com/binance/client/model/trade/WalletDeltaLog.java: -------------------------------------------------------------------------------- 1 | package com.binance.client.model.trade; 2 | 3 | import com.binance.client.constant.BinanceApiConstants; 4 | import org.apache.commons.lang3.builder.ToStringBuilder; 5 | 6 | /** 7 | * @author : wangwanlu 8 | * @since : 2020/4/24, Fri 9 | **/ 10 | public class WalletDeltaLog { 11 | 12 | private String symbol; 13 | private int type; 14 | private String amount; 15 | private String asset; 16 | private Long time; 17 | private String positionSide; 18 | 19 | public String getSymbol() { 20 | return symbol; 21 | } 22 | 23 | public void setSymbol(String symbol) { 24 | this.symbol = symbol; 25 | } 26 | 27 | public int getType() { 28 | return type; 29 | } 30 | 31 | public void setType(int type) { 32 | this.type = type; 33 | } 34 | 35 | public String getAmount() { 36 | return amount; 37 | } 38 | 39 | public void setAmount(String amount) { 40 | this.amount = amount; 41 | } 42 | 43 | public String getAsset() { 44 | return asset; 45 | } 46 | 47 | public void setAsset(String asset) { 48 | this.asset = asset; 49 | } 50 | 51 | public Long getTime() { 52 | return time; 53 | } 54 | 55 | public void setTime(Long time) { 56 | this.time = time; 57 | } 58 | 59 | public String getPositionSide() { 60 | return positionSide; 61 | } 62 | 63 | public void setPositionSide(String positionSide) { 64 | this.positionSide = positionSide; 65 | } 66 | 67 | @Override 68 | public String toString() { 69 | return new ToStringBuilder(this, BinanceApiConstants.TO_STRING_BUILDER_STYLE) 70 | .append("symbol", symbol).append("type", type).append("amount", amount) 71 | .append("asset", asset).append("time", time) 72 | .append("positionSide", positionSide).toString(); 73 | } 74 | } -------------------------------------------------------------------------------- /src/main/java/com/binance/client/model/market/ExchangeInformation.java: -------------------------------------------------------------------------------- 1 | package com.binance.client.model.market; 2 | 3 | import com.binance.client.constant.BinanceApiConstants; 4 | import org.apache.commons.lang3.builder.ToStringBuilder; 5 | 6 | import java.util.List; 7 | 8 | public class ExchangeInformation { 9 | 10 | private String timezone; 11 | 12 | private Long serverTime; 13 | 14 | private List rateLimits; 15 | 16 | private List exchangeFilters; 17 | 18 | private List symbols; 19 | 20 | public String getTimezone() { 21 | return timezone; 22 | } 23 | 24 | public void setTimezone(String timezone) { 25 | this.timezone = timezone; 26 | } 27 | 28 | public Long getServerTime() { 29 | return serverTime; 30 | } 31 | 32 | public void setServerTime(Long serverTime) { 33 | this.serverTime = serverTime; 34 | } 35 | 36 | public List getRateLimits() { 37 | return rateLimits; 38 | } 39 | 40 | public void setRateLimits(List rateLimits) { 41 | this.rateLimits = rateLimits; 42 | } 43 | 44 | public List getExchangeFilters() { 45 | return exchangeFilters; 46 | } 47 | 48 | public void setExchangeFilters(List exchangeFilters) { 49 | this.exchangeFilters = exchangeFilters; 50 | } 51 | 52 | public List getSymbols() { 53 | return symbols; 54 | } 55 | 56 | public void setSymbols(List symbols) { 57 | this.symbols = symbols; 58 | } 59 | 60 | @Override 61 | public String toString() { 62 | return new ToStringBuilder(this, BinanceApiConstants.TO_STRING_BUILDER_STYLE).append("timezone", timezone) 63 | .append("serverTime", serverTime).append("rateLimits", rateLimits) 64 | .append("exchangeFilters", exchangeFilters).append("symbols", symbols).toString(); 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /src/main/java/com/binance/client/model/market/SymbolOrderBook.java: -------------------------------------------------------------------------------- 1 | package com.binance.client.model.market; 2 | 3 | import com.binance.client.constant.BinanceApiConstants; 4 | import org.apache.commons.lang3.builder.ToStringBuilder; 5 | 6 | import java.math.BigDecimal; 7 | 8 | public class SymbolOrderBook { 9 | 10 | private String symbol; 11 | 12 | private BigDecimal bidPrice; 13 | 14 | private BigDecimal bidQty; 15 | 16 | private BigDecimal askPrice; 17 | 18 | private BigDecimal askQty; 19 | 20 | private Long time; 21 | 22 | public Long getTime() { 23 | return time; 24 | } 25 | 26 | public void setTime(Long time) { 27 | this.time = time; 28 | } 29 | 30 | public String getSymbol() { 31 | return symbol; 32 | } 33 | 34 | public void setSymbol(String symbol) { 35 | this.symbol = symbol; 36 | } 37 | 38 | public BigDecimal getBidPrice() { 39 | return bidPrice; 40 | } 41 | 42 | public void setBidPrice(BigDecimal bidPrice) { 43 | this.bidPrice = bidPrice; 44 | } 45 | 46 | public BigDecimal getBidQty() { 47 | return bidQty; 48 | } 49 | 50 | public void setBidQty(BigDecimal bidQty) { 51 | this.bidQty = bidQty; 52 | } 53 | 54 | public BigDecimal getAskPrice() { 55 | return askPrice; 56 | } 57 | 58 | public void setAskPrice(BigDecimal askPrice) { 59 | this.askPrice = askPrice; 60 | } 61 | 62 | public BigDecimal getAskQty() { 63 | return askQty; 64 | } 65 | 66 | public void setAskQty(BigDecimal askQty) { 67 | this.askQty = askQty; 68 | } 69 | 70 | @Override 71 | public String toString() { 72 | return new ToStringBuilder(this, BinanceApiConstants.TO_STRING_BUILDER_STYLE).append("symbol", symbol) 73 | .append("bidPrice", bidPrice).append("bidQty", bidQty).append("askPrice", askPrice) 74 | .append("askQty", askQty).append("time", time).toString(); 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /src/main/java/com/binance/client/model/market/AggregateTrade.java: -------------------------------------------------------------------------------- 1 | package com.binance.client.model.market; 2 | 3 | import com.binance.client.constant.BinanceApiConstants; 4 | import org.apache.commons.lang3.builder.ToStringBuilder; 5 | 6 | import java.math.BigDecimal; 7 | 8 | public class AggregateTrade { 9 | 10 | private Long id; 11 | 12 | private BigDecimal price; 13 | 14 | private BigDecimal qty; 15 | 16 | private Long firstId; 17 | 18 | private Long lastId; 19 | 20 | private Long time; 21 | 22 | private Boolean isBuyerMaker; 23 | 24 | public Long getId() { 25 | return id; 26 | } 27 | 28 | public void setId(Long id) { 29 | this.id = id; 30 | } 31 | 32 | public BigDecimal getPrice() { 33 | return price; 34 | } 35 | 36 | public void setPrice(BigDecimal price) { 37 | this.price = price; 38 | } 39 | 40 | public BigDecimal getQty() { 41 | return qty; 42 | } 43 | 44 | public void setQty(BigDecimal qty) { 45 | this.qty = qty; 46 | } 47 | 48 | public Long getFirstId() { 49 | return firstId; 50 | } 51 | 52 | public void setFirstId(Long firstId) { 53 | this.firstId = firstId; 54 | } 55 | 56 | public Long getLastId() { 57 | return lastId; 58 | } 59 | 60 | public void setLastId(Long lastId) { 61 | this.lastId = lastId; 62 | } 63 | 64 | public Long getTime() { 65 | return time; 66 | } 67 | 68 | public void setTime(Long time) { 69 | this.time = time; 70 | } 71 | 72 | public Boolean getIsBuyerMaker() { 73 | return isBuyerMaker; 74 | } 75 | 76 | public void setIsBuyerMaker(Boolean isBuyerMaker) { 77 | this.isBuyerMaker = isBuyerMaker; 78 | } 79 | 80 | @Override 81 | public String toString() { 82 | return new ToStringBuilder(this, BinanceApiConstants.TO_STRING_BUILDER_STYLE).append("id", id) 83 | .append("price", price).append("qty", qty).append("firstId", firstId).append("lastId", lastId) 84 | .append("time", time).append("isBuyerMaker", isBuyerMaker).toString(); 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /src/main/java/com/binance/client/impl/ApiSignature.java: -------------------------------------------------------------------------------- 1 | package com.binance.client.impl; 2 | 3 | import com.binance.client.exception.BinanceApiException; 4 | import com.binance.client.constant.BinanceApiConstants; 5 | import com.binance.client.impl.utils.UrlParamsBuilder; 6 | import java.security.InvalidKeyException; 7 | import java.security.NoSuchAlgorithmException; 8 | import javax.crypto.Mac; 9 | import javax.crypto.spec.SecretKeySpec; 10 | import org.apache.commons.codec.binary.Hex; 11 | 12 | class ApiSignature { 13 | 14 | static final String op = "op"; 15 | static final String opValue = "auth"; 16 | private static final String signatureMethodValue = "HmacSHA256"; 17 | public static final String signatureVersionValue = "2"; 18 | 19 | void createSignature(String accessKey, String secretKey, UrlParamsBuilder builder) { 20 | 21 | if (accessKey == null || "".equals(accessKey) || secretKey == null || "".equals(secretKey)) { 22 | throw new BinanceApiException(BinanceApiException.KEY_MISSING, "API key and secret key are required"); 23 | } 24 | 25 | builder.putToUrl("recvWindow", Long.toString(BinanceApiConstants.DEFAULT_RECEIVING_WINDOW)) 26 | .putToUrl("timestamp", Long.toString(System.currentTimeMillis())); 27 | 28 | Mac hmacSha256; 29 | try { 30 | hmacSha256 = Mac.getInstance(signatureMethodValue); 31 | SecretKeySpec secKey = new SecretKeySpec(secretKey.getBytes(), signatureMethodValue); 32 | hmacSha256.init(secKey); 33 | } catch (NoSuchAlgorithmException e) { 34 | throw new BinanceApiException(BinanceApiException.RUNTIME_ERROR, 35 | "[Signature] No such algorithm: " + e.getMessage()); 36 | } catch (InvalidKeyException e) { 37 | throw new BinanceApiException(BinanceApiException.RUNTIME_ERROR, 38 | "[Signature] Invalid key: " + e.getMessage()); 39 | } 40 | String payload = builder.buildSignature(); 41 | String actualSign = new String(Hex.encodeHex(hmacSha256.doFinal(payload.getBytes()))); 42 | 43 | builder.putToUrl("signature", actualSign); 44 | 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/com/binance/client/model/user/UserDataUpdateEvent.java: -------------------------------------------------------------------------------- 1 | package com.binance.client.model.user; 2 | 3 | import com.binance.client.constant.BinanceApiConstants; 4 | import org.apache.commons.lang3.builder.ToStringBuilder; 5 | 6 | public class UserDataUpdateEvent { 7 | 8 | private String eventType; 9 | 10 | private Long eventTime; 11 | 12 | private Long transactionTime; 13 | 14 | private String eventReasonType; 15 | 16 | private AccountUpdate accountUpdate; 17 | 18 | private OrderUpdate orderUpdate; 19 | 20 | public String getEventType() { 21 | return eventType; 22 | } 23 | 24 | public void setEventType(String eventType) { 25 | this.eventType = eventType; 26 | } 27 | 28 | public Long getEventTime() { 29 | return eventTime; 30 | } 31 | 32 | public void setEventTime(Long eventTime) { 33 | this.eventTime = eventTime; 34 | } 35 | 36 | public Long getTransactionTime() { 37 | return transactionTime; 38 | } 39 | 40 | public void setTransactionTime(Long transactionTime) { 41 | this.transactionTime = transactionTime; 42 | } 43 | 44 | public AccountUpdate getAccountUpdate() { 45 | return accountUpdate; 46 | } 47 | 48 | public void setAccountUpdate(AccountUpdate accountUpdate) { 49 | this.accountUpdate = accountUpdate; 50 | } 51 | 52 | public OrderUpdate getOrderUpdate() { 53 | return orderUpdate; 54 | } 55 | 56 | public void setOrderUpdate(OrderUpdate orderUpdate) { 57 | this.orderUpdate = orderUpdate; 58 | } 59 | 60 | public String getEventReasonType() { 61 | return eventReasonType; 62 | } 63 | 64 | public void setEventReasonType(String eventReasonType) { 65 | this.eventReasonType = eventReasonType; 66 | } 67 | 68 | @Override 69 | public String toString() { 70 | return new ToStringBuilder(this, BinanceApiConstants.TO_STRING_BUILDER_STYLE).append("eventType", eventType) 71 | .append("eventTime", eventTime).append("transactionTime", transactionTime).append("eventReasonType", eventReasonType) 72 | .append("accountUpdate", accountUpdate).append("orderUpdate", orderUpdate).toString(); 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /src/main/java/com/binance/client/model/trade/Income.java: -------------------------------------------------------------------------------- 1 | package com.binance.client.model.trade; 2 | 3 | import com.binance.client.constant.BinanceApiConstants; 4 | import org.apache.commons.lang3.builder.ToStringBuilder; 5 | 6 | import java.math.BigDecimal; 7 | 8 | public class Income { 9 | 10 | private String symbol; 11 | 12 | private String incomeType; 13 | 14 | private BigDecimal income; 15 | 16 | private String asset; 17 | 18 | private String info; 19 | 20 | private Long time; 21 | 22 | private Long tranId; 23 | 24 | private String tradeId; 25 | 26 | public String getInfo() { 27 | return info; 28 | } 29 | 30 | public void setInfo(String info) { 31 | this.info = info; 32 | } 33 | 34 | public Long getTranId() { 35 | return tranId; 36 | } 37 | 38 | public void setTranId(Long tranId) { 39 | this.tranId = tranId; 40 | } 41 | 42 | public String getTradeId() { 43 | return tradeId; 44 | } 45 | 46 | public void setTradeId(String tradeId) { 47 | this.tradeId = tradeId; 48 | } 49 | 50 | public String getSymbol() { 51 | return symbol; 52 | } 53 | 54 | public void setSymbol(String symbol) { 55 | this.symbol = symbol; 56 | } 57 | 58 | public String getIncomeType() { 59 | return incomeType; 60 | } 61 | 62 | public void setIncomeType(String incomeType) { 63 | this.incomeType = incomeType; 64 | } 65 | 66 | public BigDecimal getIncome() { 67 | return income; 68 | } 69 | 70 | public void setIncome(BigDecimal income) { 71 | this.income = income; 72 | } 73 | 74 | public String getAsset() { 75 | return asset; 76 | } 77 | 78 | public void setAsset(String asset) { 79 | this.asset = asset; 80 | } 81 | 82 | public Long getTime() { 83 | return time; 84 | } 85 | 86 | public void setTime(Long time) { 87 | this.time = time; 88 | } 89 | 90 | @Override 91 | public String toString() { 92 | return new ToStringBuilder(this, BinanceApiConstants.TO_STRING_BUILDER_STYLE).append("symbol", symbol) 93 | .append("incomeType", incomeType).append("income", income).append("asset", asset).append("info", info) 94 | .append("time", time).append("tranId", tranId).append("tradeId", tradeId).toString(); 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /src/main/java/com/binance/client/model/trade/AccountBalance.java: -------------------------------------------------------------------------------- 1 | package com.binance.client.model.trade; 2 | 3 | import com.binance.client.constant.BinanceApiConstants; 4 | import org.apache.commons.lang3.builder.ToStringBuilder; 5 | 6 | import java.math.BigDecimal; 7 | 8 | public class AccountBalance { 9 | 10 | private String accountAlias; 11 | 12 | private String asset; 13 | 14 | private BigDecimal balance; 15 | private BigDecimal maxWithdrawAmount; 16 | private BigDecimal crossWalletBalance; 17 | private BigDecimal availableBalance; 18 | 19 | 20 | private BigDecimal crossUnPnl; 21 | 22 | public String getAccountAlias() { 23 | return accountAlias; 24 | } 25 | 26 | public void setAccountAlias(String accountAlias) { 27 | this.accountAlias = accountAlias; 28 | } 29 | 30 | public BigDecimal getCrossWalletBalance() { 31 | return crossWalletBalance; 32 | } 33 | 34 | public void setCrossWalletBalance(BigDecimal crossWalletBalance) { 35 | this.crossWalletBalance = crossWalletBalance; 36 | } 37 | 38 | public BigDecimal getAvailableBalance() { 39 | return availableBalance; 40 | } 41 | 42 | public void setAvailableBalance(BigDecimal availableBalance) { 43 | this.availableBalance = availableBalance; 44 | } 45 | 46 | public BigDecimal getCrossUnPnl() { 47 | return crossUnPnl; 48 | } 49 | 50 | public void setCrossUnPnl(BigDecimal crossUnPnl) { 51 | this.crossUnPnl = crossUnPnl; 52 | } 53 | 54 | public String getAsset() { 55 | return asset; 56 | } 57 | 58 | public void setAsset(String asset) { 59 | this.asset = asset; 60 | } 61 | 62 | public BigDecimal getBalance() { 63 | return balance; 64 | } 65 | 66 | public void setBalance(BigDecimal balance) { 67 | this.balance = balance; 68 | } 69 | 70 | public BigDecimal getMaxWithdrawAmount() { 71 | return maxWithdrawAmount; 72 | } 73 | 74 | public void setMaxWithdrawAmount(BigDecimal maxWithdrawAmount) { 75 | this.maxWithdrawAmount = maxWithdrawAmount; 76 | } 77 | 78 | @Override 79 | public String toString() { 80 | return new ToStringBuilder(this, BinanceApiConstants.TO_STRING_BUILDER_STYLE).append("asset", asset) 81 | .append("balance", balance).append("withdrawAvailable", maxWithdrawAmount).toString(); 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /src/main/java/com/binance/client/model/market/MarkPrice.java: -------------------------------------------------------------------------------- 1 | package com.binance.client.model.market; 2 | 3 | import com.binance.client.constant.BinanceApiConstants; 4 | import org.apache.commons.lang3.builder.ToStringBuilder; 5 | 6 | import java.math.BigDecimal; 7 | 8 | public class MarkPrice { 9 | 10 | private String symbol; 11 | 12 | private BigDecimal markPrice; 13 | 14 | private BigDecimal indexPrice; 15 | 16 | private BigDecimal lastFundingRate; 17 | 18 | 19 | 20 | private Long nextFundingTime; 21 | 22 | private BigDecimal interestRate; 23 | 24 | private Long time; 25 | 26 | public BigDecimal getIndexPrice() { 27 | return indexPrice; 28 | } 29 | 30 | public void setIndexPrice(BigDecimal indexPrice) { 31 | this.indexPrice = indexPrice; 32 | } 33 | 34 | public BigDecimal getInterestRate() { 35 | return interestRate; 36 | } 37 | 38 | public void setInterestRate(BigDecimal interestRate) { 39 | this.interestRate = interestRate; 40 | } 41 | 42 | public String getSymbol() { 43 | return symbol; 44 | } 45 | 46 | public void setSymbol(String symbol) { 47 | this.symbol = symbol; 48 | } 49 | 50 | public BigDecimal getMarkPrice() { 51 | return markPrice; 52 | } 53 | 54 | public void setMarkPrice(BigDecimal markPrice) { 55 | this.markPrice = markPrice; 56 | } 57 | 58 | public BigDecimal getLastFundingRate() { 59 | return lastFundingRate; 60 | } 61 | 62 | public void setLastFundingRate(BigDecimal lastFundingRate) { 63 | this.lastFundingRate = lastFundingRate; 64 | } 65 | 66 | public Long getNextFundingTime() { 67 | return nextFundingTime; 68 | } 69 | 70 | public void setNextFundingTime(Long nextFundingTime) { 71 | this.nextFundingTime = nextFundingTime; 72 | } 73 | 74 | public Long getTime() { 75 | return time; 76 | } 77 | 78 | public void setTime(Long time) { 79 | this.time = time; 80 | } 81 | 82 | @Override 83 | public String toString() { 84 | return new ToStringBuilder(this, BinanceApiConstants.TO_STRING_BUILDER_STYLE).append("symbol", symbol) 85 | .append("markPrice", markPrice).append("indexPrice", indexPrice).append("lastFundingRate", lastFundingRate) 86 | .append("nextFundingTime", nextFundingTime).append("interestRate", interestRate).append("time", time).toString(); 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /src/main/java/com/binance/client/impl/WebSocketWatchDog.java: -------------------------------------------------------------------------------- 1 | package com.binance.client.impl; 2 | 3 | import com.binance.client.SubscriptionOptions; 4 | import com.binance.client.impl.WebSocketConnection.ConnectionState; 5 | import java.util.Objects; 6 | import java.util.concurrent.CopyOnWriteArrayList; 7 | import java.util.concurrent.Executors; 8 | import java.util.concurrent.ScheduledExecutorService; 9 | import java.util.concurrent.TimeUnit; 10 | import org.slf4j.Logger; 11 | import org.slf4j.LoggerFactory; 12 | 13 | class WebSocketWatchDog { 14 | 15 | private final CopyOnWriteArrayList TIME_HELPER = new CopyOnWriteArrayList<>(); 16 | private final SubscriptionOptions options; 17 | private static final Logger log = LoggerFactory.getLogger(WebSocketConnection.class); 18 | 19 | WebSocketWatchDog(SubscriptionOptions subscriptionOptions) { 20 | this.options = Objects.requireNonNull(subscriptionOptions); 21 | long t = 1_000; 22 | ScheduledExecutorService exec = Executors.newScheduledThreadPool(1); 23 | exec.scheduleAtFixedRate(() -> { 24 | TIME_HELPER.forEach(connection -> { 25 | if (connection.getState() == ConnectionState.CONNECTED) { 26 | // Check response 27 | if (options.isAutoReconnect()) { 28 | long ts = System.currentTimeMillis() - connection.getLastReceivedTime(); 29 | if (ts > options.getReceiveLimitMs()) { 30 | log.warn("[Sub][" + connection.getConnectionId() + "] No response from server"); 31 | connection.reConnect(options.getConnectionDelayOnFailure()); 32 | } 33 | } 34 | } else if (connection.getState() == ConnectionState.DELAY_CONNECT) { 35 | connection.reConnect(); 36 | } else if (connection.getState() == ConnectionState.CLOSED_ON_ERROR) { 37 | if (options.isAutoReconnect()) { 38 | connection.reConnect(options.getConnectionDelayOnFailure()); 39 | } 40 | } 41 | }); 42 | }, t, t, TimeUnit.MILLISECONDS); 43 | Runtime.getRuntime().addShutdownHook(new Thread(exec::shutdown)); 44 | } 45 | 46 | void onConnectionCreated(WebSocketConnection connection) { 47 | TIME_HELPER.addIfAbsent(connection); 48 | } 49 | 50 | void onClosedNormally(WebSocketConnection connection) { 51 | TIME_HELPER.remove(connection); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/com/binance/client/model/user/PositionUpdate.java: -------------------------------------------------------------------------------- 1 | package com.binance.client.model.user; 2 | 3 | import com.binance.client.constant.BinanceApiConstants; 4 | import org.apache.commons.lang3.builder.ToStringBuilder; 5 | import java.math.BigDecimal; 6 | 7 | public class PositionUpdate { 8 | 9 | private String symbol; 10 | 11 | private BigDecimal amount; 12 | 13 | private BigDecimal entryPrice; 14 | 15 | private BigDecimal preFee; 16 | 17 | private BigDecimal unrealizedPnl; 18 | 19 | private String marginType; 20 | 21 | private BigDecimal isolatedWallet; 22 | 23 | private String positionSide; 24 | 25 | 26 | public String getSymbol() { 27 | return symbol; 28 | } 29 | 30 | public void setSymbol(String symbol) { 31 | this.symbol = symbol; 32 | } 33 | 34 | public BigDecimal getAmount() { 35 | return amount; 36 | } 37 | 38 | public void setAmount(BigDecimal amount) { 39 | this.amount = amount; 40 | } 41 | 42 | public BigDecimal getEntryPrice() { 43 | return entryPrice; 44 | } 45 | 46 | public void setEntryPrice(BigDecimal entryPrice) { 47 | this.entryPrice = entryPrice; 48 | } 49 | 50 | public BigDecimal getPreFee() { 51 | return preFee; 52 | } 53 | 54 | public void setPreFee(BigDecimal preFee) { 55 | this.preFee = preFee; 56 | } 57 | 58 | public BigDecimal getUnrealizedPnl() { 59 | return unrealizedPnl; 60 | } 61 | 62 | public void setUnrealizedPnl(BigDecimal unrealizedPnl) { 63 | this.unrealizedPnl = unrealizedPnl; 64 | } 65 | 66 | public String getMarginType() { 67 | return marginType; 68 | } 69 | 70 | public void setMarginType(String marginType) { 71 | this.marginType = marginType; 72 | } 73 | 74 | public BigDecimal getIsolatedWallet() { 75 | return isolatedWallet; 76 | } 77 | 78 | public void setIsolatedWallet(BigDecimal isolatedWallet) { 79 | this.isolatedWallet = isolatedWallet; 80 | } 81 | 82 | public String getPositionSide() { 83 | return positionSide; 84 | } 85 | 86 | public void setPositionSide(String positionSide) { 87 | this.positionSide = positionSide; 88 | } 89 | 90 | @Override 91 | public String toString() { 92 | return new ToStringBuilder(this, BinanceApiConstants.TO_STRING_BUILDER_STYLE).append("symbol", symbol) 93 | .append("amount", amount).append("entryPrice", entryPrice).append("preFee", preFee) 94 | .append("unrealizedPnl", unrealizedPnl).append("marginType", marginType).append("isolatedWallet", isolatedWallet) 95 | .append("positionSide", positionSide).toString(); 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /src/main/java/com/binance/client/model/event/MarkPriceEvent.java: -------------------------------------------------------------------------------- 1 | package com.binance.client.model.event; 2 | 3 | import com.binance.client.constant.BinanceApiConstants; 4 | import org.apache.commons.lang3.builder.ToStringBuilder; 5 | 6 | import java.math.BigDecimal; 7 | 8 | public class MarkPriceEvent { 9 | 10 | private String eventType; 11 | 12 | private Long eventTime; 13 | 14 | private String symbol; 15 | 16 | private BigDecimal markPrice; 17 | 18 | private BigDecimal indexPrice; 19 | 20 | private BigDecimal estimatedPrice; 21 | 22 | private BigDecimal fundingRate; 23 | 24 | private Long nextFundingTime; 25 | 26 | public String getEventType() { 27 | return eventType; 28 | } 29 | 30 | public void setEventType(String eventType) { 31 | this.eventType = eventType; 32 | } 33 | 34 | public Long getEventTime() { 35 | return eventTime; 36 | } 37 | 38 | public void setEventTime(Long eventTime) { 39 | this.eventTime = eventTime; 40 | } 41 | 42 | public String getSymbol() { 43 | return symbol; 44 | } 45 | 46 | public void setSymbol(String symbol) { 47 | this.symbol = symbol; 48 | } 49 | 50 | public BigDecimal getMarkPrice() { 51 | return markPrice; 52 | } 53 | 54 | public void setMarkPrice(BigDecimal markPrice) { 55 | this.markPrice = markPrice; 56 | } 57 | 58 | public BigDecimal getFundingRate() { 59 | return fundingRate; 60 | } 61 | 62 | public void setFundingRate(BigDecimal fundingRate) { 63 | this.fundingRate = fundingRate; 64 | } 65 | 66 | public Long getNextFundingTime() { 67 | return nextFundingTime; 68 | } 69 | 70 | public void setNextFundingTime(Long nextFundingTime) { 71 | this.nextFundingTime = nextFundingTime; 72 | } 73 | 74 | public BigDecimal getIndexPrice() { 75 | return indexPrice; 76 | } 77 | 78 | public void setIndexPrice(BigDecimal indexPrice) { 79 | this.indexPrice = indexPrice; 80 | } 81 | 82 | public BigDecimal getEstimatedPrice() { 83 | return estimatedPrice; 84 | } 85 | 86 | public void setEstimatedPrice(BigDecimal estimatedPrice) { 87 | this.estimatedPrice = estimatedPrice; 88 | } 89 | 90 | @Override 91 | public String toString() { 92 | return new ToStringBuilder(this, BinanceApiConstants.TO_STRING_BUILDER_STYLE).append("eventType", eventType) 93 | .append("eventTime", eventTime).append("symbol", symbol).append("markPrice", markPrice) 94 | .append("indexPrice", indexPrice).append("estimatedPrice", estimatedPrice) 95 | .append("fundingRate", fundingRate).append("nextFundingTime", nextFundingTime).toString(); 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /src/main/java/com/binance/client/model/event/SymbolBookTickerEvent.java: -------------------------------------------------------------------------------- 1 | package com.binance.client.model.event; 2 | 3 | import com.binance.client.constant.BinanceApiConstants; 4 | import org.apache.commons.lang3.builder.ToStringBuilder; 5 | 6 | import java.math.BigDecimal; 7 | 8 | public class SymbolBookTickerEvent { 9 | 10 | private Long orderBookUpdateId; 11 | 12 | private Long eventTime; 13 | 14 | private Long transactionTime; 15 | 16 | private String symbol; 17 | 18 | private BigDecimal bestBidPrice; 19 | 20 | private BigDecimal bestBidQty; 21 | 22 | private BigDecimal bestAskPrice; 23 | 24 | private BigDecimal bestAskQty; 25 | 26 | public Long getOrderBookUpdateId() { 27 | return orderBookUpdateId; 28 | } 29 | 30 | public void setOrderBookUpdateId(Long orderBookUpdateId) { 31 | this.orderBookUpdateId = orderBookUpdateId; 32 | } 33 | 34 | public String getSymbol() { 35 | return symbol; 36 | } 37 | 38 | public void setSymbol(String symbol) { 39 | this.symbol = symbol; 40 | } 41 | 42 | public BigDecimal getBestBidPrice() { 43 | return bestBidPrice; 44 | } 45 | 46 | public void setBestBidPrice(BigDecimal bestBidPrice) { 47 | this.bestBidPrice = bestBidPrice; 48 | } 49 | 50 | public BigDecimal getBestBidQty() { 51 | return bestBidQty; 52 | } 53 | 54 | public void setBestBidQty(BigDecimal bestBidQty) { 55 | this.bestBidQty = bestBidQty; 56 | } 57 | 58 | public BigDecimal getBestAskPrice() { 59 | return bestAskPrice; 60 | } 61 | 62 | public void setBestAskPrice(BigDecimal bestAskPrice) { 63 | this.bestAskPrice = bestAskPrice; 64 | } 65 | 66 | public BigDecimal getBestAskQty() { 67 | return bestAskQty; 68 | } 69 | 70 | public void setBestAskQty(BigDecimal bestAskQty) { 71 | this.bestAskQty = bestAskQty; 72 | } 73 | 74 | public Long getEventTime() { 75 | return eventTime; 76 | } 77 | 78 | public void setEventTime(Long eventTime) { 79 | this.eventTime = eventTime; 80 | } 81 | 82 | public Long getTransactionTime() { 83 | return transactionTime; 84 | } 85 | 86 | public void setTransactionTime(Long transactionTime) { 87 | this.transactionTime = transactionTime; 88 | } 89 | 90 | @Override 91 | public String toString() { 92 | return new ToStringBuilder(this, BinanceApiConstants.TO_STRING_BUILDER_STYLE) 93 | .append("orderBookUpdateId", orderBookUpdateId).append("eventTime", eventTime) 94 | .append("transactionTime", transactionTime).append("symbol", symbol) 95 | .append("bestBidPrice", bestBidPrice).append("bestBidQty", bestBidQty) 96 | .append("bestAskPrice", bestAskPrice).append("bestAskQty", bestAskQty).toString(); 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /src/main/java/com/binance/client/model/event/AggregateTradeEvent.java: -------------------------------------------------------------------------------- 1 | package com.binance.client.model.event; 2 | 3 | import com.binance.client.constant.BinanceApiConstants; 4 | import org.apache.commons.lang3.builder.ToStringBuilder; 5 | 6 | import java.math.BigDecimal; 7 | 8 | public class AggregateTradeEvent { 9 | 10 | private String eventType; 11 | 12 | private Long eventTime; 13 | 14 | private String symbol; 15 | 16 | private Long id; 17 | 18 | private BigDecimal price; 19 | 20 | private BigDecimal qty; 21 | 22 | private Long firstId; 23 | 24 | private Long lastId; 25 | 26 | private Long time; 27 | 28 | private Boolean isBuyerMaker; 29 | 30 | public String getEventType() { 31 | return eventType; 32 | } 33 | 34 | public void setEventType(String eventType) { 35 | this.eventType = eventType; 36 | } 37 | 38 | public Long getEventTime() { 39 | return eventTime; 40 | } 41 | 42 | public void setEventTime(Long eventTime) { 43 | this.eventTime = eventTime; 44 | } 45 | 46 | public String getSymbol() { 47 | return symbol; 48 | } 49 | 50 | public void setSymbol(String symbol) { 51 | this.symbol = symbol; 52 | } 53 | 54 | public Long getId() { 55 | return id; 56 | } 57 | 58 | public void setId(Long id) { 59 | this.id = id; 60 | } 61 | 62 | public BigDecimal getPrice() { 63 | return price; 64 | } 65 | 66 | public void setPrice(BigDecimal price) { 67 | this.price = price; 68 | } 69 | 70 | public BigDecimal getQty() { 71 | return qty; 72 | } 73 | 74 | public void setQty(BigDecimal qty) { 75 | this.qty = qty; 76 | } 77 | 78 | public Long getFirstId() { 79 | return firstId; 80 | } 81 | 82 | public void setFirstId(Long firstId) { 83 | this.firstId = firstId; 84 | } 85 | 86 | public Long getLastId() { 87 | return lastId; 88 | } 89 | 90 | public void setLastId(Long lastId) { 91 | this.lastId = lastId; 92 | } 93 | 94 | public Long getTime() { 95 | return time; 96 | } 97 | 98 | public void setTime(Long time) { 99 | this.time = time; 100 | } 101 | 102 | public Boolean getIsBuyerMaker() { 103 | return isBuyerMaker; 104 | } 105 | 106 | public void setIsBuyerMaker(Boolean isBuyerMaker) { 107 | this.isBuyerMaker = isBuyerMaker; 108 | } 109 | 110 | @Override 111 | public String toString() { 112 | return new ToStringBuilder(this, BinanceApiConstants.TO_STRING_BUILDER_STYLE).append("eventType", eventType) 113 | .append("eventTime", eventTime).append("symbol", symbol).append("id", id).append("price", price) 114 | .append("qty", qty).append("firstId", firstId).append("lastId", lastId).append("time", time) 115 | .append("isBuyerMaker", isBuyerMaker).toString(); 116 | } 117 | } 118 | -------------------------------------------------------------------------------- /src/main/java/com/binance/client/model/event/SymbolMiniTickerEvent.java: -------------------------------------------------------------------------------- 1 | package com.binance.client.model.event; 2 | 3 | import com.binance.client.constant.BinanceApiConstants; 4 | import org.apache.commons.lang3.builder.ToStringBuilder; 5 | 6 | import java.math.BigDecimal; 7 | 8 | public class SymbolMiniTickerEvent { 9 | 10 | private String eventType; 11 | 12 | private Long eventTime; 13 | 14 | private String symbol; 15 | 16 | private BigDecimal open; 17 | 18 | private BigDecimal close; 19 | 20 | private BigDecimal high; 21 | 22 | private BigDecimal low; 23 | 24 | private BigDecimal totalTradedBaseAssetVolume; 25 | 26 | private BigDecimal totalTradedQuoteAssetVolume; 27 | 28 | public String getEventType() { 29 | return eventType; 30 | } 31 | 32 | public void setEventType(String eventType) { 33 | this.eventType = eventType; 34 | } 35 | 36 | public Long getEventTime() { 37 | return eventTime; 38 | } 39 | 40 | public void setEventTime(Long eventTime) { 41 | this.eventTime = eventTime; 42 | } 43 | 44 | public String getSymbol() { 45 | return symbol; 46 | } 47 | 48 | public void setSymbol(String symbol) { 49 | this.symbol = symbol; 50 | } 51 | 52 | public BigDecimal getOpen() { 53 | return open; 54 | } 55 | 56 | public void setOpen(BigDecimal open) { 57 | this.open = open; 58 | } 59 | 60 | public BigDecimal getClose() { 61 | return close; 62 | } 63 | 64 | public void setClose(BigDecimal close) { 65 | this.close = close; 66 | } 67 | 68 | public BigDecimal getHigh() { 69 | return high; 70 | } 71 | 72 | public void setHigh(BigDecimal high) { 73 | this.high = high; 74 | } 75 | 76 | public BigDecimal getLow() { 77 | return low; 78 | } 79 | 80 | public void setLow(BigDecimal low) { 81 | this.low = low; 82 | } 83 | 84 | public BigDecimal getTotalTradedBaseAssetVolume() { 85 | return totalTradedBaseAssetVolume; 86 | } 87 | 88 | public void setTotalTradedBaseAssetVolume(BigDecimal totalTradedBaseAssetVolume) { 89 | this.totalTradedBaseAssetVolume = totalTradedBaseAssetVolume; 90 | } 91 | 92 | public BigDecimal getTotalTradedQuoteAssetVolume() { 93 | return totalTradedQuoteAssetVolume; 94 | } 95 | 96 | public void setTotalTradedQuoteAssetVolume(BigDecimal totalTradedQuoteAssetVolume) { 97 | this.totalTradedQuoteAssetVolume = totalTradedQuoteAssetVolume; 98 | } 99 | 100 | @Override 101 | public String toString() { 102 | return new ToStringBuilder(this, BinanceApiConstants.TO_STRING_BUILDER_STYLE).append("eventType", eventType) 103 | .append("eventTime", eventTime).append("symbol", symbol).append("open", open).append("close", close) 104 | .append("high", high).append("low", low) 105 | .append("totalTradedBaseAssetVolume", totalTradedBaseAssetVolume) 106 | .append("totalTradedQuoteAssetVolume", totalTradedQuoteAssetVolume).toString(); 107 | } 108 | } 109 | -------------------------------------------------------------------------------- /src/main/java/com/binance/client/model/event/OrderBookEvent.java: -------------------------------------------------------------------------------- 1 | package com.binance.client.model.event; 2 | 3 | import com.binance.client.constant.BinanceApiConstants; 4 | import org.apache.commons.lang3.builder.ToStringBuilder; 5 | 6 | import java.util.List; 7 | 8 | import com.binance.client.model.market.OrderBookEntry; 9 | 10 | public class OrderBookEvent { 11 | 12 | private String eventType; 13 | 14 | private Long eventTime; 15 | 16 | private Long transactionTime; 17 | 18 | private String symbol; 19 | 20 | private Long firstUpdateId; 21 | 22 | private Long lastUpdateId; 23 | 24 | private Long lastUpdateIdInlastStream; 25 | 26 | private List bids; 27 | 28 | private List asks; 29 | 30 | public String getEventType() { 31 | return eventType; 32 | } 33 | 34 | public void setEventType(String eventType) { 35 | this.eventType = eventType; 36 | } 37 | 38 | public Long getEventTime() { 39 | return eventTime; 40 | } 41 | 42 | public void setEventTime(Long eventTime) { 43 | this.eventTime = eventTime; 44 | } 45 | 46 | public Long getTransactionTime() { 47 | return transactionTime; 48 | } 49 | 50 | public void setTransactionTime(Long transactionTime) { 51 | this.transactionTime = transactionTime; 52 | } 53 | 54 | public String getSymbol() { 55 | return symbol; 56 | } 57 | 58 | public void setSymbol(String symbol) { 59 | this.symbol = symbol; 60 | } 61 | 62 | public Long getFirstUpdateId() { 63 | return firstUpdateId; 64 | } 65 | 66 | public void setFirstUpdateId(Long firstUpdateId) { 67 | this.firstUpdateId = firstUpdateId; 68 | } 69 | 70 | public Long getLastUpdateId() { 71 | return lastUpdateId; 72 | } 73 | 74 | public void setLastUpdateId(Long lastUpdateId) { 75 | this.lastUpdateId = lastUpdateId; 76 | } 77 | 78 | public Long getLastUpdateIdInlastStream() { 79 | return lastUpdateIdInlastStream; 80 | } 81 | 82 | public void setLastUpdateIdInlastStream(Long lastUpdateIdInlastStream) { 83 | this.lastUpdateIdInlastStream = lastUpdateIdInlastStream; 84 | } 85 | 86 | public List getBids() { 87 | return bids; 88 | } 89 | 90 | public void setBids(List bids) { 91 | this.bids = bids; 92 | } 93 | 94 | public List getAsks() { 95 | return asks; 96 | } 97 | 98 | public void setAsks(List asks) { 99 | this.asks = asks; 100 | } 101 | 102 | @Override 103 | public String toString() { 104 | return new ToStringBuilder(this, BinanceApiConstants.TO_STRING_BUILDER_STYLE).append("eventType", eventType) 105 | .append("eventTime", eventTime).append("transactionTime", transactionTime).append("symbol", symbol) 106 | .append("firstUpdateId", firstUpdateId).append("lastUpdateId", lastUpdateId) 107 | .append("lastUpdateIdInlastStream", lastUpdateIdInlastStream).append("bids", bids).append("asks", asks) 108 | .toString(); 109 | } 110 | } 111 | -------------------------------------------------------------------------------- /src/main/java/com/binance/client/SubscriptionOptions.java: -------------------------------------------------------------------------------- 1 | package com.binance.client; 2 | 3 | import com.binance.client.exception.BinanceApiException; 4 | import java.net.URI; 5 | 6 | /** 7 | * The configuration for the subscription APIs 8 | */ 9 | public class SubscriptionOptions { 10 | 11 | private String uri = "wss://api.binance.pro/"; 12 | private boolean isAutoReconnect = true; 13 | private int receiveLimitMs = 300_000; 14 | private int connectionDelayOnFailure = 15; 15 | 16 | public SubscriptionOptions(SubscriptionOptions options) { 17 | this.uri = options.uri; 18 | this.isAutoReconnect = options.isAutoReconnect; 19 | this.receiveLimitMs = options.receiveLimitMs; 20 | this.connectionDelayOnFailure = options.connectionDelayOnFailure; 21 | } 22 | 23 | public SubscriptionOptions() { 24 | } 25 | 26 | /** 27 | * Set the URI for subscription. 28 | * 29 | * @param uri The URI name like "wss://api.binance.pro". 30 | */ 31 | public void setUri(String uri) { 32 | try { 33 | URI u = new URI(uri); 34 | this.uri = u.toString(); 35 | } catch (Exception e) { 36 | throw new BinanceApiException(BinanceApiException.INPUT_ERROR, "The URI is incorrect: " + e.getMessage()); 37 | } 38 | this.uri = uri; 39 | } 40 | 41 | /** 42 | * Set the receive limit in millisecond. If no message is received within this 43 | * limit time, the connection will be disconnected. 44 | * 45 | * @param receiveLimitMs The receive limit in millisecond. 46 | */ 47 | public void setReceiveLimitMs(int receiveLimitMs) { 48 | this.receiveLimitMs = receiveLimitMs; 49 | } 50 | 51 | /** 52 | * If auto reconnect is enabled, specify the delay time before reconnect. 53 | * 54 | * @param connectionDelayOnFailure The delay time in second. 55 | */ 56 | public void setConnectionDelayOnFailure(int connectionDelayOnFailure) { 57 | this.connectionDelayOnFailure = connectionDelayOnFailure; 58 | } 59 | 60 | /** 61 | * When the connection lost is happening on the subscription line, specify 62 | * whether the client reconnect to server automatically. 63 | *

64 | * The connection lost means: 65 | *

    66 | *
  • Caused by network problem
  • 67 | *
  • The connection close triggered by server (happened every 24 hours)
  • 68 | *
  • No any message can be received from server within a specified time, see 69 | * {@link #setReceiveLimitMs(int)} (int)}
  • 70 | *
71 | * 72 | * @param isAutoReconnect The boolean flag, true for enable, false for disable 73 | * @return Return self for chaining 74 | */ 75 | public SubscriptionOptions setAutoReconnect(boolean isAutoReconnect) { 76 | this.isAutoReconnect = isAutoReconnect; 77 | return this; 78 | } 79 | 80 | public boolean isAutoReconnect() { 81 | return isAutoReconnect; 82 | } 83 | 84 | public int getReceiveLimitMs() { 85 | return receiveLimitMs; 86 | } 87 | 88 | public int getConnectionDelayOnFailure() { 89 | return connectionDelayOnFailure; 90 | } 91 | 92 | public String getUri() { 93 | return uri; 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /src/main/java/com/binance/client/impl/RestApiInvoker.java: -------------------------------------------------------------------------------- 1 | package com.binance.client.impl; 2 | 3 | import okhttp3.OkHttpClient; 4 | import okhttp3.Request; 5 | import okhttp3.Response; 6 | import okhttp3.WebSocket; 7 | import okhttp3.WebSocketListener; 8 | import org.slf4j.Logger; 9 | import org.slf4j.LoggerFactory; 10 | 11 | import com.binance.client.exception.BinanceApiException; 12 | import com.binance.client.impl.utils.JsonWrapper; 13 | 14 | abstract class RestApiInvoker { 15 | 16 | private static final Logger log = LoggerFactory.getLogger(RestApiInvoker.class); 17 | private static final OkHttpClient client = new OkHttpClient(); 18 | 19 | static void checkResponse(JsonWrapper json) { 20 | try { 21 | if (json.containKey("success")) { 22 | boolean success = json.getBoolean("success"); 23 | if (!success) { 24 | String err_code = json.getStringOrDefault("code", ""); 25 | String err_msg = json.getStringOrDefault("msg", ""); 26 | if ("".equals(err_code)) { 27 | throw new BinanceApiException(BinanceApiException.EXEC_ERROR, "[Executing] " + err_msg); 28 | } else { 29 | throw new BinanceApiException(BinanceApiException.EXEC_ERROR, 30 | "[Executing] " + err_code + ": " + err_msg); 31 | } 32 | } 33 | } else if (json.containKey("code")) { 34 | 35 | int code = json.getInteger("code"); 36 | if (code != 200) { 37 | String message = json.getStringOrDefault("msg", ""); 38 | throw new BinanceApiException(BinanceApiException.EXEC_ERROR, 39 | "[Executing] " + code + ": " + message); 40 | } 41 | } 42 | } catch (BinanceApiException e) { 43 | throw e; 44 | } catch (Exception e) { 45 | throw new BinanceApiException(BinanceApiException.RUNTIME_ERROR, 46 | "[Invoking] Unexpected error: " + e.getMessage()); 47 | } 48 | } 49 | 50 | static T callSync(RestApiRequest request) { 51 | try { 52 | String str; 53 | log.debug("Request URL " + request.request.url()); 54 | Response response = client.newCall(request.request).execute(); 55 | // System.out.println(response.body().string()); 56 | if (response != null && response.body() != null) { 57 | str = response.body().string(); 58 | response.close(); 59 | } else { 60 | throw new BinanceApiException(BinanceApiException.ENV_ERROR, 61 | "[Invoking] Cannot get the response from server"); 62 | } 63 | log.debug("Response =====> " + str); 64 | JsonWrapper jsonWrapper = JsonWrapper.parseFromString(str); 65 | checkResponse(jsonWrapper); 66 | return request.jsonParser.parseJson(jsonWrapper); 67 | } catch (BinanceApiException e) { 68 | throw e; 69 | } catch (Exception e) { 70 | throw new BinanceApiException(BinanceApiException.ENV_ERROR, 71 | "[Invoking] Unexpected error: " + e.getMessage()); 72 | } 73 | } 74 | 75 | static WebSocket createWebSocket(Request request, WebSocketListener listener) { 76 | return client.newWebSocket(request, listener); 77 | } 78 | 79 | } 80 | -------------------------------------------------------------------------------- /src/main/java/com/binance/client/model/market/Candlestick.java: -------------------------------------------------------------------------------- 1 | package com.binance.client.model.market; 2 | 3 | import com.binance.client.constant.BinanceApiConstants; 4 | import org.apache.commons.lang3.builder.ToStringBuilder; 5 | 6 | import java.math.BigDecimal; 7 | 8 | public class Candlestick { 9 | 10 | private Long openTime; 11 | 12 | private BigDecimal open; 13 | 14 | private BigDecimal high; 15 | 16 | private BigDecimal low; 17 | 18 | private BigDecimal close; 19 | 20 | private BigDecimal volume; 21 | 22 | private Long closeTime; 23 | 24 | private BigDecimal quoteAssetVolume; 25 | 26 | private Integer numTrades; 27 | 28 | private BigDecimal takerBuyBaseAssetVolume; 29 | 30 | private BigDecimal takerBuyQuoteAssetVolume; 31 | 32 | public Long getOpenTime() { 33 | return openTime; 34 | } 35 | 36 | public void setOpenTime(Long openTime) { 37 | this.openTime = openTime; 38 | } 39 | 40 | public BigDecimal getOpen() { 41 | return open; 42 | } 43 | 44 | public void setOpen(BigDecimal open) { 45 | this.open = open; 46 | } 47 | 48 | public BigDecimal getHigh() { 49 | return high; 50 | } 51 | 52 | public void setHigh(BigDecimal high) { 53 | this.high = high; 54 | } 55 | 56 | public BigDecimal getLow() { 57 | return low; 58 | } 59 | 60 | public void setLow(BigDecimal low) { 61 | this.low = low; 62 | } 63 | 64 | public BigDecimal getClose() { 65 | return close; 66 | } 67 | 68 | public void setClose(BigDecimal close) { 69 | this.close = close; 70 | } 71 | 72 | public BigDecimal getVolume() { 73 | return volume; 74 | } 75 | 76 | public void setVolume(BigDecimal volume) { 77 | this.volume = volume; 78 | } 79 | 80 | public Long getCloseTime() { 81 | return closeTime; 82 | } 83 | 84 | public void setCloseTime(Long closeTime) { 85 | this.closeTime = closeTime; 86 | } 87 | 88 | public BigDecimal getQuoteAssetVolume() { 89 | return quoteAssetVolume; 90 | } 91 | 92 | public void setQuoteAssetVolume(BigDecimal quoteAssetVolume) { 93 | this.quoteAssetVolume = quoteAssetVolume; 94 | } 95 | 96 | public Integer getNumTrades() { 97 | return numTrades; 98 | } 99 | 100 | public void setNumTrades(Integer numTrades) { 101 | this.numTrades = numTrades; 102 | } 103 | 104 | public BigDecimal getTakerBuyBaseAssetVolume() { 105 | return takerBuyBaseAssetVolume; 106 | } 107 | 108 | public void setTakerBuyBaseAssetVolume(BigDecimal takerBuyBaseAssetVolume) { 109 | this.takerBuyBaseAssetVolume = takerBuyBaseAssetVolume; 110 | } 111 | 112 | public BigDecimal getTakerBuyQuoteAssetVolume() { 113 | return takerBuyQuoteAssetVolume; 114 | } 115 | 116 | public void setTakerBuyQuoteAssetVolume(BigDecimal takerBuyQuoteAssetVolume) { 117 | this.takerBuyQuoteAssetVolume = takerBuyQuoteAssetVolume; 118 | } 119 | 120 | @Override 121 | public String toString() { 122 | return new ToStringBuilder(this, BinanceApiConstants.TO_STRING_BUILDER_STYLE).append("openTime", openTime) 123 | .append("open", open).append("high", high).append("low", low).append("close", close) 124 | .append("volume", volume).append("closeTime", closeTime).append("quoteAssetVolume", quoteAssetVolume) 125 | .append("numTrades", numTrades).append("takerBuyBaseAssetVolume", takerBuyBaseAssetVolume) 126 | .append("takerBuyQuoteAssetVolume", takerBuyQuoteAssetVolume).toString(); 127 | } 128 | } 129 | -------------------------------------------------------------------------------- /src/main/java/com/binance/client/model/event/LiquidationOrderEvent.java: -------------------------------------------------------------------------------- 1 | package com.binance.client.model.event; 2 | 3 | import com.binance.client.constant.BinanceApiConstants; 4 | import org.apache.commons.lang3.builder.ToStringBuilder; 5 | 6 | import java.math.BigDecimal; 7 | 8 | public class LiquidationOrderEvent { 9 | 10 | private String eventType; 11 | 12 | private Long eventTime; 13 | 14 | private String symbol; 15 | 16 | private String side; 17 | 18 | private String type; 19 | 20 | private String timeInForce; 21 | 22 | private BigDecimal origQty; 23 | 24 | private BigDecimal price; 25 | 26 | private BigDecimal averagePrice; 27 | 28 | private String orderStatus; 29 | 30 | private BigDecimal lastFilledQty; 31 | 32 | private BigDecimal lastFilledAccumulatedQty; 33 | 34 | private Long time; 35 | 36 | public String getEventType() { 37 | return eventType; 38 | } 39 | 40 | public void setEventType(String eventType) { 41 | this.eventType = eventType; 42 | } 43 | 44 | public Long getEventTime() { 45 | return eventTime; 46 | } 47 | 48 | public void setEventTime(Long eventTime) { 49 | this.eventTime = eventTime; 50 | } 51 | 52 | public String getSymbol() { 53 | return symbol; 54 | } 55 | 56 | public void setSymbol(String symbol) { 57 | this.symbol = symbol; 58 | } 59 | 60 | public String getSide() { 61 | return side; 62 | } 63 | 64 | public void setSide(String side) { 65 | this.side = side; 66 | } 67 | 68 | public String getType() { 69 | return type; 70 | } 71 | 72 | public void setType(String type) { 73 | this.type = type; 74 | } 75 | 76 | public String getTimeInForce() { 77 | return timeInForce; 78 | } 79 | 80 | public void setTimeInForce(String timeInForce) { 81 | this.timeInForce = timeInForce; 82 | } 83 | 84 | public BigDecimal getOrigQty() { 85 | return origQty; 86 | } 87 | 88 | public void setOrigQty(BigDecimal origQty) { 89 | this.origQty = origQty; 90 | } 91 | 92 | public BigDecimal getPrice() { 93 | return price; 94 | } 95 | 96 | public void setPrice(BigDecimal price) { 97 | this.price = price; 98 | } 99 | 100 | public BigDecimal getAveragePrice() { 101 | return averagePrice; 102 | } 103 | 104 | public void setAveragePrice(BigDecimal averagePrice) { 105 | this.averagePrice = averagePrice; 106 | } 107 | 108 | public String getOrderStatus() { 109 | return orderStatus; 110 | } 111 | 112 | public void setOrderStatus(String orderStatus) { 113 | this.orderStatus = orderStatus; 114 | } 115 | 116 | public BigDecimal getLastFilledQty() { 117 | return lastFilledQty; 118 | } 119 | 120 | public void setLastFilledQty(BigDecimal lastFilledQty) { 121 | this.lastFilledQty = lastFilledQty; 122 | } 123 | 124 | public BigDecimal getLastFilledAccumulatedQty() { 125 | return lastFilledAccumulatedQty; 126 | } 127 | 128 | public void setLastFilledAccumulatedQty(BigDecimal lastFilledAccumulatedQty) { 129 | this.lastFilledAccumulatedQty = lastFilledAccumulatedQty; 130 | } 131 | 132 | public Long getTime() { 133 | return time; 134 | } 135 | 136 | public void setTime(Long time) { 137 | this.time = time; 138 | } 139 | 140 | @Override 141 | public String toString() { 142 | return new ToStringBuilder(this, BinanceApiConstants.TO_STRING_BUILDER_STYLE).append("eventType", eventType) 143 | .append("eventTime", eventTime).append("symbol", symbol).append("side", side).append("type", type) 144 | .append("timeInForce", timeInForce).append("origQty", origQty).append("price", price) 145 | .append("averagePrice", averagePrice).append("orderStatus", orderStatus) 146 | .append("lastFilledQty", lastFilledQty).append("lastFilledAccumulatedQty", lastFilledAccumulatedQty) 147 | .append("time", time).toString(); 148 | } 149 | } 150 | -------------------------------------------------------------------------------- /src/main/java/com/binance/client/model/trade/PositionRisk.java: -------------------------------------------------------------------------------- 1 | package com.binance.client.model.trade; 2 | 3 | import com.binance.client.constant.BinanceApiConstants; 4 | import org.apache.commons.lang3.builder.ToStringBuilder; 5 | 6 | import java.math.BigDecimal; 7 | 8 | public class PositionRisk { 9 | 10 | private BigDecimal entryPrice; 11 | 12 | private String marginType; 13 | 14 | private Boolean isAutoAddMargin; 15 | 16 | private String isolatedMargin; 17 | 18 | private BigDecimal leverage; 19 | 20 | private BigDecimal liquidationPrice; 21 | 22 | private BigDecimal markPrice; 23 | 24 | private Double maxNotionalValue; 25 | 26 | private BigDecimal positionAmt; 27 | 28 | private String symbol; 29 | 30 | private BigDecimal unrealizedProfit; 31 | 32 | private String positionSide; 33 | 34 | 35 | public Boolean getAutoAddMargin() { 36 | return isAutoAddMargin; 37 | } 38 | 39 | public void setAutoAddMargin(Boolean autoAddMargin) { 40 | isAutoAddMargin = autoAddMargin; 41 | } 42 | 43 | public BigDecimal getEntryPrice() { 44 | return entryPrice; 45 | } 46 | 47 | public void setEntryPrice(BigDecimal entryPrice) { 48 | this.entryPrice = entryPrice; 49 | } 50 | 51 | public BigDecimal getLeverage() { 52 | return leverage; 53 | } 54 | 55 | public void setLeverage(BigDecimal leverage) { 56 | this.leverage = leverage; 57 | } 58 | 59 | public Double getMaxNotionalValue() { 60 | return maxNotionalValue; 61 | } 62 | 63 | public void setMaxNotionalValue(Double maxNotionalValue) { 64 | this.maxNotionalValue = maxNotionalValue; 65 | } 66 | 67 | public BigDecimal getLiquidationPrice() { 68 | return liquidationPrice; 69 | } 70 | 71 | public void setLiquidationPrice(BigDecimal liquidationPrice) { 72 | this.liquidationPrice = liquidationPrice; 73 | } 74 | 75 | public BigDecimal getMarkPrice() { 76 | return markPrice; 77 | } 78 | 79 | public void setMarkPrice(BigDecimal markPrice) { 80 | this.markPrice = markPrice; 81 | } 82 | 83 | public BigDecimal getPositionAmt() { 84 | return positionAmt; 85 | } 86 | 87 | public void setPositionAmt(BigDecimal positionAmt) { 88 | this.positionAmt = positionAmt; 89 | } 90 | 91 | public String getSymbol() { 92 | return symbol; 93 | } 94 | 95 | public void setSymbol(String symbol) { 96 | this.symbol = symbol; 97 | } 98 | 99 | public BigDecimal getUnrealizedProfit() { 100 | return unrealizedProfit; 101 | } 102 | 103 | public void setUnrealizedProfit(BigDecimal unrealizedProfit) { 104 | this.unrealizedProfit = unrealizedProfit; 105 | } 106 | 107 | public String getIsolatedMargin() { 108 | return isolatedMargin; 109 | } 110 | 111 | public void setIsolatedMargin(String isolatedMargin) { 112 | this.isolatedMargin = isolatedMargin; 113 | } 114 | 115 | public String getPositionSide() { 116 | return positionSide; 117 | } 118 | 119 | public void setPositionSide(String positionSide) { 120 | this.positionSide = positionSide; 121 | } 122 | 123 | public String getMarginType() { 124 | return marginType; 125 | } 126 | 127 | public void setMarginType(String marginType) { 128 | this.marginType = marginType; 129 | } 130 | 131 | @Override 132 | public String toString() { 133 | return new ToStringBuilder(this, BinanceApiConstants.TO_STRING_BUILDER_STYLE).append("entryPrice", entryPrice) 134 | .append("marginType", marginType).append("isAutoAddMargin", isAutoAddMargin) 135 | .append("isolatedMargin", isolatedMargin).append("leverage", leverage) 136 | .append("liquidationPrice", liquidationPrice).append("markPrice", markPrice) 137 | .append("maxNotionalValue", maxNotionalValue).append("positionAmt", positionAmt) 138 | .append("symbol", symbol).append("unrealizedProfit", unrealizedProfit) 139 | .append("positionSide", positionSide).toString(); 140 | } 141 | } 142 | -------------------------------------------------------------------------------- /src/main/java/com/binance/client/model/trade/Position.java: -------------------------------------------------------------------------------- 1 | package com.binance.client.model.trade; 2 | 3 | import com.binance.client.constant.BinanceApiConstants; 4 | import org.apache.commons.lang3.builder.ToStringBuilder; 5 | 6 | import java.math.BigDecimal; 7 | 8 | public class Position { 9 | 10 | private String symbol; 11 | 12 | private BigDecimal initialMargin; 13 | 14 | private BigDecimal maintMargin; 15 | 16 | private BigDecimal unrealizedProfit; 17 | 18 | private BigDecimal positionInitialMargin; 19 | 20 | private BigDecimal openOrderInitialMargin; 21 | 22 | private BigDecimal leverage; 23 | 24 | private Boolean isolated; 25 | 26 | private String entryPrice; 27 | 28 | private String maxNotional; 29 | 30 | private String positionSide; 31 | 32 | private BigDecimal positionAmt; 33 | 34 | 35 | public BigDecimal getPositionAmt() { 36 | return positionAmt; 37 | } 38 | 39 | public void setPositionAmt(BigDecimal positionAmt) { 40 | this.positionAmt = positionAmt; 41 | } 42 | 43 | public Boolean getIsolated() { 44 | return isolated; 45 | } 46 | 47 | public void setIsolated(Boolean isolated) { 48 | this.isolated = isolated; 49 | } 50 | 51 | public BigDecimal getLeverage() { 52 | return leverage; 53 | } 54 | 55 | public void setLeverage(BigDecimal leverage) { 56 | this.leverage = leverage; 57 | } 58 | 59 | public BigDecimal getInitialMargin() { 60 | return initialMargin; 61 | } 62 | 63 | public void setInitialMargin(BigDecimal initialMargin) { 64 | this.initialMargin = initialMargin; 65 | } 66 | 67 | public BigDecimal getMaintMargin() { 68 | return maintMargin; 69 | } 70 | 71 | public void setMaintMargin(BigDecimal maintMargin) { 72 | this.maintMargin = maintMargin; 73 | } 74 | 75 | public BigDecimal getOpenOrderInitialMargin() { 76 | return openOrderInitialMargin; 77 | } 78 | 79 | public void setOpenOrderInitialMargin(BigDecimal openOrderInitialMargin) { 80 | this.openOrderInitialMargin = openOrderInitialMargin; 81 | } 82 | 83 | public BigDecimal getPositionInitialMargin() { 84 | return positionInitialMargin; 85 | } 86 | 87 | public void setPositionInitialMargin(BigDecimal positionInitialMargin) { 88 | this.positionInitialMargin = positionInitialMargin; 89 | } 90 | 91 | public String getSymbol() { 92 | return symbol; 93 | } 94 | 95 | public void setSymbol(String symbol) { 96 | this.symbol = symbol; 97 | } 98 | 99 | public BigDecimal getUnrealizedProfit() { 100 | return unrealizedProfit; 101 | } 102 | 103 | public void setUnrealizedProfit(BigDecimal unrealizedProfit) { 104 | this.unrealizedProfit = unrealizedProfit; 105 | } 106 | 107 | public String getEntryPrice() { 108 | return entryPrice; 109 | } 110 | 111 | public void setEntryPrice(String entryPrice) { 112 | this.entryPrice = entryPrice; 113 | } 114 | 115 | public String getMaxNotional() { 116 | return maxNotional; 117 | } 118 | 119 | public void setMaxNotional(String maxNotional) { 120 | this.maxNotional = maxNotional; 121 | } 122 | 123 | public String getPositionSide() { 124 | return positionSide; 125 | } 126 | 127 | public void setPositionSide(String positionSide) { 128 | this.positionSide = positionSide; 129 | } 130 | 131 | @Override 132 | public String toString() { 133 | return new ToStringBuilder(this, BinanceApiConstants.TO_STRING_BUILDER_STYLE) 134 | .append("symbol", symbol).append("initialMargin", initialMargin).append("maintMargin", maintMargin) 135 | .append("unrealizedProfit", unrealizedProfit).append("positionInitialMargin", positionInitialMargin) 136 | .append("openOrderInitialMargin", openOrderInitialMargin).append("leverage", leverage) 137 | .append("isolated", isolated).append("entryPrice", entryPrice) 138 | .append("maxNotional", maxNotional).append("positionSide", positionSide) 139 | .append("positionAmt", positionAmt).toString(); 140 | } 141 | } 142 | -------------------------------------------------------------------------------- /src/main/java/com/binance/client/model/trade/MyTrade.java: -------------------------------------------------------------------------------- 1 | package com.binance.client.model.trade; 2 | 3 | import com.binance.client.constant.BinanceApiConstants; 4 | import org.apache.commons.lang3.builder.ToStringBuilder; 5 | 6 | import java.math.BigDecimal; 7 | 8 | public class MyTrade { 9 | 10 | private Boolean isBuyer; 11 | 12 | private BigDecimal commission; 13 | 14 | private String commissionAsset; 15 | 16 | private Long counterPartyId; 17 | 18 | private Boolean isMaker; 19 | 20 | private Long orderId; 21 | 22 | private BigDecimal price; 23 | 24 | private BigDecimal qty; 25 | 26 | private BigDecimal quoteQty; 27 | 28 | private BigDecimal realizedPnl; 29 | 30 | private String side; 31 | 32 | private String positionSide; 33 | 34 | private String symbol; 35 | 36 | private Long time; 37 | 38 | public Boolean getIsBuyer() { 39 | return isBuyer; 40 | } 41 | 42 | public void setIsBuyer(Boolean isBuyer) { 43 | this.isBuyer = isBuyer; 44 | } 45 | 46 | public BigDecimal getCommission() { 47 | return commission; 48 | } 49 | 50 | public void setCommission(BigDecimal commission) { 51 | this.commission = commission; 52 | } 53 | 54 | public String getCommissionAsset() { 55 | return commissionAsset; 56 | } 57 | 58 | public void setCommissionAsset(String commissionAsset) { 59 | this.commissionAsset = commissionAsset; 60 | } 61 | 62 | public Long getCounterPartyId() { 63 | return counterPartyId; 64 | } 65 | 66 | public void setCounterPartyId(Long counterPartyId) { 67 | this.counterPartyId = counterPartyId; 68 | } 69 | 70 | public Boolean getIsMaker() { 71 | return isMaker; 72 | } 73 | 74 | public void setIsMaker(Boolean isMaker) { 75 | this.isMaker = isMaker; 76 | } 77 | 78 | public Long getOrderId() { 79 | return orderId; 80 | } 81 | 82 | public void setOrderId(Long orderId) { 83 | this.orderId = orderId; 84 | } 85 | 86 | public BigDecimal getPrice() { 87 | return price; 88 | } 89 | 90 | public void setPrice(BigDecimal price) { 91 | this.price = price; 92 | } 93 | 94 | public BigDecimal getQty() { 95 | return qty; 96 | } 97 | 98 | public void setQty(BigDecimal qty) { 99 | this.qty = qty; 100 | } 101 | 102 | public BigDecimal getQuoteQty() { 103 | return quoteQty; 104 | } 105 | 106 | public void setQuoteQty(BigDecimal quoteQty) { 107 | this.quoteQty = quoteQty; 108 | } 109 | 110 | public BigDecimal getRealizedPnl() { 111 | return realizedPnl; 112 | } 113 | 114 | public void setRealizedPnl(BigDecimal realizedPnl) { 115 | this.realizedPnl = realizedPnl; 116 | } 117 | 118 | public String getSide() { 119 | return side; 120 | } 121 | 122 | public void setSide(String side) { 123 | this.side = side; 124 | } 125 | 126 | public String getPositionSide() { 127 | return positionSide; 128 | } 129 | 130 | public void setPositionSide(String positionSide) { 131 | this.positionSide = positionSide; 132 | } 133 | 134 | public String getSymbol() { 135 | return symbol; 136 | } 137 | 138 | public void setSymbol(String symbol) { 139 | this.symbol = symbol; 140 | } 141 | 142 | public Long getTime() { 143 | return time; 144 | } 145 | 146 | public void setTime(Long time) { 147 | this.time = time; 148 | } 149 | 150 | @Override 151 | public String toString() { 152 | return new ToStringBuilder(this, BinanceApiConstants.TO_STRING_BUILDER_STYLE).append("isBuyer", isBuyer) 153 | .append("commission", commission).append("commissionAsset", commissionAsset) 154 | .append("counterPartyId", counterPartyId).append("isMaker", isMaker) 155 | .append("orderId", orderId).append("price", price).append("qty", qty).append("quoteQty", quoteQty) 156 | .append("realizedPnl", realizedPnl).append("side", side).append("positionSide", positionSide) 157 | .append("symbol", symbol).append("time", time).toString(); 158 | } 159 | } 160 | -------------------------------------------------------------------------------- /src/main/java/com/binance/client/impl/InputChecker.java: -------------------------------------------------------------------------------- 1 | package com.binance.client.impl; 2 | 3 | import com.binance.client.exception.BinanceApiException; 4 | 5 | import java.util.List; 6 | import java.util.regex.Matcher; 7 | import java.util.regex.Pattern; 8 | 9 | class InputChecker { 10 | 11 | private static final String regEx = "[ _`~!@#$%^&*()+=|{}':;',\\[\\].<>/?~!@#¥%……&*()——+|{}【】‘;:”“’。,、?]|\n|\t"; 12 | 13 | private static final InputChecker checkerInst; 14 | 15 | static { 16 | checkerInst = new InputChecker(); 17 | } 18 | 19 | static InputChecker checker() { 20 | return checkerInst; 21 | } 22 | 23 | private boolean isSpecialChar(String str) { 24 | 25 | Pattern p = Pattern.compile(regEx); 26 | Matcher m = p.matcher(str); 27 | return m.find(); 28 | } 29 | 30 | InputChecker shouldNotNull(T value, String name) { 31 | if (value == null) { 32 | throw new BinanceApiException(BinanceApiException.INPUT_ERROR, 33 | "[Input] " + name + " should not be null"); 34 | } 35 | return checkerInst; 36 | } 37 | 38 | InputChecker shouldNull(T value, String name) { 39 | if (value != null) { 40 | throw new BinanceApiException(BinanceApiException.INPUT_ERROR, 41 | "[Input] " + name + " should be null"); 42 | } 43 | return checkerInst; 44 | } 45 | 46 | InputChecker checkSymbol(String symbol) { 47 | if (symbol == null || "".equals(symbol)) { 48 | throw new BinanceApiException(BinanceApiException.INPUT_ERROR, 49 | "[Input] Symbol is mandatory"); 50 | } 51 | if (isSpecialChar(symbol)) { 52 | throw new BinanceApiException(BinanceApiException.INPUT_ERROR, 53 | "[Input] " + symbol + " is invalid symbol"); 54 | } 55 | return checkerInst; 56 | } 57 | 58 | InputChecker checkCurrency(String currency) { 59 | if (currency == null || "".equals(currency)) { 60 | throw new BinanceApiException(BinanceApiException.INPUT_ERROR, 61 | "[Input] Currency is mandatory"); 62 | } 63 | if (isSpecialChar(currency)) { 64 | throw new BinanceApiException(BinanceApiException.INPUT_ERROR, 65 | "[Input] " + currency + " is invalid currency"); 66 | } 67 | return checkerInst; 68 | } 69 | 70 | InputChecker checkETF(String symbol) { 71 | if (!"hb10".equals(symbol)) { 72 | throw new BinanceApiException(BinanceApiException.INPUT_ERROR, 73 | "currently only support hb10 :-)"); 74 | } 75 | return checkerInst; 76 | } 77 | 78 | private InputChecker checkRange(int size, int min, int max, String name) { 79 | if (!(min <= size && size <= max)) { 80 | throw new BinanceApiException(BinanceApiException.INPUT_ERROR, 81 | "[Input] " + name + " is out of bound. " + size + " is not in [" + min + "," + max + "]"); 82 | } 83 | return checkerInst; 84 | } 85 | 86 | InputChecker checkSymbolList(List symbols) { 87 | if (symbols == null || symbols.size() == 0) { 88 | throw new BinanceApiException(BinanceApiException.INPUT_ERROR, "[Input] Symbol is mandatory"); 89 | } 90 | for (String symbol : symbols) { 91 | checkSymbol(symbol); 92 | } 93 | return checkerInst; 94 | } 95 | 96 | InputChecker checkRange(Integer size, int min, int max, String name) { 97 | if (size != null) { 98 | checkRange(size.intValue(), min, max, name); 99 | } 100 | return checkerInst; 101 | } 102 | 103 | InputChecker greaterOrEqual(Integer value, int base, String name) { 104 | if (value != null && value < base) { 105 | throw new BinanceApiException(BinanceApiException.INPUT_ERROR, 106 | "[Input] " + name + " should be greater than " + base); 107 | } 108 | return checkerInst; 109 | } 110 | 111 | InputChecker checkList(List list, int min, int max, String name) { 112 | if (list != null) { 113 | if (list.size() > max) { 114 | throw new BinanceApiException(BinanceApiException.INPUT_ERROR, 115 | "[Input] " + name + " is out of bound, the max size is " + max); 116 | } else if (list.size() < min) { 117 | throw new BinanceApiException(BinanceApiException.INPUT_ERROR, 118 | "[Input] " + name + " should contain " + min + " item(s) at least"); 119 | } 120 | } 121 | return checkerInst; 122 | } 123 | } 124 | -------------------------------------------------------------------------------- /src/main/java/com/binance/client/model/trade/Asset.java: -------------------------------------------------------------------------------- 1 | package com.binance.client.model.trade; 2 | 3 | import com.binance.client.constant.BinanceApiConstants; 4 | import org.apache.commons.lang3.builder.ToStringBuilder; 5 | 6 | import java.math.BigDecimal; 7 | 8 | public class Asset { 9 | 10 | private String asset; 11 | 12 | private BigDecimal walletBalance; 13 | 14 | private BigDecimal unrealizedProfit; 15 | 16 | private BigDecimal marginBalance; 17 | 18 | private BigDecimal maintMargin; 19 | 20 | private BigDecimal initialMargin; 21 | 22 | private BigDecimal positionInitialMargin; 23 | 24 | private BigDecimal openOrderInitialMargin; 25 | 26 | private BigDecimal crossWalletBalance; 27 | 28 | private BigDecimal crossUnPnl; 29 | 30 | private BigDecimal availableBalance; 31 | 32 | private BigDecimal maxWithdrawAmount; 33 | 34 | public BigDecimal getWalletBalance() { return walletBalance; } 35 | 36 | public void setWalletBalance(BigDecimal walletBalance) { this.walletBalance = walletBalance; } 37 | 38 | public BigDecimal getCrossWalletBalance() { return crossWalletBalance; } 39 | 40 | public void setCrossWalletBalance(BigDecimal crossWalletBalance) { 41 | this.crossWalletBalance = crossWalletBalance; 42 | } 43 | 44 | public BigDecimal getCrossUnPnl() { 45 | return crossUnPnl; 46 | } 47 | 48 | public void setCrossUnPnl(BigDecimal crossUnPnl) { 49 | this.crossUnPnl = crossUnPnl; 50 | } 51 | 52 | public BigDecimal getAvailableBalance() { 53 | return availableBalance; 54 | } 55 | 56 | public void setAvailableBalance(BigDecimal availableBalance) { 57 | this.availableBalance = availableBalance; 58 | } 59 | 60 | public String getAsset() { 61 | return asset; 62 | } 63 | 64 | public void setAsset(String asset) { 65 | this.asset = asset; 66 | } 67 | 68 | public BigDecimal getInitialMargin() { 69 | return initialMargin; 70 | } 71 | 72 | public void setInitialMargin(BigDecimal initialMargin) { 73 | this.initialMargin = initialMargin; 74 | } 75 | 76 | public BigDecimal getMaintMargin() { 77 | return maintMargin; 78 | } 79 | 80 | public void setMaintMargin(BigDecimal maintMargin) { 81 | this.maintMargin = maintMargin; 82 | } 83 | 84 | public BigDecimal getMarginBalance() { 85 | return marginBalance; 86 | } 87 | 88 | public void setMarginBalance(BigDecimal marginBalance) { 89 | this.marginBalance = marginBalance; 90 | } 91 | 92 | public BigDecimal getMaxWithdrawAmount() { 93 | return maxWithdrawAmount; 94 | } 95 | 96 | public void setMaxWithdrawAmount(BigDecimal maxWithdrawAmount) { 97 | this.maxWithdrawAmount = maxWithdrawAmount; 98 | } 99 | 100 | public BigDecimal getOpenOrderInitialMargin() { 101 | return openOrderInitialMargin; 102 | } 103 | 104 | public void setOpenOrderInitialMargin(BigDecimal openOrderInitialMargin) { 105 | this.openOrderInitialMargin = openOrderInitialMargin; 106 | } 107 | 108 | public BigDecimal getPositionInitialMargin() { 109 | return positionInitialMargin; 110 | } 111 | 112 | public void setPositionInitialMargin(BigDecimal positionInitialMargin) { 113 | this.positionInitialMargin = positionInitialMargin; 114 | } 115 | 116 | public BigDecimal getUnrealizedProfit() { 117 | return unrealizedProfit; 118 | } 119 | 120 | public void setUnrealizedProfit(BigDecimal unrealizedProfit) { 121 | this.unrealizedProfit = unrealizedProfit; 122 | } 123 | 124 | @Override 125 | public String toString() { 126 | return new ToStringBuilder(this, BinanceApiConstants.TO_STRING_BUILDER_STYLE).append("asset", asset) 127 | .append("walletBalance", walletBalance).append("unrealizedProfit", unrealizedProfit) 128 | .append("marginBalance", marginBalance).append("maintMargin", maintMargin).append("initialMargin", initialMargin) 129 | .append("positionInitialMargin", positionInitialMargin).append("openOrderInitialMargin", openOrderInitialMargin) 130 | .append("crossWalletBalance", crossWalletBalance).append("crossUnPnl", crossUnPnl) 131 | .append("availableBalance", availableBalance).append("maxWithdrawAmount", maxWithdrawAmount) 132 | .toString(); 133 | } 134 | } 135 | -------------------------------------------------------------------------------- /src/main/java/com/binance/client/model/market/ExchangeInfoEntry.java: -------------------------------------------------------------------------------- 1 | package com.binance.client.model.market; 2 | 3 | import com.binance.client.constant.BinanceApiConstants; 4 | import org.apache.commons.lang3.builder.ToStringBuilder; 5 | 6 | import java.util.List; 7 | import java.util.Map; 8 | 9 | import java.math.BigDecimal; 10 | 11 | public class ExchangeInfoEntry { 12 | 13 | private String symbol; 14 | 15 | private String status; 16 | 17 | private BigDecimal maintMarginPercent; 18 | 19 | private BigDecimal requiredMarginPercent; 20 | 21 | private String baseAsset; 22 | 23 | private String quoteAsset; 24 | 25 | private Long pricePrecision; 26 | 27 | private Long quantityPrecision; 28 | 29 | private Long baseAssetPrecision; 30 | 31 | private Long quotePrecision; 32 | 33 | private List orderTypes; 34 | 35 | private List timeInForce; 36 | 37 | private List>> filters; 38 | 39 | public String getSymbol() { 40 | return symbol; 41 | } 42 | 43 | public void setSymbol(String symbol) { 44 | this.symbol = symbol; 45 | } 46 | 47 | public String getStatus() { 48 | return status; 49 | } 50 | 51 | public void setStatus(String status) { 52 | this.status = status; 53 | } 54 | 55 | public BigDecimal getMaintMarginPercent() { 56 | return maintMarginPercent; 57 | } 58 | 59 | public void setMaintMarginPercent(BigDecimal maintMarginPercent) { 60 | this.maintMarginPercent = maintMarginPercent; 61 | } 62 | 63 | public BigDecimal getRequiredMarginPercent() { 64 | return requiredMarginPercent; 65 | } 66 | 67 | public void setRequiredMarginPercent(BigDecimal requiredMarginPercent) { 68 | this.requiredMarginPercent = requiredMarginPercent; 69 | } 70 | 71 | public String getBaseAsset() { 72 | return baseAsset; 73 | } 74 | 75 | public void setBaseAsset(String baseAsset) { 76 | this.baseAsset = baseAsset; 77 | } 78 | 79 | public String getQuoteAsset() { 80 | return quoteAsset; 81 | } 82 | 83 | public void setQuoteAsset(String quoteAsset) { 84 | this.quoteAsset = quoteAsset; 85 | } 86 | 87 | public Long getPricePrecision() { 88 | return pricePrecision; 89 | } 90 | 91 | public void setPricePrecision(Long pricePrecision) { 92 | this.pricePrecision = pricePrecision; 93 | } 94 | 95 | public Long getQuantityPrecision() { 96 | return quantityPrecision; 97 | } 98 | 99 | public void setQuantityPrecision(Long quantityPrecision) { 100 | this.quantityPrecision = quantityPrecision; 101 | } 102 | 103 | public Long getBaseAssetPrecision() { 104 | return baseAssetPrecision; 105 | } 106 | 107 | public void setBaseAssetPrecision(Long baseAssetPrecision) { 108 | this.baseAssetPrecision = baseAssetPrecision; 109 | } 110 | 111 | public Long getQuotePrecision() { 112 | return quotePrecision; 113 | } 114 | 115 | public void setQuotePrecision(Long quotePrecision) { 116 | this.quotePrecision = quotePrecision; 117 | } 118 | 119 | public List getOrderTypes() { 120 | return orderTypes; 121 | } 122 | 123 | public void setOrderTypes(List orderTypes) { 124 | this.orderTypes = orderTypes; 125 | } 126 | 127 | public List getTimeInForce() { 128 | return timeInForce; 129 | } 130 | 131 | public void setTimeInForce(List timeInForce) { 132 | this.timeInForce = timeInForce; 133 | } 134 | 135 | public List>> getFilters() { 136 | return filters; 137 | } 138 | 139 | public void setFilters(List>> filters) { 140 | this.filters = filters; 141 | } 142 | 143 | @Override 144 | public String toString() { 145 | return new ToStringBuilder(this, BinanceApiConstants.TO_STRING_BUILDER_STYLE).append("symbol", symbol) 146 | .append("status", status).append("maintMarginPercent", maintMarginPercent) 147 | .append("requiredMarginPercent", requiredMarginPercent).append("baseAsset", baseAsset) 148 | .append("quoteAsset", quoteAsset).append("pricePrecision", pricePrecision) 149 | .append("quantityPrecision", quantityPrecision).append("baseAssetPrecision", baseAssetPrecision) 150 | .append("quotePrecision", quotePrecision).append("orderTypes", orderTypes) 151 | .append("timeInForce", timeInForce).append("filters", filters).toString(); 152 | } 153 | } 154 | -------------------------------------------------------------------------------- /src/main/java/com/binance/client/impl/utils/JsonWrapperArray.java: -------------------------------------------------------------------------------- 1 | package com.binance.client.impl.utils; 2 | 3 | import com.alibaba.fastjson.JSON; 4 | import com.alibaba.fastjson.JSONArray; 5 | import com.alibaba.fastjson.JSONObject; 6 | import com.binance.client.exception.BinanceApiException; 7 | import java.math.BigDecimal; 8 | import java.util.List; 9 | import java.util.LinkedList; 10 | 11 | public class JsonWrapperArray { 12 | 13 | private JSONArray array = null; 14 | 15 | public JsonWrapperArray(JSONArray array) { 16 | this.array = array; 17 | } 18 | 19 | public JsonWrapper getJsonObjectAt(int index) { 20 | if (array != null && array.size() > index) { 21 | JSONObject object = (JSONObject) array.get(index); 22 | if (object == null) { 23 | throw new BinanceApiException(BinanceApiException.RUNTIME_ERROR, 24 | "[Json] Cannot get object at index " + index + " in array"); 25 | } 26 | return new JsonWrapper(object); 27 | } else { 28 | throw new BinanceApiException(BinanceApiException.RUNTIME_ERROR, 29 | "[Json] Index is out of bound or array is null"); 30 | } 31 | } 32 | 33 | public void add(JSON val) { 34 | this.array.add(val); 35 | } 36 | 37 | public JsonWrapperArray getArrayAt(int index) { 38 | if (array != null && array.size() > index) { 39 | JSONArray newArray = (JSONArray) array.get(index); 40 | if (newArray == null) { 41 | throw new BinanceApiException(BinanceApiException.RUNTIME_ERROR, 42 | "[Json] Cannot get array at index " + index + " in array"); 43 | } 44 | return new JsonWrapperArray(newArray); 45 | } else { 46 | throw new BinanceApiException(BinanceApiException.RUNTIME_ERROR, 47 | "[Json] Index is out of bound or array is null"); 48 | } 49 | } 50 | 51 | private Object getObjectAt(int index) { 52 | if (array != null && array.size() > index) { 53 | return array.get(index); 54 | } else { 55 | throw new BinanceApiException(BinanceApiException.RUNTIME_ERROR, 56 | "[Json] Index is out of bound or array is null"); 57 | } 58 | } 59 | 60 | public long getLongAt(int index) { 61 | try { 62 | return (Long) getObjectAt(index); 63 | } catch (Exception e) { 64 | throw new BinanceApiException(BinanceApiException.RUNTIME_ERROR, 65 | "[Json] Cannot get long at index " + index + " in array: " + e.getMessage()); 66 | } 67 | 68 | } 69 | 70 | public Integer getIntegerAt(int index) { 71 | try { 72 | return (Integer) getObjectAt(index); 73 | } catch (Exception e) { 74 | throw new BinanceApiException(BinanceApiException.RUNTIME_ERROR, 75 | "[Json] Cannot get integer at index " + index + " in array: " + e.getMessage()); 76 | } 77 | 78 | } 79 | 80 | public BigDecimal getBigDecimalAt(int index) { 81 | 82 | try { 83 | return new BigDecimal(new BigDecimal(getStringAt(index)).stripTrailingZeros().toPlainString()); 84 | } catch (RuntimeException e) { 85 | throw new BinanceApiException(null, e.getMessage()); 86 | } 87 | 88 | } 89 | 90 | public String getStringAt(int index) { 91 | 92 | try { 93 | return (String) getObjectAt(index); 94 | } catch (RuntimeException e) { 95 | throw new BinanceApiException(null, e.getMessage()); 96 | } 97 | 98 | } 99 | 100 | public void forEach(Handler objectHandler) { 101 | array.forEach((object) -> { 102 | if (!(object instanceof JSONObject)) { 103 | throw new BinanceApiException(BinanceApiException.RUNTIME_ERROR, "[Json] Parse array error in forEach"); 104 | } 105 | objectHandler.handle(new JsonWrapper((JSONObject) object)); 106 | }); 107 | } 108 | 109 | public void forEachAsArray(Handler objectHandler) { 110 | array.forEach((object) -> { 111 | if (!(object instanceof JSONArray)) { 112 | throw new BinanceApiException(BinanceApiException.RUNTIME_ERROR, 113 | "[Json] Parse array error in forEachAsArray"); 114 | } 115 | objectHandler.handle(new JsonWrapperArray((JSONArray) object)); 116 | }); 117 | } 118 | 119 | public void forEachAsString(Handler objectHandler) { 120 | array.forEach((object) -> { 121 | if (!(object instanceof String)) { 122 | throw new BinanceApiException(BinanceApiException.RUNTIME_ERROR, 123 | "[Json] Parse array error in forEachAsString"); 124 | } 125 | objectHandler.handle((String) object); 126 | }); 127 | } 128 | 129 | public List convert2StringList() { 130 | List result = new LinkedList<>(); 131 | this.forEachAsString((item) -> { 132 | result.add(item); 133 | }); 134 | return result; 135 | } 136 | 137 | } 138 | -------------------------------------------------------------------------------- /src/main/java/com/binance/client/model/market/PriceChangeTicker.java: -------------------------------------------------------------------------------- 1 | package com.binance.client.model.market; 2 | 3 | import com.binance.client.constant.BinanceApiConstants; 4 | import org.apache.commons.lang3.builder.ToStringBuilder; 5 | 6 | import java.math.BigDecimal; 7 | 8 | public class PriceChangeTicker { 9 | 10 | private String symbol; 11 | 12 | private BigDecimal priceChange; 13 | 14 | private BigDecimal priceChangePercent; 15 | 16 | private BigDecimal weightedAvgPrice; 17 | 18 | private BigDecimal prevClosePrice; 19 | 20 | private BigDecimal lastPrice; 21 | 22 | private BigDecimal lastQty; 23 | 24 | private BigDecimal openPrice; 25 | 26 | private BigDecimal highPrice; 27 | 28 | private BigDecimal lowPrice; 29 | 30 | private BigDecimal volume; 31 | 32 | private BigDecimal quoteVolume; 33 | 34 | private Long openTime; 35 | 36 | private Long closeTime; 37 | 38 | private Long firstId; 39 | 40 | private Long lastId; 41 | 42 | private Long count; 43 | 44 | public BigDecimal getPrevClosePrice() { 45 | return prevClosePrice; 46 | } 47 | 48 | public void setPrevClosePrice(BigDecimal prevClosePrice) { 49 | this.prevClosePrice = prevClosePrice; 50 | } 51 | 52 | public String getSymbol() { 53 | return symbol; 54 | } 55 | 56 | public void setSymbol(String symbol) { 57 | this.symbol = symbol; 58 | } 59 | 60 | public BigDecimal getPriceChange() { 61 | return priceChange; 62 | } 63 | 64 | public void setPriceChange(BigDecimal priceChange) { 65 | this.priceChange = priceChange; 66 | } 67 | 68 | public BigDecimal getPriceChangePercent() { 69 | return priceChangePercent; 70 | } 71 | 72 | public void setPriceChangePercent(BigDecimal priceChangePercent) { 73 | this.priceChangePercent = priceChangePercent; 74 | } 75 | 76 | public BigDecimal getWeightedAvgPrice() { 77 | return weightedAvgPrice; 78 | } 79 | 80 | public void setWeightedAvgPrice(BigDecimal weightedAvgPrice) { 81 | this.weightedAvgPrice = weightedAvgPrice; 82 | } 83 | 84 | public BigDecimal getLastPrice() { 85 | return lastPrice; 86 | } 87 | 88 | public void setLastPrice(BigDecimal lastPrice) { 89 | this.lastPrice = lastPrice; 90 | } 91 | 92 | public BigDecimal getLastQty() { 93 | return lastQty; 94 | } 95 | 96 | public void setLastQty(BigDecimal lastQty) { 97 | this.lastQty = lastQty; 98 | } 99 | 100 | public BigDecimal getOpenPrice() { 101 | return openPrice; 102 | } 103 | 104 | public void setOpenPrice(BigDecimal openPrice) { 105 | this.openPrice = openPrice; 106 | } 107 | 108 | public BigDecimal getHighPrice() { 109 | return highPrice; 110 | } 111 | 112 | public void setHighPrice(BigDecimal highPrice) { 113 | this.highPrice = highPrice; 114 | } 115 | 116 | public BigDecimal getLowPrice() { 117 | return lowPrice; 118 | } 119 | 120 | public void setLowPrice(BigDecimal lowPrice) { 121 | this.lowPrice = lowPrice; 122 | } 123 | 124 | public BigDecimal getVolume() { 125 | return volume; 126 | } 127 | 128 | public void setVolume(BigDecimal volume) { 129 | this.volume = volume; 130 | } 131 | 132 | public BigDecimal getQuoteVolume() { 133 | return quoteVolume; 134 | } 135 | 136 | public void setQuoteVolume(BigDecimal quoteVolume) { 137 | this.quoteVolume = quoteVolume; 138 | } 139 | 140 | public Long getOpenTime() { 141 | return openTime; 142 | } 143 | 144 | public void setOpenTime(Long openTime) { 145 | this.openTime = openTime; 146 | } 147 | 148 | public Long getCloseTime() { 149 | return closeTime; 150 | } 151 | 152 | public void setCloseTime(Long closeTime) { 153 | this.closeTime = closeTime; 154 | } 155 | 156 | public Long getFirstId() { 157 | return firstId; 158 | } 159 | 160 | public void setFirstId(Long firstId) { 161 | this.firstId = firstId; 162 | } 163 | 164 | public Long getLastId() { 165 | return lastId; 166 | } 167 | 168 | public void setLastId(Long lastId) { 169 | this.lastId = lastId; 170 | } 171 | 172 | public Long getCount() { 173 | return count; 174 | } 175 | 176 | public void setCount(Long count) { 177 | this.count = count; 178 | } 179 | 180 | @Override 181 | public String toString() { 182 | return new ToStringBuilder(this, BinanceApiConstants.TO_STRING_BUILDER_STYLE).append("symbol", symbol) 183 | .append("priceChange", priceChange).append("priceChangePercent", priceChangePercent) 184 | .append("weightedAvgPrice", weightedAvgPrice).append("prevClosePrice", prevClosePrice).append("lastPrice", lastPrice).append("lastQty", lastQty) 185 | .append("openPrice", openPrice).append("highPrice", highPrice).append("lowPrice", lowPrice) 186 | .append("volume", volume).append("quoteVolume", quoteVolume).append("openTime", openTime) 187 | .append("closeTime", closeTime).append("firstId", firstId).append("lastId", lastId) 188 | .append("count", count).toString(); 189 | } 190 | } 191 | -------------------------------------------------------------------------------- /src/main/java/com/binance/client/model/event/SymbolTickerEvent.java: -------------------------------------------------------------------------------- 1 | package com.binance.client.model.event; 2 | 3 | import com.binance.client.constant.BinanceApiConstants; 4 | import org.apache.commons.lang3.builder.ToStringBuilder; 5 | 6 | import java.math.BigDecimal; 7 | 8 | public class SymbolTickerEvent { 9 | 10 | private String eventType; 11 | 12 | private Long eventTime; 13 | 14 | private String symbol; 15 | 16 | private BigDecimal priceChange; 17 | 18 | private BigDecimal priceChangePercent; 19 | 20 | private BigDecimal weightedAvgPrice; 21 | 22 | private BigDecimal lastPrice; 23 | 24 | private BigDecimal lastQty; 25 | 26 | private BigDecimal open; 27 | 28 | private BigDecimal high; 29 | 30 | private BigDecimal low; 31 | 32 | private BigDecimal totalTradedBaseAssetVolume; 33 | 34 | private BigDecimal totalTradedQuoteAssetVolume; 35 | 36 | private Long openTime; 37 | 38 | private Long closeTime; 39 | 40 | private Long firstId; 41 | 42 | private Long lastId; 43 | 44 | private Long count; 45 | 46 | public String getEventType() { 47 | return eventType; 48 | } 49 | 50 | public void setEventType(String eventType) { 51 | this.eventType = eventType; 52 | } 53 | 54 | public Long getEventTime() { 55 | return eventTime; 56 | } 57 | 58 | public void setEventTime(Long eventTime) { 59 | this.eventTime = eventTime; 60 | } 61 | 62 | public String getSymbol() { 63 | return symbol; 64 | } 65 | 66 | public void setSymbol(String symbol) { 67 | this.symbol = symbol; 68 | } 69 | 70 | public BigDecimal getPriceChange() { 71 | return priceChange; 72 | } 73 | 74 | public void setPriceChange(BigDecimal priceChange) { 75 | this.priceChange = priceChange; 76 | } 77 | 78 | public BigDecimal getPriceChangePercent() { 79 | return priceChangePercent; 80 | } 81 | 82 | public void setPriceChangePercent(BigDecimal priceChangePercent) { 83 | this.priceChangePercent = priceChangePercent; 84 | } 85 | 86 | public BigDecimal getWeightedAvgPrice() { 87 | return weightedAvgPrice; 88 | } 89 | 90 | public void setWeightedAvgPrice(BigDecimal weightedAvgPrice) { 91 | this.weightedAvgPrice = weightedAvgPrice; 92 | } 93 | 94 | public BigDecimal getLastPrice() { 95 | return lastPrice; 96 | } 97 | 98 | public void setLastPrice(BigDecimal lastPrice) { 99 | this.lastPrice = lastPrice; 100 | } 101 | 102 | public BigDecimal getLastQty() { 103 | return lastQty; 104 | } 105 | 106 | public void setLastQty(BigDecimal lastQty) { 107 | this.lastQty = lastQty; 108 | } 109 | 110 | public BigDecimal getOpen() { 111 | return open; 112 | } 113 | 114 | public void setOpen(BigDecimal open) { 115 | this.open = open; 116 | } 117 | 118 | public BigDecimal getHigh() { 119 | return high; 120 | } 121 | 122 | public void setHigh(BigDecimal high) { 123 | this.high = high; 124 | } 125 | 126 | public BigDecimal getLow() { 127 | return low; 128 | } 129 | 130 | public void setLow(BigDecimal low) { 131 | this.low = low; 132 | } 133 | 134 | public BigDecimal getTotalTradedBaseAssetVolume() { 135 | return totalTradedBaseAssetVolume; 136 | } 137 | 138 | public void setTotalTradedBaseAssetVolume(BigDecimal totalTradedBaseAssetVolume) { 139 | this.totalTradedBaseAssetVolume = totalTradedBaseAssetVolume; 140 | } 141 | 142 | public BigDecimal getTotalTradedQuoteAssetVolume() { 143 | return totalTradedQuoteAssetVolume; 144 | } 145 | 146 | public void setTotalTradedQuoteAssetVolume(BigDecimal totalTradedQuoteAssetVolume) { 147 | this.totalTradedQuoteAssetVolume = totalTradedQuoteAssetVolume; 148 | } 149 | 150 | public Long getOpenTime() { 151 | return openTime; 152 | } 153 | 154 | public void setOpenTime(Long openTime) { 155 | this.openTime = openTime; 156 | } 157 | 158 | public Long getCloseTime() { 159 | return closeTime; 160 | } 161 | 162 | public void setCloseTime(Long closeTime) { 163 | this.closeTime = closeTime; 164 | } 165 | 166 | public Long getFirstId() { 167 | return firstId; 168 | } 169 | 170 | public void setFirstId(Long firstId) { 171 | this.firstId = firstId; 172 | } 173 | 174 | public Long getLastId() { 175 | return lastId; 176 | } 177 | 178 | public void setLastId(Long lastId) { 179 | this.lastId = lastId; 180 | } 181 | 182 | public Long getCount() { 183 | return count; 184 | } 185 | 186 | public void setCount(Long count) { 187 | this.count = count; 188 | } 189 | 190 | @Override 191 | public String toString() { 192 | return new ToStringBuilder(this, BinanceApiConstants.TO_STRING_BUILDER_STYLE).append("eventType", eventType) 193 | .append("eventTime", eventTime).append("symbol", symbol).append("priceChange", priceChange) 194 | .append("priceChangePercent", priceChangePercent).append("weightedAvgPrice", weightedAvgPrice) 195 | .append("lastPrice", lastPrice).append("lastQty", lastQty).append("open", open).append("high", high) 196 | .append("low", low).append("totalTradedBaseAssetVolume", totalTradedBaseAssetVolume) 197 | .append("totalTradedQuoteAssetVolume", totalTradedQuoteAssetVolume).append("openTime", openTime) 198 | .append("closeTime", closeTime).append("firstId", firstId).append("lastId", lastId) 199 | .append("count", count).toString(); 200 | } 201 | } 202 | -------------------------------------------------------------------------------- /src/main/java/com/binance/client/model/event/CandlestickEvent.java: -------------------------------------------------------------------------------- 1 | package com.binance.client.model.event; 2 | 3 | import com.binance.client.constant.BinanceApiConstants; 4 | import org.apache.commons.lang3.builder.ToStringBuilder; 5 | 6 | import java.math.BigDecimal; 7 | 8 | public class CandlestickEvent { 9 | 10 | private String eventType; 11 | 12 | private Long eventTime; 13 | 14 | private String symbol; 15 | 16 | private Long startTime; 17 | 18 | private Long closeTime; 19 | 20 | private String interval; 21 | 22 | private Long firstTradeId; 23 | 24 | private Long lastTradeId; 25 | 26 | private BigDecimal open; 27 | 28 | private BigDecimal close; 29 | 30 | private BigDecimal high; 31 | 32 | private BigDecimal low; 33 | 34 | private BigDecimal volume; 35 | 36 | private Long numTrades; 37 | 38 | private Boolean isClosed; 39 | 40 | private BigDecimal quoteAssetVolume; 41 | 42 | private BigDecimal takerBuyBaseAssetVolume; 43 | 44 | private BigDecimal takerBuyQuoteAssetVolume; 45 | 46 | private Long ignore; 47 | 48 | public String getEventType() { 49 | return eventType; 50 | } 51 | 52 | public void setEventType(String eventType) { 53 | this.eventType = eventType; 54 | } 55 | 56 | public Long getEventTime() { 57 | return eventTime; 58 | } 59 | 60 | public void setEventTime(Long eventTime) { 61 | this.eventTime = eventTime; 62 | } 63 | 64 | public String getSymbol() { 65 | return symbol; 66 | } 67 | 68 | public void setSymbol(String symbol) { 69 | this.symbol = symbol; 70 | } 71 | 72 | public Long getStartTime() { 73 | return startTime; 74 | } 75 | 76 | public void setStartTime(Long startTime) { 77 | this.startTime = startTime; 78 | } 79 | 80 | public Long getCloseTime() { 81 | return closeTime; 82 | } 83 | 84 | public void setCloseTime(Long closeTime) { 85 | this.closeTime = closeTime; 86 | } 87 | 88 | public String getInterval() { 89 | return interval; 90 | } 91 | 92 | public void setInterval(String interval) { 93 | this.interval = interval; 94 | } 95 | 96 | public Long getFirstTradeId() { 97 | return firstTradeId; 98 | } 99 | 100 | public void setFirstTradeId(Long firstTradeId) { 101 | this.firstTradeId = firstTradeId; 102 | } 103 | 104 | public Long getLastTradeId() { 105 | return lastTradeId; 106 | } 107 | 108 | public void setLastTradeId(Long lastTradeId) { 109 | this.lastTradeId = lastTradeId; 110 | } 111 | 112 | public BigDecimal getOpen() { 113 | return open; 114 | } 115 | 116 | public void setOpen(BigDecimal open) { 117 | this.open = open; 118 | } 119 | 120 | public BigDecimal getClose() { 121 | return close; 122 | } 123 | 124 | public void setClose(BigDecimal close) { 125 | this.close = close; 126 | } 127 | 128 | public BigDecimal getHigh() { 129 | return high; 130 | } 131 | 132 | public void setHigh(BigDecimal high) { 133 | this.high = high; 134 | } 135 | 136 | public BigDecimal getLow() { 137 | return low; 138 | } 139 | 140 | public void setLow(BigDecimal low) { 141 | this.low = low; 142 | } 143 | 144 | public BigDecimal getVolume() { 145 | return volume; 146 | } 147 | 148 | public void setVolume(BigDecimal volume) { 149 | this.volume = volume; 150 | } 151 | 152 | public Long getNumTrades() { 153 | return numTrades; 154 | } 155 | 156 | public void setNumTrades(Long numTrades) { 157 | this.numTrades = numTrades; 158 | } 159 | 160 | public Boolean getIsClosed() { 161 | return isClosed; 162 | } 163 | 164 | public void setIsClosed(Boolean isClosed) { 165 | this.isClosed = isClosed; 166 | } 167 | 168 | public BigDecimal getQuoteAssetVolume() { 169 | return quoteAssetVolume; 170 | } 171 | 172 | public void setQuoteAssetVolume(BigDecimal quoteAssetVolume) { 173 | this.quoteAssetVolume = quoteAssetVolume; 174 | } 175 | 176 | public BigDecimal getTakerBuyBaseAssetVolume() { 177 | return takerBuyBaseAssetVolume; 178 | } 179 | 180 | public void setTakerBuyBaseAssetVolume(BigDecimal takerBuyBaseAssetVolume) { 181 | this.takerBuyBaseAssetVolume = takerBuyBaseAssetVolume; 182 | } 183 | 184 | public BigDecimal getTakerBuyQuoteAssetVolume() { 185 | return takerBuyQuoteAssetVolume; 186 | } 187 | 188 | public void setTakerBuyQuoteAssetVolume(BigDecimal takerBuyQuoteAssetVolume) { 189 | this.takerBuyQuoteAssetVolume = takerBuyQuoteAssetVolume; 190 | } 191 | 192 | public Long getIgnore() { 193 | return ignore; 194 | } 195 | 196 | public void setIgnore(Long ignore) { 197 | this.ignore = ignore; 198 | } 199 | 200 | @Override 201 | public String toString() { 202 | return new ToStringBuilder(this, BinanceApiConstants.TO_STRING_BUILDER_STYLE).append("eventType", eventType) 203 | .append("eventTime", eventTime).append("symbol", symbol).append("startTime", startTime) 204 | .append("closeTime", closeTime).append("symbol", symbol).append("interval", interval) 205 | .append("firstTradeId", firstTradeId).append("lastTradeId", lastTradeId).append("open", open) 206 | .append("close", close).append("high", high).append("low", low).append("volume", volume) 207 | .append("numTrades", numTrades).append("isClosed", isClosed) 208 | .append("quoteAssetVolume", quoteAssetVolume).append("takerBuyBaseAssetVolume", takerBuyBaseAssetVolume) 209 | .append("takerBuyQuoteAssetVolume", takerBuyQuoteAssetVolume).append("ignore", ignore).toString(); 210 | } 211 | 212 | } 213 | -------------------------------------------------------------------------------- /src/main/java/com/binance/client/model/market/LiquidationOrder.java: -------------------------------------------------------------------------------- 1 | package com.binance.client.model.market; 2 | 3 | import com.binance.client.constant.BinanceApiConstants; 4 | import org.apache.commons.lang3.builder.ToStringBuilder; 5 | 6 | import java.math.BigDecimal; 7 | 8 | public class LiquidationOrder { 9 | 10 | private Long orderId; 11 | 12 | private String symbol; 13 | 14 | private String status; 15 | 16 | private String clientOrderId; 17 | 18 | private BigDecimal price; 19 | 20 | private BigDecimal averagePrice; 21 | 22 | private BigDecimal origQty; 23 | 24 | private BigDecimal executedQty; 25 | 26 | private BigDecimal cumQuote; 27 | 28 | 29 | 30 | private String timeInForce; 31 | 32 | private String type; 33 | 34 | private Boolean reduceOnly; 35 | 36 | private Boolean closePosition; 37 | 38 | private String side; 39 | 40 | private String positionSide; 41 | 42 | private BigDecimal stopPrice; 43 | 44 | private String workingType; 45 | 46 | private String origType; 47 | 48 | private Long time; 49 | 50 | private Long updateTime; 51 | 52 | 53 | public String getStatus() { 54 | return status; 55 | } 56 | 57 | public void setStatus(String status) { 58 | this.status = status; 59 | } 60 | 61 | public String getSymbol() { 62 | return symbol; 63 | } 64 | 65 | public void setSymbol(String symbol) { 66 | this.symbol = symbol; 67 | } 68 | 69 | public BigDecimal getPrice() { 70 | return price; 71 | } 72 | 73 | public void setPrice(BigDecimal price) { 74 | this.price = price; 75 | } 76 | 77 | public BigDecimal getOrigQty() { 78 | return origQty; 79 | } 80 | 81 | public void setOrigQty(BigDecimal origQty) { 82 | this.origQty = origQty; 83 | } 84 | 85 | public BigDecimal getExecutedQty() { 86 | return executedQty; 87 | } 88 | 89 | public void setExecutedQty(BigDecimal executedQty) { 90 | this.executedQty = executedQty; 91 | } 92 | 93 | public BigDecimal getAveragePrice() { 94 | return averagePrice; 95 | } 96 | 97 | public void setAveragePrice(BigDecimal averagePrice) { 98 | this.averagePrice = averagePrice; 99 | } 100 | 101 | public String getTimeInForce() { 102 | return timeInForce; 103 | } 104 | 105 | public void setTimeInForce(String timeInForce) { 106 | this.timeInForce = timeInForce; 107 | } 108 | 109 | public String getType() { 110 | return type; 111 | } 112 | 113 | public void setType(String type) { 114 | this.type = type; 115 | } 116 | 117 | public String getSide() { 118 | return side; 119 | } 120 | 121 | public void setSide(String side) { 122 | this.side = side; 123 | } 124 | 125 | public Long getTime() { 126 | return time; 127 | } 128 | 129 | public void setTime(Long time) { 130 | this.time = time; 131 | } 132 | 133 | public Long getOrderId() { 134 | return orderId; 135 | } 136 | 137 | public void setOrderId(Long orderId) { 138 | this.orderId = orderId; 139 | } 140 | 141 | public String getClientOrderId() { 142 | return clientOrderId; 143 | } 144 | 145 | public void setClientOrderId(String clientOrderId) { 146 | this.clientOrderId = clientOrderId; 147 | } 148 | 149 | public BigDecimal getCumQuote() { 150 | return cumQuote; 151 | } 152 | 153 | public void setCumQuote(BigDecimal cumQuote) { 154 | this.cumQuote = cumQuote; 155 | } 156 | 157 | public Boolean getReduceOnly() { 158 | return reduceOnly; 159 | } 160 | 161 | public void setReduceOnly(Boolean reduceOnly) { 162 | this.reduceOnly = reduceOnly; 163 | } 164 | 165 | public Boolean getClosePosition() { 166 | return closePosition; 167 | } 168 | 169 | public void setClosePosition(Boolean closePosition) { 170 | this.closePosition = closePosition; 171 | } 172 | 173 | public String getPositionSide() { 174 | return positionSide; 175 | } 176 | 177 | public void setPositionSide(String positionSide) { 178 | this.positionSide = positionSide; 179 | } 180 | 181 | public BigDecimal getStopPrice() { 182 | return stopPrice; 183 | } 184 | 185 | public void setStopPrice(BigDecimal stopPrice) { 186 | this.stopPrice = stopPrice; 187 | } 188 | 189 | public String getWorkingType() { 190 | return workingType; 191 | } 192 | 193 | public void setWorkingType(String workingType) { 194 | this.workingType = workingType; 195 | } 196 | 197 | public String getOrigType() { 198 | return origType; 199 | } 200 | 201 | public void setOrigType(String origType) { 202 | this.origType = origType; 203 | } 204 | 205 | public Long getUpdateTime() { 206 | return updateTime; 207 | } 208 | 209 | public void setUpdateTime(Long updateTime) { 210 | this.updateTime = updateTime; 211 | } 212 | 213 | @Override 214 | public String toString() { 215 | return new ToStringBuilder(this, BinanceApiConstants.TO_STRING_BUILDER_STYLE).append("orderId", orderId) 216 | .append("symbol", symbol).append("status", status).append("clientOrderId", clientOrderId) 217 | .append("price", price).append("averagePrice", averagePrice).append("origQty", origQty) 218 | .append("executedQty", executedQty).append("cumQuote", cumQuote).append("timeInForce", timeInForce) 219 | .append("type", type).append("reduceOnly", reduceOnly).append("closePosition", closePosition).append("side", side) 220 | .append("positionSide", positionSide).append("stopPrice", stopPrice).append("workingType", workingType) 221 | .append("origType", origType).append("time", time).append("updateTime", updateTime).toString(); 222 | } 223 | } 224 | --------------------------------------------------------------------------------