-
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.
Merge pull request #4983 from bigscoop/coinex
[coinex] Extend functionality
- Loading branch information
Showing
19 changed files
with
542 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); | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
...nge-coinex/src/main/java/org/knowm/xchange/coinex/dto/trade/CoinexCancelOrderRequest.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,27 @@ | ||
package org.knowm.xchange.coinex.dto.trade; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import com.fasterxml.jackson.databind.annotation.JsonSerialize; | ||
import lombok.Builder; | ||
import lombok.Data; | ||
import lombok.extern.jackson.Jacksonized; | ||
import org.knowm.xchange.coinex.config.converter.CurrencyPairToStringConverter; | ||
import org.knowm.xchange.coinex.dto.account.CoinexMarketType; | ||
import org.knowm.xchange.instrument.Instrument; | ||
|
||
@Data | ||
@Builder | ||
@Jacksonized | ||
public class CoinexCancelOrderRequest { | ||
|
||
@JsonProperty("market") | ||
@JsonSerialize(converter = CurrencyPairToStringConverter.class) | ||
Instrument instrument; | ||
|
||
@JsonProperty("market_type") | ||
private CoinexMarketType marketType; | ||
|
||
@JsonProperty("order_id") | ||
private Long orderId; | ||
|
||
} |
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(); | ||
} | ||
} |
Oops, something went wrong.