Skip to content

Documentation

Andrey Vasilyev edited this page Mar 11, 2018 · 30 revisions

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.

Public API

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.

Info

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

Ticker

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

Depth

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

Trades

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

Also

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.

Trade API

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&param0=val0), signed with a Secret key using HMAC-SHA512.

GetInfo

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

Trade

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

ActiveOrders

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

OrderInfo

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

CancelOrder

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

TradeHistory

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

TransHistory

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

CoinDepositAddress

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

WithdrawCoin

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

CreateCoupon

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&currency=BTC&amount=0.1&receiver=user&nonce=0

RedeemCoupon

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

Push API

This API uses Pusher service.

Depth

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

Trades

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
});
Clone this wiki locally