kucoin-java-sdk
kucoin-java-sdk copied to clipboard
Could not create more than one API client per application
When I tried to monitor balance and orders or 2 apis (maybe more) in the same application; I find that, order and balance is always of the first api is set even you create many restclient
KucoinClientBuilder builder = new KucoinClientBuilder()
.withBaseUrl(kucoinRestEnpoint)
.withApiKey(user.getApi(), user.getSecretKey(), user.getPassPhrase());
So I checked through API code and see issue at RetrofitFactory class
private static volatile boolean authInited;
private static Retrofit authRetrofit;
public static Retrofit getAuthRetorfit(String baseUrl, String apiKey, String secret, String passPhrase) {
if (authInited)
return authRetrofit;
synchronized (RetrofitFactory.class) {
if (authInited)
return authRetrofit;
authInited = true;
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(baseUrl)
.addConverterFactory(CONVERTER_FACTORY)
.client(HttpClientFactory.getAuthClient(apiKey, secret, passPhrase))
.build();
authRetrofit = retrofit;
return retrofit;
}
}
This class should not be singleton one. This one should return are many retrofit as request (real factory). Singleton pattern should apply at application level, it's much more flexible and useful,
Thanks,
Have you fixed this issue now?
@1bazinga25 yes, I fixed at my local
Great! May you figure out what is incorrect with this SDK?
as I described about, RetrofitFactory class should be changed little bit to let user create new Retrofit with new apikey pair or new KucoinRestClient object.
Okay, I will try it later and thanks a lot!