Awesome
Phemex Exchange Java API
- Phemex Java API provides Trading Rest APIs and WebSocket to the exchange, a full list of APIs is in the official documentation.
- API Key & Secret is created in the exchange website or testnet (https://testnet.phemex.com)
- API Base path of exchange is
https://api.phemex.com
, testnet ishttps://testnet-api.phemex.com
Building from Source
Prerequisites
- Java 1.8+
- Gradle 5.6+
Compile And Test
gradle build
Quick Start
-
Create a
PhemexClient
with yourapiKey
andapiSecret
-
PhemexClient::orders
for orders related API,PhemexClient::account
forPositions
andAccounts
related API,PhemexClient::createWebSocketClient
for WebSocket -
Create a PhemexClient
PhemexClient createPhemexClient() {
String apiKey = "YOUR_API_KEY";
String apiSecret = "YOUR_API_SECRET";
return PhemexClient.builder()
.apiKey(apiKey)
.apiSecret(apiSecret)
.url(url)
.connectionTimeout(Duration.ofSeconds(600))
.expiryDuration(Duration.ofSeconds(60))
.wsUri(wsUri)
.messageListener(new PhemexMessageListener() {
@Override
public void onMessage(String json) {
log.info("websocket received msg {}", json);
}
@Override
public void onError(Exception ex) {
log.info("websocket got error ", ex);
}
})
.build();
}
- Create an order
// create a order
void placeOrder() {
PhemexResponse<OrderModelVo> res = this.phemexClient.orders().createOrder(CreateOrderRequest.builder()
.symbol(symbol)
.clOrdID(UUID.randomUUID().toString())
.orderQty(1L)
.priceEp(80_000_000L)
.side(Side.Buy)
.build()).get(5, TimeUnit.SECONDS);
}
- WebSocket subscribe user accounts, positions, orders and trades
void subscribeAop() {
this.webSocketClient = this.phemexClient.createWebSocketClient();
webSocketClient.connectBlocking(5, TimeUnit.SECONDS);
webSocketClient.login();
this.webSocketClient.subscribeAccountDetails();
}
Documentation
Rest Feature List
- Place Order
- Amend Order by OrderID
- Cancel Single Order by OrderID
- Cancel All Orders by Symbol
- Query Trading Account and Positions
- Change Position Leverage
- Change Position Risklimt
- Assign Position Balance in Isolated Margin Mode
- Query Open Orders by Symbol
- Query Closed Orders by Symbol
- Query Order by orderID
- Query User Trades by Symbol
WebSocket Feature List
- API User Authentication
- Subscribe OrderBook
- Subscribe Trade
- Subscribe Account-Order-Position (AOP)
- Subscribe symbol price