-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
417 additions
and
8 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
10 changes: 2 additions & 8 deletions
10
...x/src/main/java/org/knowm/xchange/coinex/config/converter/OrderTypeToStringConverter.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 |
---|---|---|
@@ -1,20 +1,14 @@ | ||
package org.knowm.xchange.coinex.config.converter; | ||
|
||
import com.fasterxml.jackson.databind.util.StdConverter; | ||
import org.knowm.xchange.coinex.CoinexAdapters; | ||
import org.knowm.xchange.dto.Order.OrderType; | ||
|
||
/** Converts {@code OrderType} to string */ | ||
public class OrderTypeToStringConverter extends StdConverter<OrderType, String> { | ||
|
||
@Override | ||
public String convert(OrderType value) { | ||
switch (value) { | ||
case BID: | ||
return "buy"; | ||
case ASK: | ||
return "sell"; | ||
default: | ||
throw new IllegalArgumentException("Can't map " + value); | ||
} | ||
return CoinexAdapters.toString(value); | ||
} | ||
} |
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
23 changes: 23 additions & 0 deletions
23
...-coinex/src/main/java/org/knowm/xchange/coinex/service/params/CoinexOpenOrdersParams.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,23 @@ | ||
package org.knowm.xchange.coinex.service.params; | ||
|
||
import lombok.Builder; | ||
import lombok.Data; | ||
import org.knowm.xchange.instrument.Instrument; | ||
import org.knowm.xchange.service.trade.params.orders.DefaultOpenOrdersParam; | ||
import org.knowm.xchange.service.trade.params.orders.OpenOrdersParamInstrument; | ||
import org.knowm.xchange.service.trade.params.orders.OpenOrdersParamLimit; | ||
import org.knowm.xchange.service.trade.params.orders.OpenOrdersParamOffset; | ||
|
||
@Data | ||
@Builder | ||
public class CoinexOpenOrdersParams extends DefaultOpenOrdersParam implements OpenOrdersParamLimit, | ||
OpenOrdersParamOffset, OpenOrdersParamInstrument { | ||
|
||
public static final Integer DEFAULT_LIMIT = 1000; | ||
|
||
private Instrument instrument; | ||
|
||
private Integer limit; | ||
|
||
private Integer offset; | ||
} |
52 changes: 52 additions & 0 deletions
52
xchange-coinex/src/test/java/org/knowm/xchange/coinex/CoinexExchangeWiremock.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,52 @@ | ||
package org.knowm.xchange.coinex; | ||
|
||
import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.options; | ||
|
||
import com.github.tomakehurst.wiremock.WireMockServer; | ||
import com.github.tomakehurst.wiremock.recording.RecordSpecBuilder; | ||
import org.junit.jupiter.api.AfterAll; | ||
import org.junit.jupiter.api.BeforeAll; | ||
import org.knowm.xchange.ExchangeFactory; | ||
import org.knowm.xchange.ExchangeSpecification; | ||
|
||
/** Sets up the wiremock for exchange */ | ||
public abstract class CoinexExchangeWiremock { | ||
|
||
protected static CoinexExchange exchange; | ||
|
||
// private static final boolean IS_RECORDING = true; | ||
private static final boolean IS_RECORDING = false; | ||
|
||
private static WireMockServer wireMockServer; | ||
|
||
@BeforeAll | ||
public static void initExchange() { | ||
wireMockServer = new WireMockServer(options().dynamicPort()); | ||
wireMockServer.start(); | ||
|
||
ExchangeSpecification exSpec = new ExchangeSpecification(CoinexExchange.class); | ||
exSpec.setSslUri("http://localhost:" + wireMockServer.port()); | ||
exSpec.setApiKey(System.getProperty("apiKey", "abc")); | ||
exSpec.setSecretKey(System.getProperty("secretKey", "bcd")); | ||
|
||
if (IS_RECORDING) { | ||
// use default url and record the requests | ||
wireMockServer.startRecording( | ||
new RecordSpecBuilder() | ||
.forTarget("https://api.coinex.com") | ||
.matchRequestBodyWithEqualToJson() | ||
.extractTextBodiesOver(1L) | ||
.chooseBodyMatchTypeAutomatically()); | ||
} | ||
|
||
exchange = (CoinexExchange) ExchangeFactory.INSTANCE.createExchange(exSpec); | ||
} | ||
|
||
@AfterAll | ||
public static void stop() { | ||
if (IS_RECORDING) { | ||
wireMockServer.stopRecording(); | ||
} | ||
wireMockServer.stop(); | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
xchange-coinex/src/test/java/org/knowm/xchange/coinex/service/CoinexTradeServiceTest.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,41 @@ | ||
package org.knowm.xchange.coinex.service; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import java.io.IOException; | ||
import org.junit.jupiter.api.Test; | ||
import org.knowm.xchange.coinex.CoinexExchangeWiremock; | ||
import org.knowm.xchange.currency.CurrencyPair; | ||
import org.knowm.xchange.dto.trade.OpenOrders; | ||
import org.knowm.xchange.service.trade.TradeService; | ||
import org.knowm.xchange.service.trade.params.orders.DefaultOpenOrdersParamInstrument; | ||
|
||
class CoinexTradeServiceTest extends CoinexExchangeWiremock { | ||
|
||
TradeService tradeService = exchange.getTradeService(); | ||
|
||
@Test | ||
void all_open_orders() throws IOException { | ||
OpenOrders actual = tradeService.getOpenOrders(); | ||
|
||
assertThat(actual.getOpenOrders()).hasSize(2); | ||
assertThat(actual.getHiddenOrders()).isEmpty(); | ||
|
||
assertThat(actual.getAllOpenOrders().get(0).getInstrument()) | ||
.isEqualTo(CurrencyPair.ETH_USDT); | ||
assertThat(actual.getAllOpenOrders().get(1).getInstrument()) | ||
.isEqualTo(CurrencyPair.BTC_USDT); | ||
} | ||
|
||
@Test | ||
void filtered_open_orders() throws IOException { | ||
OpenOrders actual = tradeService.getOpenOrders(new DefaultOpenOrdersParamInstrument(CurrencyPair.BTC_USDT)); | ||
|
||
assertThat(actual.getOpenOrders()).hasSize(1); | ||
assertThat(actual.getHiddenOrders()).isEmpty(); | ||
|
||
assertThat(actual.getAllOpenOrders().get(0).getInstrument()) | ||
.isEqualTo(CurrencyPair.BTC_USDT); | ||
} | ||
|
||
} |
32 changes: 32 additions & 0 deletions
32
xchange-coinex/src/test/resources/__files/v2_spot_market.json
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,32 @@ | ||
{ | ||
"code": 0, | ||
"data": [ | ||
{ | ||
"base_ccy": "ETH", | ||
"base_ccy_precision": 8, | ||
"is_amm_available": false, | ||
"is_margin_available": true, | ||
"is_pre_trading_available": false, | ||
"maker_fee_rate": "0.002", | ||
"market": "ETHUSDT", | ||
"min_amount": "0.0005", | ||
"quote_ccy": "USDT", | ||
"quote_ccy_precision": 2, | ||
"taker_fee_rate": "0.002" | ||
}, | ||
{ | ||
"base_ccy": "BTC", | ||
"base_ccy_precision": 8, | ||
"is_amm_available": false, | ||
"is_margin_available": true, | ||
"is_pre_trading_available": false, | ||
"maker_fee_rate": "0.002", | ||
"market": "BTCUSDT", | ||
"min_amount": "0.00005", | ||
"quote_ccy": "USDT", | ||
"quote_ccy_precision": 2, | ||
"taker_fee_rate": "0.002" | ||
} | ||
], | ||
"message": "OK" | ||
} |
Oops, something went wrong.