@@ -4,6 +4,7 @@ import android.content.Context
44import androidx.lifecycle.MutableLiveData
55import crypto.delta.exchange.openexchange.pojo.DeltaExchangeChartHistoryResponse
66import crypto.delta.exchange.openexchange.pojo.OrderBookResponse
7+ import crypto.delta.exchange.openexchange.pojo.products.ProductsResponse
78import retrofit2.Call
89import retrofit2.Callback
910import retrofit2.Response
@@ -30,17 +31,19 @@ class DeltaRepository {
3031 .create(DeltaExchangeApiEndPoints ::class .java)
3132 }
3233
33- fun getChartHistory (resolution : String ): MutableLiveData <DeltaExchangeChartHistoryResponse ?> {
34+ fun getChartHistory (resolution : String , symbol : String ): MutableLiveData <DeltaExchangeChartHistoryResponse ?> {
3435 val data: MutableLiveData <DeltaExchangeChartHistoryResponse ?> = MutableLiveData <DeltaExchangeChartHistoryResponse ?>()
3536 val currentTime = TimeUnit .MILLISECONDS .toSeconds(System .currentTimeMillis())
36- deltaExchangeApiEndPoints!! .getChartHistory(" BTCUSD " , resolution, " 1105261585" , currentTime.toString()).enqueue(object :
37+ deltaExchangeApiEndPoints!! .getChartHistory(symbol , resolution, " 1105261585" , currentTime.toString()).enqueue(object :
3738 Callback <DeltaExchangeChartHistoryResponse ?> {
3839 override fun onResponse (
3940 call : Call <DeltaExchangeChartHistoryResponse ?>? ,
4041 response : Response <DeltaExchangeChartHistoryResponse ?>
4142 ) {
4243 if (response.isSuccessful) {
4344 data.value = response.body()
45+ } else {
46+ data.value = null
4447 }
4548 }
4649
@@ -51,23 +54,44 @@ class DeltaRepository {
5154 return data
5255 }
5356
54- fun getOrderBook (): MutableLiveData <OrderBookResponse ?> {
55- val newsData : MutableLiveData <OrderBookResponse ?> = MutableLiveData <OrderBookResponse ?>()
56- deltaExchangeApiEndPoints!! .getOrderBook(" 16 " ).enqueue(object :
57+ fun getOrderBook (productId : String ): MutableLiveData <OrderBookResponse ?> {
58+ val data : MutableLiveData <OrderBookResponse ?> = MutableLiveData <OrderBookResponse ?>()
59+ deltaExchangeApiEndPoints!! .getOrderBook(productId ).enqueue(object :
5760 Callback <OrderBookResponse ?> {
5861 override fun onResponse (
5962 call : Call <OrderBookResponse ?>? ,
6063 response : Response <OrderBookResponse ?>
6164 ) {
6265 if (response.isSuccessful) {
63- newsData.value = response.body()
66+ data.value = response.body()
67+ } else {
68+ data.value = null
6469 }
6570 }
6671
6772 override fun onFailure (call : Call <OrderBookResponse ?>? , t : Throwable ? ) {
68- newsData.value = null
73+ data.value = null
74+ }
75+ })
76+ return data
77+ }
78+
79+ fun getProducts (): MutableLiveData <List <ProductsResponse >> {
80+ val data: MutableLiveData <List <ProductsResponse >> = MutableLiveData <List <ProductsResponse >>()
81+ deltaExchangeApiEndPoints!! .getProducts().enqueue(object :
82+ Callback <List <ProductsResponse >> {
83+ override fun onResponse (call : Call <List <ProductsResponse >>? , response : Response <List <ProductsResponse >>) {
84+ if (response.isSuccessful) {
85+ data.value = response.body()
86+ } else {
87+ data.value = null
88+ }
89+ }
90+
91+ override fun onFailure (call : Call <List <ProductsResponse >>? , t : Throwable ? ) {
92+ data.value = null
6993 }
7094 })
71- return newsData
95+ return data
7296 }
7397}
0 commit comments