GithubHelp home page GithubHelp logo

java-client's Introduction

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

java-client's People

Contributors

phemex avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.