Skip to content

phemex/java-client

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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 is https://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 your apiKey and apiSecret

  • PhemexClient::orders for orders related API, PhemexClient::account for Positions and Accounts 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

  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

About

Phemex Java Client SDK

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Languages