-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feature: add new exchange 'Korbot Ex'
'Korbot EX' based on OKEX. Has the same api as okex v3.
- Loading branch information
1 parent
c5efa24
commit cca788c
Showing
12 changed files
with
472 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,6 +32,7 @@ enum class ExchangeVendor { | |
COINEAL, | ||
POLONIEX, | ||
BITSTAMP, | ||
KORBOTEX, | ||
UNKNOWN; | ||
|
||
/** | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
apply plugin: 'kotlin' | ||
apply plugin: 'org.jetbrains.kotlin.jvm' | ||
|
||
version '1.0-SNAPSHOT' | ||
|
||
dependencies { | ||
compile project(':reactive-crypto-okex') | ||
|
||
compile "org.jetbrains.kotlin:kotlin-stdlib-jdk8" | ||
} | ||
|
||
compileKotlin { | ||
kotlinOptions.jvmTarget = "1.8" | ||
} | ||
compileTestKotlin { | ||
kotlinOptions.jvmTarget = "1.8" | ||
} |
36 changes: 36 additions & 0 deletions
36
...pto-korbotex/src/main/kotlin/com/njkim/reactivecrypto/korbotex/KorbotexWebsocketClient.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* 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.korbotex | ||
|
||
import com.njkim.reactivecrypto.core.common.model.ExchangeVendor | ||
import com.njkim.reactivecrypto.core.common.model.currency.CurrencyPair | ||
import com.njkim.reactivecrypto.core.common.model.order.OrderBook | ||
import com.njkim.reactivecrypto.core.common.model.order.TickData | ||
import com.njkim.reactivecrypto.okex.OkexWebsocketClient | ||
import reactor.core.publisher.Flux | ||
|
||
class KorbotexWebsocketClient : OkexWebsocketClient("wss://okexcomreal.bafang.com:8443/ws/v3?brokerId=151") { | ||
override fun createDepthSnapshot(subscribeTargets: List<CurrencyPair>): Flux<OrderBook> { | ||
return super.createDepthSnapshot(subscribeTargets) | ||
.map { it.copy(exchangeVendor = ExchangeVendor.KORBOTEX) } | ||
} | ||
|
||
override fun createTradeWebsocket(subscribeTargets: List<CurrencyPair>): Flux<TickData> { | ||
return super.createTradeWebsocket(subscribeTargets) | ||
.map { it.copy(exchangeVendor = ExchangeVendor.KORBOTEX) } | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
...orbotex/src/test/java/com/njkim/reactivecrypto/kobotex/ExchangeClientFactoryJavaTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* 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.kobotex; | ||
|
||
import com.njkim.reactivecrypto.core.ExchangeClientFactory; | ||
import com.njkim.reactivecrypto.core.common.model.ExchangeVendor; | ||
import com.njkim.reactivecrypto.core.websocket.ExchangeWebsocketClient; | ||
import com.njkim.reactivecrypto.korbotex.KorbotexWebsocketClient; | ||
import org.junit.Test; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
public class ExchangeClientFactoryJavaTest { | ||
@Test | ||
public void websocket_client() { | ||
ExchangeWebsocketClient exchangeWebsocketClient = ExchangeClientFactory.websocket(ExchangeVendor.KORBOTEX); | ||
|
||
assertThat(exchangeWebsocketClient).isNotNull(); | ||
assertThat(exchangeWebsocketClient).isInstanceOf(ExchangeWebsocketClient.class); | ||
assertThat(exchangeWebsocketClient).isExactlyInstanceOf(KorbotexWebsocketClient.class); | ||
} | ||
} |
137 changes: 137 additions & 0 deletions
137
...botex/src/test/java/com/njkim/reactivecrypto/kobotex/KorbotexWebsocketClientJavaTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
/* | ||
* 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.kobotex; | ||
|
||
import com.njkim.reactivecrypto.core.common.model.ExchangeVendor; | ||
import com.njkim.reactivecrypto.core.common.model.currency.CurrencyPair; | ||
import com.njkim.reactivecrypto.core.common.model.order.OrderBook; | ||
import com.njkim.reactivecrypto.core.common.model.order.TickData; | ||
import com.njkim.reactivecrypto.korbotex.KorbotexWebsocketClient; | ||
import org.junit.Test; | ||
import reactor.core.publisher.Flux; | ||
import reactor.test.StepVerifier; | ||
|
||
import java.math.BigDecimal; | ||
import java.util.Collections; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
public class KorbotexWebsocketClientJavaTest { | ||
@Test | ||
public void tick_data_subscribe() { | ||
// given | ||
CurrencyPair targetCurrencyPair = CurrencyPair.parse("BTC", "USDT"); | ||
Flux<TickData> tickDataFlux = new KorbotexWebsocketClient() | ||
.createTradeWebsocket(Collections.singletonList(targetCurrencyPair)); | ||
|
||
// when | ||
StepVerifier.create(tickDataFlux.limitRequest(5)) | ||
.expectNextCount(3) | ||
// then | ||
.assertNext(tickData -> { | ||
assertThat(tickData).isNotNull(); | ||
assertThat(tickData.getCurrencyPair()) | ||
.isEqualTo(targetCurrencyPair); | ||
assertThat(tickData.getExchangeVendor()) | ||
.isEqualByComparingTo(ExchangeVendor.KORBOTEX); | ||
assertThat(tickData.getPrice()) | ||
.isGreaterThan(BigDecimal.ZERO); | ||
assertThat(tickData.getQuantity()) | ||
.isGreaterThan(BigDecimal.ZERO); | ||
}) | ||
.assertNext(tickData -> { | ||
assertThat(tickData).isNotNull(); | ||
assertThat(tickData.getCurrencyPair()) | ||
.isEqualTo(targetCurrencyPair); | ||
assertThat(tickData.getExchangeVendor()) | ||
.isEqualByComparingTo(ExchangeVendor.KORBOTEX); | ||
assertThat(tickData.getPrice()) | ||
.isGreaterThan(BigDecimal.ZERO); | ||
assertThat(tickData.getQuantity()) | ||
.isGreaterThan(BigDecimal.ZERO); | ||
}) | ||
.verifyComplete(); | ||
} | ||
|
||
@Test | ||
public void orderBook_subscribe() { | ||
// given | ||
CurrencyPair targetCurrencyPair = CurrencyPair.parse("BTC", "USDT"); | ||
Flux<OrderBook> orderBookFlux = new KorbotexWebsocketClient() | ||
.createDepthSnapshot(Collections.singletonList(targetCurrencyPair)); | ||
|
||
// when | ||
StepVerifier.create(orderBookFlux.limitRequest(5)) | ||
.expectNextCount(3) | ||
// then | ||
.assertNext(orderBook -> { | ||
assertThat(orderBook).isNotNull(); | ||
assertThat(orderBook.getCurrencyPair()) | ||
.isEqualTo(targetCurrencyPair); | ||
assertThat(orderBook.getExchangeVendor()) | ||
.isEqualByComparingTo(ExchangeVendor.KORBOTEX); | ||
assertThat(orderBook.getAsks()) | ||
.isNotEmpty(); | ||
assertThat(orderBook.getBids()) | ||
.isNotEmpty(); | ||
|
||
assertThat(orderBook.getAsks().get(0).getQuantity()) | ||
.isGreaterThan(BigDecimal.ZERO); | ||
assertThat(orderBook.getBids().get(0).getQuantity()) | ||
.isGreaterThan(BigDecimal.ZERO); | ||
|
||
assertThat(orderBook.getAsks().get(0).getPrice()) | ||
.withFailMessage("ask price must be bigger than bid price") | ||
.isGreaterThan(orderBook.getBids().get(0).getPrice()); | ||
|
||
assertThat(orderBook.getAsks().get(0).getPrice()) | ||
.withFailMessage("asks must be sorted by price asc") | ||
.isLessThan(orderBook.getAsks().get(1).getPrice()); | ||
assertThat(orderBook.getBids().get(0).getPrice()) | ||
.withFailMessage("bids must be sorted by price desc") | ||
.isGreaterThan(orderBook.getBids().get(1).getPrice()); | ||
}) | ||
.assertNext(orderBook -> { | ||
assertThat(orderBook).isNotNull(); | ||
assertThat(orderBook.getCurrencyPair()) | ||
.isEqualTo(targetCurrencyPair); | ||
assertThat(orderBook.getExchangeVendor()) | ||
.isEqualByComparingTo(ExchangeVendor.KORBOTEX); | ||
assertThat(orderBook.getAsks()) | ||
.isNotEmpty(); | ||
assertThat(orderBook.getBids()) | ||
.isNotEmpty(); | ||
|
||
assertThat(orderBook.getAsks().get(0).getQuantity()) | ||
.isGreaterThan(BigDecimal.ZERO); | ||
assertThat(orderBook.getBids().get(0).getQuantity()) | ||
.isGreaterThan(BigDecimal.ZERO); | ||
|
||
assertThat(orderBook.getAsks().get(0).getPrice()) | ||
.withFailMessage("ask price must be bigger than bid price") | ||
.isGreaterThan(orderBook.getBids().get(0).getPrice()); | ||
|
||
assertThat(orderBook.getAsks().get(0).getPrice()) | ||
.withFailMessage("asks must be sorted by price asc") | ||
.isLessThan(orderBook.getAsks().get(1).getPrice()); | ||
assertThat(orderBook.getBids().get(0).getPrice()) | ||
.withFailMessage("bids must be sorted by price desc") | ||
.isGreaterThan(orderBook.getBids().get(1).getPrice()); | ||
}) | ||
.verifyComplete(); | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
...to-korbotex/src/test/kotlin/com/njkim/reactivecrypto/kobotex/ExchangeClientFactoryTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* 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.kobotex | ||
|
||
import com.njkim.reactivecrypto.core.ExchangeClientFactory | ||
import com.njkim.reactivecrypto.core.common.model.ExchangeVendor | ||
import com.njkim.reactivecrypto.core.websocket.ExchangeWebsocketClient | ||
import com.njkim.reactivecrypto.korbotex.KorbotexWebsocketClient | ||
import org.assertj.core.api.Assertions.assertThat | ||
import org.junit.Test | ||
|
||
class ExchangeClientFactoryTest { | ||
@Test | ||
fun `create websocket client`() { | ||
val exchangeWebsocketClient = ExchangeClientFactory.websocket(ExchangeVendor.KORBOTEX) | ||
|
||
assertThat(exchangeWebsocketClient).isNotNull | ||
assertThat(exchangeWebsocketClient).isInstanceOf(ExchangeWebsocketClient::class.java) | ||
assertThat(exchangeWebsocketClient).isExactlyInstanceOf(KorbotexWebsocketClient::class.java) | ||
} | ||
} |
Oops, something went wrong.