Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Could not create more than one API client per application #18

Open
duongvansang opened this issue Apr 15, 2020 · 5 comments
Open

Could not create more than one API client per application #18

duongvansang opened this issue Apr 15, 2020 · 5 comments

Comments

@duongvansang
Copy link

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,

@1bazinga25
Copy link
Contributor

Have you fixed this issue now?

@duongvansang
Copy link
Author

@1bazinga25 yes, I fixed at my local

@1bazinga25
Copy link
Contributor

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

@duongvansang
Copy link
Author

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.

@1bazinga25
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants