binance / binance-futures-connector-java

MIT License
111 stars 61 forks source link

UMWebsocketClientImpl.allMarkPriceStream() occured 'NoSuchMethodError' when using 'binance-connector-java' together #3

Closed yechanpark closed 1 year ago

yechanpark commented 1 year ago

hi. im using libraries both binance-futures-connector-java and binance-connector-java in one spring boot project with kotlin.

when i write following test code, NoSuchMethodError has been occured. and success when excluded 'binance-connector-java'.

class Test { @Test fun subscribe() {

    val callback = WebSocketCallback {
        println(it)
    }
    // NoSuchMethodError
    // success when excluded 'binance-connector-java'
    UMWebsocketClientImpl().allMarkPriceStream(
        3, callback
    )

    sleep(1000 * 10)
}

}



`java.lang.NoSuchMethodError: 'java.lang.String com.binance.connector.client.impl.UMWebsocketClientImpl.getBaseUrl()'`
or
`java.lang.NoSuchMethodError: 'com.binance.connector.client.utils.WebSocketCallback com.binance.connector.client.impl.UMWebsocketClientImpl.getNoopCallback()`

can i fix this without copy & paste?

im not sure, but i guess the reason of this is many classes and enums are placed in both libraries as same package but has difference properties.

i copied & pasted code in my different package (ex. `com.binance.futures.connector.~` ) because of this error and handling it my self.
jonte-z commented 1 year ago

Hi there,

Ah yes I think I know why you're facing this issue. As you mentioned how both libraries use identical naming, it looks to be the result of both the Spot and Futures connectors using the com.binance.connector.client.impl.WebsocketClientImpl class. UMWebsocketClientImpl, used in your example, is a child of WebsocketClientImpl. Generally this would be a non-issue but you have brought up an interesting use-case by leveraging both Spot and Futures Java connectors in a single file.

For example there's no getNoopCallback() or getBaseUrl() function in the Spot implementation of com.binance.connector.client.impl.WebsocketClientImpl, however both functions do exist in the Futures implementation of com.binance.connector.client.impl.WebsocketClientImpl. This explains why it works when you remove the Spot library import.

Thanks for pointing this out. I will devise a fix asap for the next release to solve any future conflicts related to importing both connectors in a single file. Likely it will involve changing com.binance.connector.client to com.binance.connector.futures-client or similar which should fix the confusion.

aisling-2 commented 1 year ago

This is handled in the new version 2.0.0. Thank you.