Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public class OkexAdapters {
private static final String TRADING_WALLET_ID = "trading";
private static final String FOUNDING_WALLET_ID = "founding";
private static final String FUTURES_WALLET_ID = "futures";
static final Map<Instrument, Long> instrumentToInstrumentIdMap = new HashMap<>();

public static UserTrades adaptUserTrades(
List<OkexOrderDetails> okexTradeHistory, ExchangeMetaData exchangeMetaData) {
Expand Down Expand Up @@ -180,6 +181,7 @@ public static OkexAmendOrderRequest adaptAmendOrder(
LimitOrder order, ExchangeMetaData exchangeMetaData) {
return OkexAmendOrderRequest.builder()
.instrumentId(adaptInstrument(order.getInstrument()))
.instIdCode(instrumentToInstrumentIdMap.get(order.getInstrument()).toString())
.orderId(order.getId())
.clientOrderId(order.getUserReference())
.amendedAmount(convertVolumeToContractSize(order, exchangeMetaData))
Expand All @@ -191,6 +193,7 @@ public static OkexOrderRequest adaptOrder(
MarketOrder order, ExchangeMetaData exchangeMetaData, String accountLevel) {
return OkexOrderRequest.builder()
.instrumentId(adaptInstrument(order.getInstrument()))
.instIdCode(instrumentToInstrumentIdMap.get(order.getInstrument()).toString())
.tradeMode(adaptTradeMode(order.getInstrument(), accountLevel))
.side(getSide(order))
.posSide(null) // PosSide should come as a input from an extended LimitOrder class to
Expand Down Expand Up @@ -244,6 +247,7 @@ public static OkexOrderRequest adaptOrder(
LimitOrder order, ExchangeMetaData exchangeMetaData, String accountLevel) {
return OkexOrderRequest.builder()
.instrumentId(adaptInstrument(order.getInstrument()))
.instIdCode(instrumentToInstrumentIdMap.get(order.getInstrument()).toString())
.tradeMode(adaptTradeMode(order.getInstrument(), accountLevel))
.side(getSide(order))
.posSide(null) // PosSide should come as a input from an extended LimitOrder class to
Expand Down Expand Up @@ -850,4 +854,8 @@ public static List<OrderBookUpdate> adaptOrderBookUpdates(
}
return orderBookUpdates;
}

public static String instrumentToInstrumentCode(Instrument instrument) {
return instrumentToInstrumentIdMap.get(instrument).toString();
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
package org.knowm.xchange.okex;

import static org.knowm.xchange.okex.dto.OkexInstType.SPOT;
import static org.knowm.xchange.okex.dto.OkexInstType.SWAP;

import java.io.IOException;
import java.util.List;
import org.knowm.xchange.BaseExchange;
import org.knowm.xchange.ExchangeSpecification;
import org.knowm.xchange.client.ResilienceRegistries;
Expand All @@ -16,7 +11,16 @@
import org.knowm.xchange.okex.service.OkexTradeService;
import si.mazi.rescu.SynchronizedValueFactory;

/** Author: Max Gao (gaamox@tutanota.com) Created: 08-06-2021 */
import java.io.IOException;
import java.util.List;

import static org.knowm.xchange.okex.OkexAdapters.adaptOkexInstrumentId;
import static org.knowm.xchange.okex.dto.OkexInstType.SPOT;
import static org.knowm.xchange.okex.dto.OkexInstType.SWAP;

/**
* Author: Max Gao (gaamox@tutanota.com) Created: 08-06-2021
*/
public class OkexExchange extends BaseExchange {

public static final String PARAM_USE_AWS = "Use_AWS";
Expand All @@ -27,8 +31,11 @@ public class OkexExchange extends BaseExchange {

public String accountLevel = "1";

/** Adjust host parameters depending on exchange specific parameters */
protected void concludeHostParams(ExchangeSpecification exchangeSpecification) {}
/**
* Adjust host parameters depending on exchange specific parameters
*/
protected void concludeHostParams(ExchangeSpecification exchangeSpecification) {
}

@Override
public void applySpecification(ExchangeSpecification exchangeSpecification) {
Expand Down Expand Up @@ -91,6 +98,10 @@ public void remoteInit() throws IOException {

instruments.addAll(swap_instruments);

instruments.forEach(instrument -> {
if (instrument.getInstIdCode() != null)
OkexAdapters.instrumentToInstrumentIdMap.put(adaptOkexInstrumentId(instrument.getInstrumentId()), Long.parseLong(instrument.getInstIdCode()));
});
// Currency data is only retrievable through a private endpoint
List<OkexCurrency> currencies = null;
if (exchangeSpecification.getApiKey() != null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,7 @@ public class OkexInstrument {

@JsonProperty("state")
private String state;

@JsonProperty("instIdCode")
private String instIdCode;
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ public class OkexAmendOrderRequest {
@JsonProperty("instId")
private String instrumentId;

@JsonProperty("instIdCode")
private String instIdCode;

@JsonProperty("cxlOnFail")
private boolean cancelOnFail;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ public class OkexCancelOrderRequest {
@JsonProperty("instId")
private String instrumentId;

@JsonProperty("instIdCode")
private String instIdCode;

@JsonProperty("ordId")
private String orderId;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ public class OkexOrderRequest {
@JsonProperty("instId")
private String instrumentId;

@JsonProperty("instIdCode")
private String instIdCode;

@JsonProperty("tdMode")
private String tradeMode;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
package info.bitrich.xchangestream.okex;

import static info.bitrich.xchangestream.core.StreamingExchange.WS_CONNECTION_TIMEOUT;
import static info.bitrich.xchangestream.core.StreamingExchange.WS_IDLE_TIMEOUT;
import static info.bitrich.xchangestream.core.StreamingExchange.WS_RETRY_DURATION;
import static info.bitrich.xchangestream.okex.OkexStreamingService.SUBSCRIBE;
import static info.bitrich.xchangestream.okex.OkexStreamingService.UNSUBSCRIBE;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JsonNode;
import info.bitrich.xchangestream.okex.dto.OkexLoginMessage;
Expand All @@ -16,17 +10,6 @@
import io.reactivex.rxjava3.core.CompletableSource;
import io.reactivex.rxjava3.core.Observable;
import io.reactivex.rxjava3.disposables.Disposable;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.time.Duration;
import java.util.Base64;
import java.util.Collections;
import java.util.concurrent.TimeUnit;
import javax.crypto.Mac;
import javax.crypto.SecretKey;
import javax.crypto.spec.SecretKeySpec;
import lombok.Getter;
import org.knowm.xchange.ExchangeSpecification;
import org.knowm.xchange.dto.trade.LimitOrder;
Expand All @@ -43,6 +26,22 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.crypto.Mac;
import javax.crypto.SecretKey;
import javax.crypto.spec.SecretKeySpec;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.time.Duration;
import java.util.Base64;
import java.util.Collections;
import java.util.concurrent.TimeUnit;

import static info.bitrich.xchangestream.core.StreamingExchange.*;
import static info.bitrich.xchangestream.okex.OkexStreamingService.SUBSCRIBE;
import static info.bitrich.xchangestream.okex.OkexStreamingService.UNSUBSCRIBE;

public class OkexPrivateStreamingService extends JsonNettyStreamingService {

private static final Logger LOG = LoggerFactory.getLogger(OkexPrivateStreamingService.class);
Expand Down Expand Up @@ -246,7 +245,7 @@ public String getSubscribeMessage(String channelName, Object... args) throws IOE
OkexCancelOrderParams params = (OkexCancelOrderParams) args[1];
OkexCancelOrderRequest orderChangePayload =
OkexCancelOrderRequest.builder()
.instrumentId(OkexAdapters.adaptInstrument(params.instrument))
.instIdCode(OkexAdapters.instrumentToInstrumentCode(params.instrument))
.orderId(params.orderId)
.clientOrderId(params.getUserReference())
.build();
Expand Down
Loading