I tried to subscribe spot market data
@Test
public void positionTest() throws InterruptedException {
ExchangeInfo exchangeInfo = BinanceClient.spotSyncClient.getExchangeInfo();
String symbol = "btcusdt";
// spotSubscription.onDepthEvent(symbol);
// spotSubscription.symbolBookTickSubscription(symbol);
spotSubscription.allBookTickSubscription();
but only the allBookTickSubscription works well, the other two onDepthEvent and symbolBookTickSubscription cant receive any information in test . and all the three work well in prd.
and the other code like that
//订阅现货最新价格
public void symbolBookTickSubscription(String symbol){
BinanceClient.spotSubsptClient.onBookTickerEvent(symbol,bookTickerEvent -> {
HashMap map = new HashMap();
map.put(BeanConstant.BEST_ASK_PRICE,bookTickerEvent.getAskPrice());
map.put(BeanConstant.BEST_ASK_Qty,bookTickerEvent.getAskQuantity());
map.put(BeanConstant.BEST_BID_PRICE,bookTickerEvent.getBidPrice());
map.put(BeanConstant.BEST_BID_QTY,bookTickerEvent.getBidQuantity());
MarketCache.spotTickerMap.put(bookTickerEvent.getSymbol(),map);
logger.info("spot info:" + bookTickerEvent.toString());
// logger.info(" spot info:"+MarketCache.spotTickerMap.get(symbol).get(BeanConstant.BEST_ASK_PRICE));
});
}
public void onDepthEvent(String symbol){
BinanceClient.spotSubsptClient.onDepthEvent(symbol,event->{
System.out.println("depthEventP:"+event);
});
}
//订阅现货最新价格
public void allBookTickSubscription(){
BinanceClient.spotSubsptClient.onAllBookTickersEvent(bookTickerEvent -> {
HashMap map = new HashMap();
map.put(BeanConstant.BEST_ASK_PRICE,bookTickerEvent.getAskPrice());
map.put(BeanConstant.BEST_ASK_Qty,bookTickerEvent.getAskQuantity());
map.put(BeanConstant.BEST_BID_PRICE,bookTickerEvent.getBidPrice());
map.put(BeanConstant.BEST_BID_QTY,bookTickerEvent.getBidQuantity());
MarketCache.spotTickerMap.put(bookTickerEvent.getSymbol(),map);
String symbol = "BNBUSDT";
if(MarketCache.spotTickerMap.containsKey(symbol)){
logger.info(" spot price:"+MarketCache.spotTickerMap.get(symbol).get(BeanConstant.BEST_ASK_PRICE));
}
});
}