Java wrapper for Poloniex Exchange
DISCLAIMER:
USE AT YOUR OWN RISK. You should not use this code in production unless you fully understand its limitations.
Even if you understand the code and its limitations, you may incur losses when using this code for trading.
When used in combination with your own code, the combination may not function as intended, and as a result you may incur losses.
Poloniex is not responsible for any losses you may incur when using this code.
- Support for REST and websocket endpoints
- Simple handling of authentication
- Response exception handling
- Register an account with Poloniex.
- Generate an API Key.
- Get the source files.
- See code sample.
- Refer to the Javadocs.
- For license refer to LICENSE file
Clone the repo into the path you will be using:
git clone https://github.com/poloniex/polo-sdk-java
Add the following dependency to your Maven pom.xml file:
<dependency>
<groupId>com.poloniex.api</groupId>
<artifactId>polo-sdk-java</artifactId>
<version>1.0.0</version>
</dependency>
Clone the repo into the path you will be using:
git clone https://github.com/poloniex/polo-sdk-java
Build the jar and add to your local Maven repository using:
mvn install
Environment | Host URL |
---|---|
Production | https://api.poloniex.com |
PoloRestClient poloniexApiClient = new PoloRestClient(POLO_HOST_URL);
PoloRestClient poloniexApiClient = new PoloRestClient(POLO_HOST_URL, API_KEY, SECRET);
Environment | Type | Host URL |
---|---|---|
Production | Public | wss://ws.poloniex.com/ws/public |
Production | Authenticated | wss://ws.poloniex.com/ws/private |
OkHttpClient httpClient = new OkHttpClient.Builder().build();
PoloPublicWebsocket publicWebsocket = new PoloPublicWebsocket(httpClient, POLO_PUBLIC_WS_URL);
If you don't pass in an OkHttpClient, one will be created for you
PoloPublicWebsocket publicWebsocket = new PoloPublicWebsocket(POLO_PUBLIC_WS_URL);
OkHttpClient httpClient = new OkHttpClient.Builder().build();
PoloPrivateWebsocket privateWebsocket = new PoloPrivateWebsocket(httpClient, POLO_PRIVATE_WS_URL, API_KEY, SECRET);
If you don't pass in an OkHttpClient, one will be created for you
PoloPrivateWebsocket publicWebsocket = new PoloPrivateWebsocket(POLO_PRIVATE_WS_URL);
// get all markets
List<Market> allMarkets = poloniexApiClient.getMarkets();
// get info about BTC_USDT market
poloniexApiClient.getMarket("BTC_USDT")
// get current price of BTC_USDT
Price btcUsdtPrice = poloniexApiClient.getPrice("BTC_USDT");
// place buy order for BTC_USDT
Order order = poloniexApiClient.placeOrder("BTC_USDT", "BUY", "GTC", "LIMIT", "SPOT", "30000", "1", "", System.currentTimeMillis());
// get order id
String orderId = order.getId();
// get order info by id
Order returnedOrder = poloniexApiClient.getOrderByOrderId(orderId);
// cancel order by id
CanceledOrder canceledOrder = poloniexApiClient.cancelOrderByOrderId(orderId);
PoloApiCallback<TickerEvent> callback = new PoloApiCallback<>() {
@Override
public void onResponse(PoloEvent<TickerEvent> response) {
// logic to process ticker data here
log.info(response.getData().get(0).getClose());
}
@Override
public void onFailure(Throwable t) {
log.warn("error",t);
}
};
publicWebsocket.onTickerEvent(List.of("TRX_USDT"), callback);
Using callback class:
publicWebsocket.onTickerEvent(List.of("TRX_USDT"), new PoloLoggingCallback<>());
privateWebsocket.onOrderEvent(List.of("all"), new PoloLoggingCallback<>());