Spot
Installation
- Maven
- Gradle
pom.xml
<dependency>
<groupId>{{groupId}}</groupId>
<artifactId>{{artifactId}}</artifactId>
<version>{{version}}</version>
</dependency>
build.gradle
implementation '{{groupId}}:{{artifactId}}:{{version}}'
Client instantiation
SpotClient client = new SpotClient(key, secret);
Testnet client instantiation
TestnetSpotClient client = new TestnetSpotClient(testnetKey, testnetSecret);
Features
Send a Market order.
- BUY
- SELL
- Sync
- Async
try{
NewOrderResponse res = client.newOrder(MarketOrder.buy(symbol, quantity)).sync();
}catch(ApiException e){
//...
}
client.newOrder(MarketOrder.buy(symbol, quantity)).async((response, exception) -> {
if(exception == null){
//...
}else{
//...
}
});
- Sync
- Async
try{
NewOrderResponse res = client.newOrder(MarketOrder.sell(symbol, quantity)).sync();
}catch(ApiException e){
//...
}
client.newOrder(MarketOrder.sell(symbol, quantity)).async((response, exception) -> {
if(exception == null){
//...
}else{
//...
}
});
Send a Market Quote order.
- BUY
- SELL
- Sync
- Async
try{
NewOrderResponse res = client.newOrder(MarketQuoteOrder.buy(symbol, quoteAssetQty)).sync();
}catch(ApiException e){
//...
}
client.newOrder(MarketQuoteOrder.buy(symbol, quoteAssetQty)).async((response, exception) -> {
if(exception == null){
//...
}else{
//...
}
});
- Sync
- Async
try{
NewOrderResponse res = client.newOrder(MarketQuoteOrder.sell(symbol, quoteAssetQty)).sync();
}catch(ApiException e){
//...
}
client.newOrder(MarketQuoteOrder.sell(symbol, quoteAssetQty)).async((response, exception) -> {
if(exception == null){
//...
}else{
//...
}
});
Send a Limit order.
- BUY
- SELL
- BUY (TimeInForce.GTC)
- SELL (TimeInForce.GTC)
- Sync
- Async
try{
NewOrderResponse res = client.newOrder(LimitOrder.buy(symbol, quantity, price, timeInForce)).sync();
}catch(ApiException e){
//...
}
client.newOrder(LimitOrder.buy(symbol, quantity, price, timeInForce)).async((response, exception) -> {
if(exception == null){
//...
}else{
//...
}
});
- Sync
- Async
try{
NewOrderResponse res = client.newOrder(LimitOrder.sell(symbol, quantity, price, timeInForce)).sync();
}catch(ApiException e){
//...
}
client.newOrder(LimitOrder.sell(symbol, quantity, price, timeInForce)).async((response, exception) -> {
if(exception == null){
//...
}else{
//...
}
});
- Sync
- Async
try{
NewOrderResponse res = client.newOrder(LimitOrder.buy(symbol, quantity, price)).sync();
}catch(ApiException e){
//...
}
client.newOrder(LimitOrder.buy(symbol, quantity, price)).async((response, exception) -> {
if(exception == null){
//...
}else{
//...
}
});
- Sync
- Async
try{
NewOrderResponse res = client.newOrder(LimitOrder.sell(symbol, quantity, price)).sync();
}catch(ApiException e){
//...
}
client.newOrder(LimitOrder.sell(symbol, quantity, price)).async((response, exception) -> {
if(exception == null){
//...
}else{
//...
}
});
Send a Limit Maker order.
- BUY (TimeInForce.GTC)
- SELL (TimeInForce.GTC)
- Sync
- Async
try{
NewOrderResponse res = client.newOrder(LimitMakerOrder.buy(symbol, quantity, price)).sync();
}catch(ApiException e){
//...
}
client.newOrder(LimitMakerOrder.buy(symbol, quantity, price)).async((response, exception) -> {
if(exception == null){
//...
}else{
//...
}
});
- Sync
- Async
try{
NewOrderResponse res = client.newOrder(LimitMakerOrder.sell(symbol, quantity, price)).sync();
}catch(ApiException e){
//...
}
client.newOrder(LimitMakerOrder.sell(symbol, quantity, price)).async((response, exception) -> {
if(exception == null){
//...
}else{
//...
}
});
Send a Stop Loss order.
- BUY (Stop price)
- SELL (Stop price)
- BUY (Trailing delta)
- SELL (Trailing delta)
- Sync
- Async
try{
NewOrderResponse res = client.newOrder(StopLossOrder.buy(symbol, quantity, stopPrice)).sync();
}catch(ApiException e){
//...
}
client.newOrder(StopLossOrder.buy(symbol, quantity, stopPrice)).async((response, exception) -> {
if(exception == null){
//...
}else{
//...
}
});
- Sync
- Async
try{
NewOrderResponse res = client.newOrder(StopLossOrder.sell(symbol, quantity, stopPrice)).sync();
}catch(ApiException e){
//...
}
client.newOrder(StopLossOrder.sell(symbol, quantity, stopPrice)).async((response, exception) -> {
if(exception == null){
//...
}else{
//...
}
});
- Sync
- Async
try{
NewOrderResponse res = client.newOrder(StopLossOrder.buy(symbol, quantity, trailingDelta)).sync();
}catch(ApiException e){
//...
}
client.newOrder(StopLossOrder.buy(symbol, quantity, trailingDelta)).async((response, exception) -> {
if(exception == null){
//...
}else{
//...
}
});
- Sync
- Async
try{
NewOrderResponse res = client.newOrder(StopLossOrder.sell(symbol, quantity, trailingDelta)).sync();
}catch(ApiException e){
//...
}
client.newOrder(StopLossOrder.sell(symbol, quantity, trailingDelta)).async((response, exception) -> {
if(exception == null){
//...
}else{
//...
}
});
Send a Stop Loss Limit order.
- BUY
- SELL
- BUY (TimeInForce.GTC)
- SELL (TimeInForce.GTC)
- Sync
- Async
try{
NewOrderResponse res = client.newOrder(StopLossOrder.buy(symbol, quantity, price, stopPrice, timeInForce)).sync();
}catch(ApiException e){
//...
}
client.newOrder(StopLossOrder.buy(symbol, quantity, price, stopPrice, timeInForce)).async((response, exception) -> {
if(exception == null){
//...
}else{
//...
}
});
- Sync
- Async
try{
NewOrderResponse res = client.newOrder(StopLossOrder.sell(symbol, quantity, price, stopPrice, timeInForce)).sync();
}catch(ApiException e){
//...
}
client.newOrder(StopLossOrder.sell(symbol, quantity, price, stopPrice, timeInForce)).async((response, exception) -> {
if(exception == null){
//...
}else{
//...
}
});
- Sync
- Async
try{
NewOrderResponse res = client.newOrder(StopLossOrder.buy(symbol, quantity, price, stopPrice)).sync();
}catch(ApiException e){
//...
}
client.newOrder(StopLossOrder.buy(symbol, quantity, price, stopPrice)).async((response, exception) -> {
if(exception == null){
//...
}else{
//...
}
});
- Sync
- Async
try{
NewOrderResponse res = client.newOrder(StopLossOrder.sell(symbol, quantity, price, stopPrice)).sync();
}catch(ApiException e){
//...
}
client.newOrder(StopLossOrder.sell(symbol, quantity, price, stopPrice)).async((response, exception) -> {
if(exception == null){
//...
}else{
//...
}
});
Send a Take Profit order.
- BUY (Stop price)
- SELL (Stop price)
- BUY (Trailing delta)
- SELL (Trailing delta)
- Sync
- Async
try{
NewOrderResponse res = client.newOrder(TakeProfitOrder.buy(symbol, quantity, stopPrice)).sync();
}catch(ApiException e){
//...
}
client.newOrder(TakeProfitOrder.buy(symbol, quantity, stopPrice)).async((response, exception) -> {
if(exception == null){
//...
}else{
//...
}
});
- Sync
- Async
try{
NewOrderResponse res = client.newOrder(TakeProfitOrder.sell(symbol, quantity, stopPrice)).sync();
}catch(ApiException e){
//...
}
client.newOrder(TakeProfitOrder.sell(symbol, quantity, stopPrice)).async((response, exception) -> {
if(exception == null){
//...
}else{
//...
}
});
- Sync
- Async
try{
NewOrderResponse res = client.newOrder(TakeProfitOrder.buy(symbol, quantity, trailingDelta)).sync();
}catch(ApiException e){
//...
}
client.newOrder(TakeProfitOrder.buy(symbol, quantity, trailingDelta)).async((response, exception) -> {
if(exception == null){
//...
}else{
//...
}
});
- Sync
- Async
try{
NewOrderResponse res = client.newOrder(TakeProfitOrder.sell(symbol, quantity, trailingDelta)).sync();
}catch(ApiException e){
//...
}
client.newOrder(TakeProfitOrder.sell(symbol, quantity, trailingDelta)).async((response, exception) -> {
if(exception == null){
//...
}else{
//...
}
});
Send a Take Profit Limit order.
- BUY
- SELL
- BUY (TimeInForce.GTC)
- SELL (TimeInForce.GTC)
- Sync
- Async
try{
NewOrderResponse res = client.newOrder(TakeProfitLimitOrder.buy(symbol, quantity, price, stopPrice, timeInForce)).sync();
}catch(ApiException e){
//...
}
client.newOrder(TakeProfitLimitOrder.buy(symbol, quantity, price, stopPrice, timeInForce)).async((response, exception) -> {
if(exception == null){
//...
}else{
//...
}
});
- Sync
- Async
try{
NewOrderResponse res = client.newOrder(TakeProfitLimitOrder.sell(symbol, quantity, price, stopPrice, timeInForce)).sync();
}catch(ApiException e){
//...
}
client.newOrder(TakeProfitLimitOrder.sell(symbol, quantity, price, stopPrice, timeInForce)).async((response, exception) -> {
if(exception == null){
//...
}else{
//...
}
});
- Sync
- Async
try{
NewOrderResponse res = client.newOrder(TakeProfitLimitOrder.buy(symbol, quantity, price, stopPrice)).sync();
}catch(ApiException e){
//...
}
client.newOrder(TakeProfitLimitOrder.buy(symbol, quantity, price, stopPrice)).async((response, exception) -> {
if(exception == null){
//...
}else{
//...
}
});
- Sync
- Async
try{
NewOrderResponse res = client.newOrder(TakeProfitLimitOrder.sell(symbol, quantity, price, stopPrice)).sync();
}catch(ApiException e){
//...
}
client.newOrder(TakeProfitLimitOrder.sell(symbol, quantity, price, stopPrice)).async((response, exception) -> {
if(exception == null){
//...
}else{
//...
}
});
Test an order
newOrderTest
works like newOrder
.
- Sync
- Async
try{
client.newOrderTest(MarketOrder.buy(symbol, quantity)).sync();
}catch(ApiException e){
//...
}
client.newOrderTest(MarketOrder.buy(symbol, quantity)).async((response, exception) -> {
if(exception == null){
//...
}else{
//...
}
});
note
buyQuote
and sellQuote
let you buy the base asset by providing the quote asset amount.
Get open orders
- Sync
- Async
try{
List<OrderInfo> res = client.getOpenOrders().sync();
}catch(ApiException e){
//...
}
client.getOpenOrders().async((response, exception) -> {
if(exception == null){
//...
}else{
//...
}
});
Cancel open orders
- Sync
- Async
try{
List<CancelOrderResponse> res = client.cancelOpenOrders(new CancelOpenOrdersParams(symbol)).sync();
}catch(ApiException e){
//...
}
client.cancelOpenOrders(new CancelOpenOrdersParams(symbol)).async((response, exception) -> {
if(exception == null){
//...
}else{
//...
}
});
Check an order's status
- Sync
- Async
try{
OrderInfo res = client.getOrderStatus(new OrderStatusParams(symbol, orderId)).sync();
}catch(ApiException e){
//...
}
client.getOrderStatus(new OrderStatusParams(symbol, orderId)).async((response, exception) -> {
if(exception == null){
//...
}else{
//...
}
});
Cancel an active order
- Sync
- Async
try{
CancelOrderResponse res = client.cancelOrder(new CancelOrderParams(symbol, orderId)).sync();
}catch(ApiException e){
//...
}
client.cancelOrder(new CancelOrderParams(symbol, orderId)).async((response, exception) -> {
if(exception == null){
//...
}else{
//...
}
});
Displays the user's current order count usage for all intervals with default request
- Sync
- Async
try{
List<OrderCount> res = client.getOrderCount().sync();
}catch(ApiException e){
//...
}
client.getOrderCount().async((response, exception) -> {
if(exception == null){
//...
}else{
//...
}
});
Get current account information
- Sync
- Async
try{
Account res = client.getAccount().sync();
}catch(ApiException e){
//...
}
client.getAccount().async((response, exception) -> {
if(exception == null){
//...
}else{
//...
}
});
Get all orders on a symbol
- By symbol
- By symbol and order id
- Sync
- Async
try{
List<OrderInfo> res = client.getAllOrders(new AllOrdersParams(symbol)).sync();
}catch(ApiException e){
//...
}
client.getAllOrders(new AllOrdersParams(symbol)).async((response, exception) -> {
if(exception == null){
//...
}else{
//...
}
});
- Sync
- Async
try{
List<OrderInfo> res = client.getAllOrders(new AllOrdersParams(symbol, orderId)).sync();
}catch(ApiException e){
//...
}
client.getAllOrders(new AllOrdersParams(symbol, orderId)).async((response, exception) -> {
if(exception == null){
//...
}else{
//...
}
});
Get trades for a specific account and symbol.
- From id
- By symbol and order id
- Sync
- Async
try{
List<Trade> res = client.getTrades(new TradesParams(fromId, symbol)).sync();
}catch(ApiException e){
//...
}
client.getTrades(new TradesParams(fromId, symbol)).async((response, exception) -> {
if(exception == null){
//...
}else{
//...
}
});
- Sync
- Async
try{
List<Trade> res = client.getTrades(new TradesParams(symbol, orderId)).sync();
}catch(ApiException e){
//...
}
client.getTrades(new TradesParams(symbol, orderId)).async((response, exception) -> {
if(exception == null){
//...
}else{
//...
}
});
Send in an OCO order
- Sync
- Async
try{
OCOResponse res = client.newOCO(NewOCOOrderParams(symbol, side, quantity, price, stopPrice, stopLimitPrice, stopLimitTimeInForce)).sync();
}catch(ApiException e){
//...
}
client.newOCO(NewOCOOrderParams(symbol, side, quantity, price, stopPrice, stopLimitPrice, stopLimitTimeInForce)).async((response, exception) -> {
if(exception == null){
//...
}else{
//...
}
});
Cancel an entire order list
- By order id
- By client order id
- Sync
- Async
try{
OCOResponse res = client.cancelOCO(new CancelOCOParams(symbol, orderListId)).sync();
}catch(ApiException e){
//...
}
client.cancelOCO(new CancelOCOParams(symbol, orderListId)).async((response, exception) -> {
if(exception == null){
//...
}else{
//...
}
});
- Sync
- Async
try{
OCOResponse res = client.cancelOCO(new CancelOCOParams(symbol, listClientOrderId)).sync();
}catch(ApiException e){
//...
}
client.cancelOCO(new CancelOCOParams(symbol, listClientOrderId)).async((response, exception) -> {
if(exception == null){
//...
}else{
//...
}
});
Retrieves all OCO
- Default
- By order id
- Framed
- Sync
- Async
try{
List<OCOInfo> res = client.getAllOCO().sync();
}catch(ApiException e){
//...
}
client.getAllOCO().async((response, exception) -> {
if(exception == null){
//...
}else{
//...
}
});
- Sync
- Async
try{
List<OCOInfo> res = client.getAllOCO(new AllOCOInfoParams(orderId)).sync();
}catch(ApiException e){
//...
}
client.getAllOCO(new AllOCOInfoParams(orderId)).async((response, exception) -> {
if(exception == null){
//...
}else{
//...
}
});
- Sync
- Async
try{
List<OCOInfo> res = client.getAllOCO(new AllOCOInfoParams(new TimeFrame(startTime, endTime, limit))).sync();
}catch(ApiException e){
//...
}
client.getAllOCO(new AllOCOInfoParams(new TimeFrame(startTime, endTime, limit))).async((response, exception) -> {
if(exception == null){
//...
}else{
//...
}
});