Skip to main content
Version: Next

Basics

Client instantiation

Every RestClient require an API key and a SECRET key in their constructor except for SpotVisionClient where every data is public.

MarketClient client = new MarketClient(key, secret);

Send a request

RestClient's methods don't make API calls, they return an instance of a Request able to make sync and async calls.

var req = client.getExchangeInfo();

//sync

try{
var res = req.sync();
}catch(ApiException e){
//...
}

// async

req.async((res, e)->{
if(e != null){
///...
}
});

Exception handling

Any error will throw an ApiException. Sync calls must be wrapped in a try catch and async calls return an ApiException in the callback.

try{
ExchangeInfo res = client.getExchangeInfo().sync();
}catch(ApiException e){
//...
}

Accessing headers

You can access the response headers by adding them as second parameter in the callback of an async call/

client.getExchangeInfo().async((response, headers, exception) -> {
if(exception == null){
//...
}else{
//...
}
});

Rate limiting

Rate limiting is enabled by default. Your first REST request will fetch the API rate limits and instantiate two limiters: one for the raw request limits and one for the request weight limits. It will then start a one second interval when exceeding the period limit will make the current thread sleep for the remaining time before the next one second period.

If you want to disable rate limiting:

RateLimiting.disable();

To enable rate limiting:

RateLimiting.enable();

To check rate limiting state:

RateLimiting.isEnabled();