| | |
| | | import com.google.gson.reflect.TypeToken; |
| | | |
| | | import com.yami.trading.bean.data.domain.Realtime; |
| | | import com.yami.trading.bean.item.domain.Item; |
| | | import com.yami.trading.huobi.data.DataCache; |
| | | import com.yami.trading.huobi.websocket.constant.enums.EStockType; |
| | | import com.yami.trading.service.item.ItemService; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.java_websocket.client.WebSocketClient; |
| | | import org.java_websocket.handshake.ServerHandshake; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.context.annotation.Scope; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import java.lang.reflect.Type; |
| | | import java.math.BigDecimal; |
| | |
| | | import java.util.*; |
| | | |
| | | @Slf4j |
| | | @Component |
| | | @Scope("prototype") |
| | | public class WebsocketRunClient extends WebSocketClient { |
| | | |
| | | private EStockType eStockType; |
| | | |
| | | @Autowired |
| | | ItemService itemService; |
| | | |
| | | public WebsocketRunClient() { |
| | | super(URI.create("wss://ws.jinmanxuan.com/websocket-server")); |
| | | } |
| | | |
| | | public WebsocketRunClient(URI serverUri, EStockType eStockType) { |
| | | // 修改为新的WebSocket服务器地址 |
| | | super(URI.create("wss://usws.yanshiz.com/websocket-server")); |
| | | super(URI.create("wss://ws.jinmanxuan.com/websocket-server")); |
| | | this.eStockType = eStockType; |
| | | } |
| | | |
| | | |
| | | @Override |
| | | public void onOpen(ServerHandshake serverHandshake) { |
| | | log.info("WebSocket连接已建立,连接到: wss://usws.yanshiz.com/websocket-server"); |
| | | log.info("WebSocket连接已建立,连接到: wss://ws.jinmanxuan.com/websocket-server"); |
| | | // 发送身份验证消息 |
| | | send(("key:"+ eStockType.getStockKey()+":"+eStockType.getContryId()).getBytes()); |
| | | Timer heartbeatTimer; |
| | |
| | | if(!s.equals("pong") && !s.equals("身份验证成功")){ |
| | | try { |
| | | Map<String, String> stringObjectMap = jsonToMap(s); |
| | | String symbol = stringObjectMap.get("symbol").trim(); |
| | | Item item = itemService.findCaCheBySymbol(symbol); |
| | | if (item == null || !item.getType().equalsIgnoreCase(Item.US_STOCKS)) { |
| | | return; |
| | | } |
| | | Realtime realtime = new Realtime(); |
| | | realtime.setUuid(stringObjectMap.get("pid")); |
| | | realtime.setSymbol(stringObjectMap.get("symbol")); |