| | |
| | | import com.google.gson.Gson; |
| | | import com.google.gson.JsonSyntaxException; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.example.geteclient.GeteClientApplication; |
| | | import org.example.geteclient.comm.ApplicationContextProvider; |
| | | import org.example.geteclient.pojo.Currency; |
| | | import org.example.geteclient.util.RedisUtil; |
| | | import org.json.JSONException; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.boot.SpringApplication; |
| | | import org.springframework.context.ApplicationContext; |
| | | import org.springframework.context.ConfigurableApplicationContext; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import javax.websocket.*; |
| | | import java.math.BigDecimal; |
| | |
| | | String[] asksData = dataArray[0]; |
| | | pvMap.put("p", new BigDecimal(asksData[0]).toPlainString()); |
| | | pvMap.put("v", new BigDecimal(asksData[1]).toPlainString()); |
| | | hashMap.put(BIDS_KEY, pvMap); // 放入 bids 数据 |
| | | hashMap.put(ASKS_KEY, pvMap); // 放入 bids 数据 |
| | | } |
| | | |
| | | if (bidsObj instanceof List && !((List<?>) bidsObj).isEmpty()) { |
| | |
| | | HashMap<String, Object> pvMap = new HashMap<>(); // 创建新的 HashMap 保存 bids 和 asks |
| | | pvMap.put("p", new BigDecimal(bidsData[0]).toPlainString()); |
| | | pvMap.put("v", new BigDecimal(bidsData[1]).toPlainString()); |
| | | hashMap.put(ASKS_KEY,pvMap); |
| | | hashMap.put(BIDS_KEY,pvMap); |
| | | } |
| | | |
| | | String key = "gate" + resultMap.get(S_KEY); // 生成 Redis 键 |
| | |
| | | |
| | | |
| | | @OnClose |
| | | public void onClose() { |
| | | public void onClose() throws Exception { |
| | | log.info("gate ws 连接已关闭,尝试重新连接..."); // 连接关闭日志 |
| | | handleConnectionClosedOrError(); // 处理连接关闭或错误 |
| | | handleConnectionClosedOrError(); |
| | | } |
| | | |
| | | @OnError |
| | | public void onError(Throwable throwable) { |
| | | public void onError(Throwable throwable) throws Exception { |
| | | log.error("gate ws 发生错误: " + throwable.getMessage(), throwable); // 记录错误日志 |
| | | handleConnectionClosedOrError(); // 处理连接关闭或错误 |
| | | handleConnectionClosedOrError(); |
| | | } |
| | | |
| | | private void handleConnectionClosedOrError() { |