0

我正在开发一个使用 API 从交易所获取加密货币数据的应用程序。我能够成功地获取和分析数据(使用 TA-LIB 计算 EMA、MA),但不确定在片段(用户界面)上绘制这些数据的最佳方式。这就像在片段上绘制实时加密数据。任何帮助表示赞赏。我的代码如下。

import com.binance.api.client.BinanceApiClientFactory;
import com.binance.api.client.BinanceApiRestClient;
import com.binance.api.client.domain.market.Candlestick;
import com.binance.api.client.domain.market.CandlestickInterval;
import com.tictactec.ta.lib.Core;
import com.tictactec.ta.lib.MInteger;

import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.TreeMap;
import java.util.stream.Collectors;

public class GET_EMA
{
    private Map<Long, Candlestick> candlesticksCache = new TreeMap<>();
    public static final int TOTAL_PERIODS=300;
    double[] result_ema=new double[TOTAL_PERIODS];
    private static double[] values;
    private static final int LOOKBACK = 10;
    private static final double EXTRA_VALUE = 100000;
    MInteger begin = new MInteger();
    MInteger length = new MInteger();
    private long m_LastOpenTime=0;

    public static void main(String[] pArgs)
    {
    }
    public GET_EMA(){
        //Default Constructor
    }
    public GET_EMA(String symbol,CandlestickInterval interval)
    {
        Locale.setDefault(Locale.US);
        Calculate_EMA(symbol,interval);
    }
    public String Calculate_EMA(String symbol, CandlestickInterval interval)
    {
        //Initialize Binance API
        BinanceApiClientFactory factory = BinanceApiClientFactory.newInstance();
        BinanceApiRestClient client = factory.newRestClient();
        //GET Required EMA Value
        List<Candlestick> candlestickBars = client.getCandlestickBars(symbol.toUpperCase(), interval, Integer.valueOf(TOTAL_PERIODS), null, null);
        List<Double> closingPriceList = candlestickBars.stream().map(c -> Double.valueOf(c.getClose())).collect(Collectors.toList());
    //        System.out.println("Total Candlesticks : "+candlestickBars.size());
//        System.out.println(Arrays.toString(closingPriceList.toArray()));
        double values[]=new double[closingPriceList.size()];
        for(int i=0;i<closingPriceList.size();i++)
        {
            values[i]=closingPriceList.get(i);
        }
            Core talib=new Core();
            int emaValue=26;
            int pos=TOTAL_PERIODS-emaValue;
            talib.ema(0,values.length-1,values,emaValue,begin,length,result_ema);
            String ema=String.valueOf(result_ema[pos]);
            return ema;
    }
}

我只想在片段上打印这个 ema 值,片段会不断更新。

4

0 回答 0