-
Notifications
You must be signed in to change notification settings - Fork 2
Documentation
You should use check() after creation new WexClient's instance. Code:
WexClient client = new WexClient("https://wex.com");
try {
client.check();
} catch (IOException e) {
// something wrong! it can be an incorrect url or something simular
}
There are three parts of API: public, trade and push. Official documentation Public, Trade, Push or Public, Trade, Push.
This API provides access to such information as tickers of currency pairs, active orders on different pairs, the latest trades for each pair etc. The library uses 3th version of Public API.
This method provides all the information about currently active pairs, such as the maximum number of digits after the decimal point, the minimum price, the maximum price, the minimum transaction size, whether the pair is hidden, the commission for each pair.
Code:
Info info = new WexClient("https://wex.com").publicApi().getInfo();
Equals request:
GET https://wex.com/api/3/info
This method provides all the information about currently active pairs, such as: the maximum price, the minimum price, average price, trade volume, trade volume in currency, the last trade, Buy and Sell price. All information is provided over the past 24 hours.
Code:
Map<String, Ticker> tickers = new WexClient("https://wex.com")
.publicApi()
.getTicker("btc_usd")
.execute();
Equals request:
GET https://wex.com/api/3/ticker/btc_usd
This method provides the information about active orders on the pair.
Code:
Map<String, Depth> depths = new WexClient("https://wex.com")
.publicApi()
.getDepth("btc_usd")
.execute();
Equals request:
GET https://wex.com/api/3/depth/btc_usd
This method provides the information about the last trades.
Code:
Map<String, List<Trade>> tradeMap = new WexClient("https://wex.com")
.publicApi()
.getTrade("btc_usd")
.execute();
Equals request:
GET https://wex.com/api/3/trades/btc_usd
All methods with execute() can have additional parameters. For example:
new WexClient("https://wex.com")
.publicApi()
.getDepth("btc_usd")
.setLimit(1) // indicates how many orders should be displayed
.ignoreInvalid() // request has no error for a non-existent pair
.execute();
The maximum allowable value of setLimit() is 5000.
To use this API, you need to create an API key.
An API key can be created in your Profile in the API Keys section. After creating an API key you'll receive a key and a secret. API key examples: 46G9R9D6-WJ77XOIP-XH9HH5VQ-A3XN3YOZ-8T1R8I8T.
Note that the Secret can be received only during the first hour after the creation of the Key.
API key information is used for authentication.
Important things:
- nonce - parameter with incremental numeric value for each request. To reset the nonce value you need to create a new key.
-
Sign — Signature. POST-parameters (
nonce=1¶m0=val0), signed with a Secret key using HMAC-SHA512.
Returns information about the user’s current balance, API-key privileges, the number of open orders and Server Time.
Code:
GetInfo info = new WexClient("https://wex.com", key, secret)
.tradeApi()
.getInfo();
Equals request:
POST https://wex.com/tapi
HEADERS:
Key -> <API-key from account>
Sign -> <From all parameters from request's body and secret-key from account>
BODY:
method=getInfo&nonce=0
The basic method that can be used for creating orders and trading on the exchange.
Code:
Trade trade = new WexClient("https://wex.com", key, secret)
.tradeApi()
.trade(
"btc_usd",
OrderType.BUY,
BigDecimal.valueOf(100.0),
BigDecimal.valueOf(1.0)
);
Equals request:
POST https://wex.com/tapi
HEADERS:
Key -> <API-key from account>
Sign -> <From all parameters from request's body and secret-key from account>
BODY:
method=Trade&pair=btc_usd&type=buy&rate=100.0&amount=1.0&nonce=0
Returns the list of your active orders.
Code:
ActiveOrders orders = new WexClient("https://wex.com", key, secret)
.tradeApi()
.activeOrders("btc_usd");
Equals request:
POST https://wex.com/tapi
HEADERS:
Key -> <API-key from account>
Sign -> <From all parameters from request's body and secret-key from account>
BODY:
method=ActiveOrders&pair=btc_usd&nonce=0
Returns the information on particular order.
Code:
OrderInfo info = new WexClient("https://wex.com", key, secret)
.tradeApi()
.orderInfo(12345);
Equals request:
POST https://wex.com/tapi
HEADERS:
Key -> <API-key from account>
Sign -> <From all parameters from request's body and secret-key from account>
BODY:
method=OrderInfo&order_id=12345&nonce=0
This method is used for order cancelation.
Code:
CancelOrder cancel = new WexClient("https://wex.com", key, secret)
.tradeApi()
.cancelOrder(12345);
Equals request:
POST https://wex.com/tapi
HEADERS:
Key -> <API-key from account>
Sign -> <From all parameters from request's body and secret-key from account>
BODY:
method=CancelOrder&order_id=12345&nonce=0
Returns trade history.
Code:
TradeHistory history = new WexClient("https://wex.com", key, secret)
.tradeApi()
.tradeHistory()
.from(1234)
.count(1)
.fromId(1234)
.endId(1234)
.order(SortOrder.DESC) // sorting
.since(1234) // the time to start the display
.end(1234) // the time to end the display
.pair("btc_usd") // pair to be displayed
.execute();
Equals request:
POST https://wex.com/tapi
HEADERS:
Key -> <API-key from account>
Sign -> <From all parameters from request's body and secret-key from account>
BODY:
method=TradeHistory&from=12345&count=1&from_id=1234&end_id=1234&order=desc&since=1234&end=1234&pair=btc_usd&nonce=0
Returns the history of transactions.
Code:
TransactionsHistory history = new WexClient("https://wex.com", key, secret)
.tradeApi()
.transactionsHistory()
.from(1234)
.count(1)
.fromId(1234)
.endId(1234)
.order(SortOrder.DESC)
.since(1234)
.end(1234)
.execute();
Equals request:
POST https://wex.com/tapi
HEADERS:
Key -> <API-key from account>
Sign -> <From all parameters from request's body and secret-key from account>
BODY:
method=TransHistory&from=12345&count=1&from_id=1234&end_id=1234&order=desc&since=1234&end=1234&nonce=0
This method can be used to retrieve the address for depositing crypto-currency.
Code:
CoinDepositAddress address = new WexClient("https://wex.com", key, secret)
.tradeApi()
.coinDepositAddress("BTC");
Equals request:
POST https://wex.com/tapi
HEADERS:
Key -> <API-key from account>
Sign -> <From all parameters from request's body and secret-key from account>
BODY:
method=CoinDepositAddress&coinName=BTC&nonce=0
The method is designed for cryptocurrency withdrawals.
Code:
WithdrawCoin withdrawCoin = new WexClient("https://wex.com", key, secret)
.tradeApi()
.withdrawCoin("BTC", 0.1, "QWERTY123456");
Equals request:
POST https://wex.com/tapi
HEADERS:
Key -> <API-key from account>
Sign -> <From all parameters from request's body and secret-key from account>
BODY:
method=WithdrawCoin&coinName=BTC&amount=0.1&address=QWERTY123456&nonce=0
This method allows you to create Coupons.
Code:
CreateCoupon createCoupon = new WexClient("https://wex.com", key, secret)
.tradeApi()
.createCoupon("BTC", 0.1, "user");
Equals request:
POST https://wex.com/tapi
HEADERS:
Key -> <API-key from account>
Sign -> <From all parameters from request's body and secret-key from account>
BODY:
method=CreateCoupon¤cy=BTC&amount=0.1&receiver=user&nonce=0
This method is used to redeem coupons.
Code:
RedeemCoupon redeemCoupon = new WexClient("https://wex.com", key, secret)
.tradeApi()
.redeemCoupon("WEXUSD1234");
Equals request:
POST https://wex.com/tapi
HEADERS:
Key -> <API-key from account>
Sign -> <From all parameters from request's body and secret-key from account>
BODY:
method=RedeemCoupon&coupon=WEXUSD1234&nonce=0
This API uses Pusher service.
This channel provides the information about changes of active orders.
Code:
WexClient client = new WexClient("https://wex.com", key, secret);
client.pushApi().subscribeToDepth("btc_usd", pushDepth -> {
// do something
});
This channel provides the information about new trades.
Code:
WexClient client = new WexClient("https://wex.com", key, secret);
client.pushApi().subscribeToTrade("btc_usd", pushTrades -> {
// do something
});