【发布时间】:2021-09-06 09:50:39
【问题描述】:
我有问题。我在我的项目中使用 Binance API。使用此 API,我打开烛台流以接收不同烛台时段的最新更新。烛台流方法位于如下所示的类中:
public class CandlestickStream {
private String market;
private String coin;
private String period;
public CandlestickStream(String market, String coin, String period) throws SecurityException, IOException {
this.market = market;
this.coin = coin;
this.period = period;
startCandlestickEventStreaming();
}
/**
* Starting a stream to get the current candlestick data of the given symbol and period
* @param symbol The symbol you want the data from
* @param interval The period of the candlestick
* @throws IOException
* @throws SecurityException
*/
public void startCandlestickEventStreaming() throws SecurityException, IOException {
BinanceApiWebSocketClient client = BinanceApiClientFactory.newInstance().newWebSocketClient();
String symbol = createSymbolString(market, coin);
CandlestickInterval interval = periodToInterval(period);
client.onCandlestickEvent(symbol, interval, response -> {
System.out.println(response);
});
}
}
使用以下代码开始流:
// Loop over every market-coin-period combination and start the firstrun and stream
for (String market : markets) {
for (String coin : coins) {
for (String period : periods) {
// Run candlestick stream to monitor if it's still running
new CandlestickStream(market, coin, period);
}
}
}
但我注意到 binance 可能会重新启动服务器,这会导致流功能停止,然后我将不会收到任何更新而不会出现任何错误。所以我需要一种方法来检查该功能是否仍在运行。如果没有,我需要重新启动它。控制进程以检查它是否仍在运行,如果没有,则重新启动类的最佳方法是什么?
【问题讨论】:
标签: java function process binance