Skip to content

Commit c5efa24

Browse files
authored
Merge pull request #80 from namjug-kim/add_default_string_factory
refactor: add default implementation ExchangeClientFactory string method
2 parents ff5323c + 9bdf772 commit c5efa24

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

reactive-crypto-binance/src/test/kotlin/com/njkim/reactivecrypto/binance/ExchangeClientFactoryTest.kt

+26-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,19 @@
1+
/*
2+
* Copyright 2019 namjug-kim
3+
*
4+
* LINE Corporation licenses this file to you under the Apache License,
5+
* version 2.0 (the "License"); you may not use this file except in compliance
6+
* with the License. You may obtain a copy of the License at:
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13+
* License for the specific language governing permissions and limitations
14+
* under the License.
15+
*/
16+
117
package com.njkim.reactivecrypto.binance
218

319
import com.njkim.reactivecrypto.core.ExchangeClientFactory
@@ -15,4 +31,13 @@ class ExchangeClientFactoryTest {
1531
assertThat(exchangeWebsocketClient).isInstanceOf(ExchangeWebsocketClient::class.java)
1632
assertThat(exchangeWebsocketClient).isExactlyInstanceOf(BinanceWebsocketClient::class.java)
1733
}
18-
}
34+
35+
@Test
36+
fun `create binance websocket client using string`() {
37+
val exchangeWebsocketClient = ExchangeClientFactory.websocket("BINANCE")
38+
39+
assertThat(exchangeWebsocketClient).isNotNull
40+
assertThat(exchangeWebsocketClient).isInstanceOf(ExchangeWebsocketClient::class.java)
41+
assertThat(exchangeWebsocketClient).isExactlyInstanceOf(BinanceWebsocketClient::class.java)
42+
}
43+
}

reactive-crypto-core/src/main/kotlin/com/njkim/reactivecrypto/core/ExchangeClientFactory.kt

+10
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,16 @@ import kotlin.reflect.full.createInstance
2525

2626
class ExchangeClientFactory {
2727
companion object {
28+
init {
29+
ExchangeVendor.values()
30+
.forEach { exchangeVendor ->
31+
ReactiveCryptoPlugins.customClientFactory
32+
.addHttpCustomFactory(exchangeVendor.name) { http(exchangeVendor) }
33+
ReactiveCryptoPlugins.customClientFactory
34+
.addWsCustomFactory(exchangeVendor.name) { websocket(exchangeVendor) }
35+
}
36+
}
37+
2838
@JvmStatic
2939
fun websocket(exchangeVendor: ExchangeVendor): ExchangeWebsocketClient {
3040
return websocket(exchangeVendor.websocketClientName)

0 commit comments

Comments
 (0)