Skip to content

Commit

Permalink
feature: add new exchange 'Korbot Ex'
Browse files Browse the repository at this point in the history
'Korbot EX' based on OKEX. Has the same api as okex v3.
  • Loading branch information
namjug-kim committed Jun 23, 2019
1 parent c5efa24 commit cca788c
Show file tree
Hide file tree
Showing 12 changed files with 472 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,4 @@ jobs:
- run: gradle ktlint test codeCoverageReport
- codecov/upload:
file: build/reports/jacoco/report.xml
token: dc59b779-b8a0-4f1c-ba53-35f1550ac5cc
token: dc59b779-b8a0-4f1c-ba53-35f1550ac5cc
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ Support public market feature (tickData, orderBook)
| ![coineal](https://user-images.githubusercontent.com/16334718/58037062-7d90cb80-7b67-11e9-9278-e8b03c5ddd86.jpg) | Coineal | COINEAL | 鈿狅笍 | 鈿狅笍 |
| ![poloniex](https://user-images.githubusercontent.com/16334718/59551277-335a0900-8fb2-11e9-9d1e-4ab2a7574148.jpg) | Poloniex | POLONIEX | * | [ws](https://docs.poloniex.com/#websocket-api) |
| ![bitstamp](https://user-images.githubusercontent.com/16334718/59565122-2c062e80-908a-11e9-8a38-6264c26aa3c2.jpg) | Bitstamp | BITSTAMP | v2 | [ws](https://www.bitstamp.net/websocket/v2/) |
| ![korbotex](https://user-images.githubusercontent.com/16334718/59919092-82e07f00-9461-11e9-869a-d801dce68b08.jpg) | Korbot EX | KOTBOTEX | v3 | [ws](https://www.okex.com/docs/en/#spot_ws-all) |

鈿狅笍 : Uses endpoints that are used by the official web. This is not an official api and should be used with care.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ enum class ExchangeVendor {
COINEAL,
POLONIEX,
BITSTAMP,
KORBOTEX,
UNKNOWN;

/**
Expand Down
33 changes: 33 additions & 0 deletions reactive-crypto-korbotex/build.gradle
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"
}
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) }
}
}
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);
}
}
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();
}
}
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)
}
}

0 comments on commit cca788c

Please sign in to comment.