| | |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.xcong.excoin.modules.gateApi.GateGridTradeService; |
| | | import com.xcong.excoin.modules.gateApi.wsHandler.AbstractPrivateChannelHandler; |
| | | import io.gate.gateapi.models.Position; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | |
| | | import java.math.BigDecimal; |
| | |
| | | |
| | | @Override |
| | | public boolean handleMessage(JSONObject response) { |
| | | if (!CHANNEL_NAME.equals(response.getString("channel"))) return false; |
| | | if (!CHANNEL_NAME.equals(response.getString("channel"))) { |
| | | return false; |
| | | } |
| | | try { |
| | | JSONArray resultArray = response.getJSONArray("result"); |
| | | if (resultArray == null || resultArray.isEmpty()) return true; |
| | | if (resultArray == null || resultArray.isEmpty()) { |
| | | return true; |
| | | } |
| | | for (int i = 0; i < resultArray.size(); i++) { |
| | | JSONObject pos = resultArray.getJSONObject(i); |
| | | if (!getContract().equals(pos.getString("contract"))) continue; |
| | | String mode = pos.getString("mode"); |
| | | if (!getContract().equals(pos.getString("contract"))) { |
| | | continue; |
| | | } |
| | | String modeStr = pos.getString("mode"); |
| | | Position.ModeEnum mode = Position.ModeEnum.fromValue(modeStr); |
| | | BigDecimal size = new BigDecimal(pos.getString("size")); |
| | | BigDecimal entryPrice = new BigDecimal(pos.getString("entry_price")); |
| | | log.info("[{}] 持仓更新, 模式:{}, 数量:{}, 入场价:{}", CHANNEL_NAME, mode, size, entryPrice); |
| | | log.info("[{}] 持仓更新, 模式:{}, 数量:{}, 入场价:{}", CHANNEL_NAME, modeStr, size, entryPrice); |
| | | if (getGridTradeService() != null) { |
| | | getGridTradeService().onPositionUpdate(getContract(), mode, size, entryPrice); |
| | | } |