com.kucoin.sdk.factory.HttpClientFactory Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of kucoin-java-sdk Show documentation
Show all versions of kucoin-java-sdk Show documentation
Fixed fork of the official Kucoin SDK
The newest version!
/**
* Copyright 2019 Mek Global Limited.
*/
package com.kucoin.sdk.factory;
import com.kucoin.sdk.rest.interceptor.AuthenticationInterceptor;
import okhttp3.Dispatcher;
import okhttp3.Interceptor;
import okhttp3.OkHttpClient;
import java.util.concurrent.TimeUnit;
/**
* Created by chenshiwei on 2019/1/18.
*/
public class HttpClientFactory {
public static OkHttpClient getPublicClient() {
return buildHttpClient(null);
}
public static OkHttpClient getAuthClient(String apiKey, String secret, String passPhrase) {
return buildHttpClient(new AuthenticationInterceptor(apiKey, secret, passPhrase));
}
private static OkHttpClient buildHttpClient(Interceptor interceptor) {
Dispatcher dispatcher = new Dispatcher();
dispatcher.setMaxRequestsPerHost(100);
dispatcher.setMaxRequests(100);
OkHttpClient.Builder builder = new OkHttpClient.Builder()
.dispatcher(dispatcher)
.pingInterval(20, TimeUnit.SECONDS);
if (interceptor != null) {
builder.addInterceptor(interceptor);
}
return builder.build();
}
}