Home

Awesome

Phemex Exchange Java API

Building from Source

Prerequisites

Compile And Test

gradle build

Quick Start

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 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);
}

void subscribeAop() {
    this.webSocketClient = this.phemexClient.createWebSocketClient();
    webSocketClient.connectBlocking(5, TimeUnit.SECONDS);
    webSocketClient.login();
    this.webSocketClient.subscribeAccountDetails();
}

Documentation

Rest Feature List

  1. Place Order
  2. Amend Order by OrderID
  3. Cancel Single Order by OrderID
  4. Cancel All Orders by Symbol
  5. Query Trading Account and Positions
  6. Change Position Leverage
  7. Change Position Risklimt
  8. Assign Position Balance in Isolated Margin Mode
  9. Query Open Orders by Symbol
  10. Query Closed Orders by Symbol
  11. Query Order by orderID
  12. Query User Trades by Symbol

WebSocket Feature List

  1. API User Authentication
  2. Subscribe OrderBook
  3. Subscribe Trade
  4. Subscribe Account-Order-Position (AOP)
  5. Subscribe symbol price