From c4278c7e75ea12a04e2ee76891e1848af230f515 Mon Sep 17 00:00:00 2001 From: henry Date: Tue, 7 Nov 2017 22:14:43 -0400 Subject: [PATCH] equivalent values in batch --- .../apigenerator/GrapheneApiGenerator.java | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/app/src/main/java/cy/agorise/crystalwallet/apigenerator/GrapheneApiGenerator.java b/app/src/main/java/cy/agorise/crystalwallet/apigenerator/GrapheneApiGenerator.java index aa824cd..138c060 100644 --- a/app/src/main/java/cy/agorise/crystalwallet/apigenerator/GrapheneApiGenerator.java +++ b/app/src/main/java/cy/agorise/crystalwallet/apigenerator/GrapheneApiGenerator.java @@ -4,6 +4,7 @@ import android.content.Context; import java.io.Serializable; import java.util.ArrayList; +import java.util.Date; import java.util.HashMap; import java.util.List; @@ -16,6 +17,7 @@ import cy.agorise.crystalwallet.models.BitsharesAsset; import cy.agorise.crystalwallet.models.BitsharesAssetInfo; import cy.agorise.crystalwallet.models.CryptoCoinBalance; import cy.agorise.crystalwallet.models.CryptoCurrency; +import cy.agorise.crystalwallet.models.CryptoCurrencyEquivalence; import cy.agorise.crystalwallet.network.WebSocketThread; import cy.agorise.graphenej.Address; import cy.agorise.graphenej.Asset; @@ -463,6 +465,9 @@ public abstract class GrapheneApiGenerator { @Override public void onSuccess(WitnessResponse response) { List orders = (List) response.result; + if(orders.size()<= 0){ + //TODO indirect equivalent value + } for(LimitOrder order : orders){ Converter converter = new Converter(); double equiValue = converter.getConversionRate(order.getSellPrice(),Converter.BASE_TO_QUOTE); @@ -479,4 +484,43 @@ public abstract class GrapheneApiGenerator { thread.start(); } + public static void getEquivalentValue(BitsharesAsset baseAsset, List quoteAssets,Context context){ + for(BitsharesAsset quoteAsset : quoteAssets){ + WebSocketThread thread = new WebSocketThread(new GetLimitOrders(baseAsset.getBitsharesId(), quoteAsset.getBitsharesId(), 10, new EquivalentValueListener(baseAsset,quoteAsset,context)),url); + thread.start(); + } + } + + private static class EquivalentValueListener implements WitnessResponseListener{ + private BitsharesAsset baseAsset; + private BitsharesAsset quoteAsset; + private Context context; + + public EquivalentValueListener(BitsharesAsset baseAsset, BitsharesAsset quoteAsset, Context context) { + this.baseAsset = baseAsset; + this.quoteAsset = quoteAsset; + this.context = context; + } + + @Override + public void onSuccess(WitnessResponse response) { + List orders = (List) response.result; + if(orders.size()<= 0){ + //TODO indirect equivalent value + } + for(LimitOrder order : orders){ + Converter converter = new Converter(); + double equiValue = converter.getConversionRate(order.getSellPrice(),Converter.BASE_TO_QUOTE); + CryptoCurrencyEquivalence equivalence = new CryptoCurrencyEquivalence(baseAsset.getId(),quoteAsset.getId(),(int)(Math.pow(10,baseAsset.getPrecision())*equiValue),new Date()); + CrystalDatabase.getAppDatabase(context).cryptoCurrencyEquivalenceDao().insertCryptoCurrencyEquivalence(equivalence); + break; + } + } + + @Override + public void onError(BaseResponse.Error error) { + + } + } + }