kucoin-java-sdk icon indicating copy to clipboard operation
kucoin-java-sdk copied to clipboard

Could not create more than one API client per application

Open duongvansang opened this issue 4 years ago • 5 comments

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,

duongvansang avatar Apr 15 '20 11:04 duongvansang

Have you fixed this issue now?

1bazinga25 avatar Sep 22 '20 02:09 1bazinga25

@1bazinga25 yes, I fixed at my local

duongvansang avatar Sep 22 '20 02:09 duongvansang

Great! May you figure out what is incorrect with this SDK?

1bazinga25 avatar Sep 22 '20 02:09 1bazinga25

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.

duongvansang avatar Sep 22 '20 03:09 duongvansang

Okay, I will try it later and thanks a lot!

1bazinga25 avatar Sep 22 '20 03:09 1bazinga25