I get a list of the index composition (102 tickers) and I want to find out detailed information about them, but out of 102 queries, no more than 10 are always executed, and the ticker is randomly selected. All requests are executed via retrofit2 using RxJava3. What could be the problem? Here is the ViewModel code:
var price: MutableLiveData<CompanyInfoModel> = MutableLiveData()
fun getCompanyInfoObserver(): MutableLiveData<CompanyInfoModel> {
return price
}
fun makeApiCall(ticker: String) {
val retrofitInstance = RetrofitYahooFinanceInstance.getRetrofitInstance().create(RetrofitService::class.java)
retrofitInstance.getCompanyInfo(ticker)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(getCompanyInfoObserverRx())
}
private fun getCompanyInfoObserverRx(): Observer<CompanyInfoModel> {
return object : Observer<CompanyInfoModel> {
override fun onComplete() {
// Hide progress bar
}
override fun onError(e: Throwable?) {
price.postValue(null)
}
override fun onNext(t: CompanyInfoModel?) {
price.postValue(t)
}
override fun onSubscribe(d: Disposable?) {
// Show progress bar
}
}
}
Here is the initialization of the model:
companyInfoModel = ViewModelProvider(this).get(CompanyInfoViewModel::class.java)
companyInfoModel.getCompanyInfoObserver().observe(this, Observer<CompanyInfoModel> { it ->
if(it != null) {
retrieveList(Helper.companyInfoToStock(it))
}
else {
Log.e(TAG, "Error in fetching data")
}
})
And here is the request method itself:
fun getCompanyInfo(ticker: String) {
companyInfoModel.makeApiCall(ticker)
}