forestwanglin / okx-v5-java

OKX V5 SDK for JAVA
MIT License
20 stars 8 forks source link

`OkxWsApiService` design suggestions #5

Closed jouzitong closed 6 months ago

jouzitong commented 6 months ago
public class OkxWsApiService {

   private void subscribe(WsChannel wsChannel, WsChannelRequestArg requestArg) {
        if (!subscribeStateService.hasSubscribed(wsChannel, requestArg)) {
            pureSubscribe(wsChannel, requestArg);
            subscribeStateService.addSubscribed(wsChannel, requestArg);
        } else {
            log.error("subscribe already exists: {} {}", wsChannel, requestArg);
        }
    }

    public void pureSubscribe(WsChannel wsChannel, WsChannelRequestArg requestArg) {
        WsRequest<WsRequestArg> wsRequest = WsRequest.builder()
                .op(Operation.SUBSCRIBE)
                .args(List.of(requestArg)).build();
        send(wsChannel, JSON.toJSONString(wsRequest));
    }

    private void unsubscribe(WsChannel wsChannel, WsChannelRequestArg requestArg) {
        WsRequest<WsRequestArg> wsRequest = WsRequest.builder()
                .op(Operation.UNSUBSCRIBE)
                .args(List.of(requestArg)).build();
        send(wsChannel, JSON.toJSONString(wsRequest));
    }

}

I hope you can change subscribe and unsubscribe to protected permissions. reason:

  1. During the development process, since you still have many unimplemented interfaces, I hope to inherit this class and then extend the new interface.
forestwanglin commented 6 months ago

Thanks for your advance. You are right. I designed it by using by myself at the beginning which it not extendable for others. I will change it and release a new version 0.4.2024051501.