Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[kraken futures] fix, instruments to uppercase #4787

Merged
merged 3 commits into from
Nov 13, 2023
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
2 changes: 1 addition & 1 deletion xchange-binance/src/test/resources/logback.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
</appender>


<root level="DEBUG">
<root level="WARN">
<appender-ref ref="CONSOLE_APPENDER"/>
</root>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
/** @author Jean-Christophe Laruelle */
public class KrakenFuturesAdapters {

private static final String MULTI_COLLATERAL_PRODUCTS = "pf_";
private static final String MULTI_COLLATERAL_PRODUCTS = "PF_";
private static final String ACCOUNT_TYPE = "multiCollateralMarginAccount";

public static Ticker adaptTicker(
Expand Down Expand Up @@ -183,7 +183,7 @@ public static ExchangeMetaData adaptInstrumentsMetaData(KrakenFuturesInstruments
Map<Currency, CurrencyMetaData> currencies = new HashMap<>();

for (KrakenFuturesInstrument instrument : krakenFuturesInstruments.getInstruments()) {
if(instrument.getSymbol().contains("pf")){
if(instrument.getSymbol().contains(MULTI_COLLATERAL_PRODUCTS)){
instruments.put(adaptInstrument(instrument.getSymbol()),new InstrumentMetaData.Builder()
.volumeScale(instrument.getVolumeScale())
.priceScale(instrument.getTickSize().scale())
Expand All @@ -198,7 +198,7 @@ public static ExchangeMetaData adaptInstrumentsMetaData(KrakenFuturesInstruments

public static Instrument adaptInstrument(String symbol) {
String main_symbol = symbol.replace(MULTI_COLLATERAL_PRODUCTS,"");
return new FuturesContract(new CurrencyPair(main_symbol.substring(0, main_symbol.length() - 3).replace("xbt","btc")+"/"+main_symbol.substring(main_symbol.length()-3)),"PERP");
return new FuturesContract(new CurrencyPair(main_symbol.substring(0, main_symbol.length() - 3).replace("XBT","BTC")+"/"+main_symbol.substring(main_symbol.length()-3)),"PERP");
}

private static BigDecimal getMinimumAmountFromVolumeScale(Integer volumeScale){
Expand All @@ -215,7 +215,7 @@ private static BigDecimal getMinimumAmountFromVolumeScale(Integer volumeScale){
}

public static String adaptKrakenFuturesSymbol(Instrument instrument) {
return MULTI_COLLATERAL_PRODUCTS+instrument.getBase().toString().replace("BTC","XBT").toLowerCase()+instrument.getCounter().toString().toLowerCase();
return MULTI_COLLATERAL_PRODUCTS+instrument.getBase().toString().replace("BTC","XBT")+instrument.getCounter().toString();
}

public static Trades adaptTrades(KrakenFuturesPublicFills krakenFuturesTrades, Instrument instrument) {
Expand Down
2 changes: 1 addition & 1 deletion xchange-okex/src/test/resources/logback.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
</appender>


<root level="DEBUG">
<root level="WARN">
<appender-ref ref="CONSOLE_APPENDER"/>
</root>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ public static OrderBook adaptKrakenFuturesSnapshot(KrakenFuturesStreamingOrderBo
List<LimitOrder> asks = new ArrayList<>();
List<LimitOrder> bids = new ArrayList<>();

snapshot.getBids().forEach(krakenFuturesSnapShotOrder -> bids.add(new LimitOrder.Builder(Order.OrderType.BID, KrakenFuturesAdapters.adaptInstrument(snapshot.getProduct_id().toLowerCase()))
snapshot.getBids().forEach(krakenFuturesSnapShotOrder -> bids.add(new LimitOrder.Builder(Order.OrderType.BID, KrakenFuturesAdapters.adaptInstrument(snapshot.getProduct_id()))
.limitPrice(krakenFuturesSnapShotOrder.getPrice())
.originalAmount(krakenFuturesSnapShotOrder.getQuantity())
.build()));
snapshot.getAsks().forEach(krakenFuturesSnapShotOrder -> asks.add(new LimitOrder.Builder(Order.OrderType.ASK, KrakenFuturesAdapters.adaptInstrument(snapshot.getProduct_id().toLowerCase()))
snapshot.getAsks().forEach(krakenFuturesSnapShotOrder -> asks.add(new LimitOrder.Builder(Order.OrderType.ASK, KrakenFuturesAdapters.adaptInstrument(snapshot.getProduct_id()))
.limitPrice(krakenFuturesSnapShotOrder.getPrice())
.originalAmount(krakenFuturesSnapShotOrder.getQuantity())
.build()));
Expand All @@ -35,7 +35,7 @@ public static OrderBook adaptKrakenFuturesSnapshot(KrakenFuturesStreamingOrderBo

public static Ticker adaptTicker(KrakenFuturesStreamingTickerResponse tickerResponse) {
return new Ticker.Builder()
.instrument(KrakenFuturesAdapters.adaptInstrument(tickerResponse.getProduct_id().toLowerCase()))
.instrument(KrakenFuturesAdapters.adaptInstrument(tickerResponse.getProduct_id()))
.ask(tickerResponse.getAsk())
.bid(tickerResponse.getBid())
.last(tickerResponse.getLast())
Expand All @@ -50,7 +50,7 @@ public static Ticker adaptTicker(KrakenFuturesStreamingTickerResponse tickerResp

public static FundingRate adaptFundingRate(KrakenFuturesStreamingTickerResponse tickerResponse) {
return new FundingRate.Builder()
.instrument(KrakenFuturesAdapters.adaptInstrument(tickerResponse.getProduct_id().toLowerCase()))
.instrument(KrakenFuturesAdapters.adaptInstrument(tickerResponse.getProduct_id()))
.fundingRate1h(tickerResponse.getRelative_funding_rate())
.fundingRate8h((tickerResponse.getRelative_funding_rate() == null)
? null
Expand All @@ -62,7 +62,7 @@ public static FundingRate adaptFundingRate(KrakenFuturesStreamingTickerResponse
public static Trade adaptTrade(KrakenFuturesStreamingTradeResponse trade) {
return new Trade.Builder()
.price(trade.getPrice())
.instrument(KrakenFuturesAdapters.adaptInstrument(trade.getProduct_id().toLowerCase()))
.instrument(KrakenFuturesAdapters.adaptInstrument(trade.getProduct_id()))
.timestamp(trade.getTime())
.type((trade.getSide().equals(KrakenFuturesStreamingOrderBookDeltaResponse.KrakenFuturesStreamingSide.sell) ? Order.OrderType.ASK : Order.OrderType.BID))
.id(trade.getUid())
Expand All @@ -82,7 +82,7 @@ public static List<UserTrade> adaptUserTrades(KrakenFuturesStreamingFillsDeltaRe
.feeCurrency(new Currency(krakenFuturesStreamingFill.getFee_currency()))
.feeAmount(krakenFuturesStreamingFill.getFee_paid())
.type((krakenFuturesStreamingFill.isBuy()) ? Order.OrderType.BID : Order.OrderType.ASK)
.instrument(KrakenFuturesAdapters.adaptInstrument(krakenFuturesStreamingFill.getInstrument().toLowerCase()))
.instrument(KrakenFuturesAdapters.adaptInstrument(krakenFuturesStreamingFill.getInstrument()))
.timestamp(krakenFuturesStreamingFill.getTime())
.build()));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public Observable<Ticker> getTicker(Instrument instrument, Object... args) {

return service.subscribeChannel(channelName)
.filter(message-> message.has("feed") && message.has("product_id"))
.filter(message-> message.get("product_id").asText().toLowerCase().equals(KrakenFuturesAdapters.adaptKrakenFuturesSymbol(instrument)))
.filter(message-> message.get("product_id").asText().equals(KrakenFuturesAdapters.adaptKrakenFuturesSymbol(instrument)))
.map(message-> KrakenFuturesStreamingAdapters.adaptTicker(objectMapper.treeToValue(message, KrakenFuturesStreamingTickerResponse.class)));
}

Expand All @@ -83,7 +83,7 @@ public Observable<FundingRate> getFundingRate(Instrument instrument, Object... a

return service.subscribeChannel(channelName)
.filter(message-> message.has("feed") && message.has("product_id"))
.filter(message-> message.get("product_id").asText().toLowerCase().equals(KrakenFuturesAdapters.adaptKrakenFuturesSymbol(instrument)))
.filter(message-> message.get("product_id").asText().equals(KrakenFuturesAdapters.adaptKrakenFuturesSymbol(instrument)))
.map(message-> KrakenFuturesStreamingAdapters.adaptFundingRate(objectMapper.treeToValue(message, KrakenFuturesStreamingTickerResponse.class)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,11 @@ protected String getChannelNameFromMessage(JsonNode message) {

if(message.has("feed") && message.has("product_id")){
if(message.get("feed").asText().contains(ORDERBOOK)){
channelName = ORDERBOOK+message.get("product_id").asText().toLowerCase();
channelName = ORDERBOOK+message.get("product_id").asText();
} else if(message.get("feed").asText().contains(TICKER)){
channelName = TICKER+message.get("product_id").asText().toLowerCase();
channelName = TICKER+message.get("product_id").asText();
} else if(message.get("feed").asText().contains(TRADES)){
channelName = TRADES+message.get("product_id").asText().toLowerCase();
channelName = TRADES+message.get("product_id").asText();
}
}
// Fills
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
</appender>


<root level="DEBUG">
<root level="WARN">
<appender-ref ref="CONSOLE_APPENDER"/>
</root>

Expand Down
Loading