Skip to content

Commit

Permalink
refactor: add default implementation ExchangeClientFactory string method
Browse files Browse the repository at this point in the history
  • Loading branch information
namjug-kim committed Jun 20, 2019
1 parent bc6ba4b commit 9bdf772
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
* Copyright 2019 namjug-kim
*
* LINE Corporation licenses this file to you under the Apache License,
* version 2.0 (the "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at:
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
* License for the specific language governing permissions and limitations
* under the License.
*/

package com.njkim.reactivecrypto.binance

import com.njkim.reactivecrypto.core.ExchangeClientFactory
Expand All @@ -15,4 +31,13 @@ class ExchangeClientFactoryTest {
assertThat(exchangeWebsocketClient).isInstanceOf(ExchangeWebsocketClient::class.java)
assertThat(exchangeWebsocketClient).isExactlyInstanceOf(BinanceWebsocketClient::class.java)
}
}

@Test
fun `create binance websocket client using string`() {
val exchangeWebsocketClient = ExchangeClientFactory.websocket("BINANCE")

assertThat(exchangeWebsocketClient).isNotNull
assertThat(exchangeWebsocketClient).isInstanceOf(ExchangeWebsocketClient::class.java)
assertThat(exchangeWebsocketClient).isExactlyInstanceOf(BinanceWebsocketClient::class.java)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,16 @@ import kotlin.reflect.full.createInstance

class ExchangeClientFactory {
companion object {
init {
ExchangeVendor.values()
.forEach { exchangeVendor ->
ReactiveCryptoPlugins.customClientFactory
.addHttpCustomFactory(exchangeVendor.name) { http(exchangeVendor) }
ReactiveCryptoPlugins.customClientFactory
.addWsCustomFactory(exchangeVendor.name) { websocket(exchangeVendor) }
}
}

@JvmStatic
fun websocket(exchangeVendor: ExchangeVendor): ExchangeWebsocketClient {
return websocket(exchangeVendor.websocketClientName)
Expand Down

0 comments on commit 9bdf772

Please sign in to comment.