Search in sources :

Example 1 with FuturesContract

use of org.knowm.xchange.derivative.FuturesContract in project XChange by knowm.

the class InstrumentDeserializer method deserialize.

@Override
public Instrument deserialize(JsonParser jsonParser, final DeserializationContext ctxt) throws IOException {
    final ObjectCodec oc = jsonParser.getCodec();
    final JsonNode node = oc.readTree(jsonParser);
    final String instrumentString = node.asText();
    long count = instrumentString.chars().filter(ch -> ch == '/').count();
    // CurrencyPair (Base/Counter) i.e. BTC/USD
    if (count == 1)
        return new CurrencyPair(instrumentString);
    // Futures/Swaps (Base/Counter/Prompt) i.e. BTC/USD/200925
    if (count == 2)
        return new FuturesContract(instrumentString);
    // Options (Base/Counter/Prompt/StrikePrice/Put?Call) i.e. BTC/USD/200925/8956.67/P
    if (count == 4)
        return new OptionsContract(instrumentString);
    else
        return null;
}
Also used : DeserializationContext(com.fasterxml.jackson.databind.DeserializationContext) FuturesContract(org.knowm.xchange.derivative.FuturesContract) JsonParser(com.fasterxml.jackson.core.JsonParser) Instrument(org.knowm.xchange.instrument.Instrument) ObjectCodec(com.fasterxml.jackson.core.ObjectCodec) JsonNode(com.fasterxml.jackson.databind.JsonNode) IOException(java.io.IOException) JsonDeserializer(com.fasterxml.jackson.databind.JsonDeserializer) OptionsContract(org.knowm.xchange.derivative.OptionsContract) CurrencyPair(org.knowm.xchange.currency.CurrencyPair) FuturesContract(org.knowm.xchange.derivative.FuturesContract) JsonNode(com.fasterxml.jackson.databind.JsonNode) ObjectCodec(com.fasterxml.jackson.core.ObjectCodec) CurrencyPair(org.knowm.xchange.currency.CurrencyPair) OptionsContract(org.knowm.xchange.derivative.OptionsContract)

Example 2 with FuturesContract

use of org.knowm.xchange.derivative.FuturesContract in project XChange by knowm.

the class DeribitAdaptersTest method adaptTrade.

@Test
public void adaptTrade() throws IOException {
    // given
    InputStream is = DeribitTrade.class.getResourceAsStream("/org/knowm/xchange/deribit/v2/dto/marketdata/example-trade.json");
    ObjectMapper mapper = new ObjectMapper();
    DeribitTrade deribitTrade = mapper.readValue(is, DeribitTrade.class);
    // when
    Trade trade = DeribitAdapters.adaptTrade(deribitTrade, new FuturesContract("BTC/USD/PERPETUAL"));
    // then
    assertThat(trade).isNotNull();
    assertThat(trade.getType()).isEqualTo(Order.OrderType.ASK);
    assertThat(trade.getOriginalAmount()).isEqualTo(new BigDecimal("10"));
    assertThat(trade.getPrice()).isEqualTo(new BigDecimal("3610"));
    assertThat(trade.getTimestamp().getTime()).isEqualTo(1550050591859L);
    assertThat(trade.getId()).isEqualTo("48470");
}
Also used : DeribitTrade(org.knowm.xchange.deribit.v2.dto.marketdata.DeribitTrade) Trade(org.knowm.xchange.dto.marketdata.Trade) InputStream(java.io.InputStream) DeribitTrade(org.knowm.xchange.deribit.v2.dto.marketdata.DeribitTrade) FuturesContract(org.knowm.xchange.derivative.FuturesContract) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Example 3 with FuturesContract

use of org.knowm.xchange.derivative.FuturesContract in project XChange by knowm.

the class DeribitTradesFetchIntegration method getTradesTest.

@Test
public void getTradesTest() throws Exception {
    Instrument pair = new FuturesContract(CurrencyPair.BTC_USD, null);
    Trades trades = deribitMarketDataService.getTrades(pair);
    assertThat(trades).isNotNull();
    assertThat(trades.getTrades()).isNotEmpty();
}
Also used : DeribitTrades(org.knowm.xchange.deribit.v2.dto.marketdata.DeribitTrades) Trades(org.knowm.xchange.dto.marketdata.Trades) Instrument(org.knowm.xchange.instrument.Instrument) FuturesContract(org.knowm.xchange.derivative.FuturesContract) Test(org.junit.Test)

Example 4 with FuturesContract

use of org.knowm.xchange.derivative.FuturesContract in project XChange by knowm.

the class DeribitAdaptersTest method adaptInstrument.

@Test
public void adaptInstrument() {
    Instrument instrument = DeribitAdapters.adaptInstrument("BTC-USDT-PERPETUAL-F");
    assertThat(instrument).isExactlyInstanceOf(FuturesContract.class);
    assertThat(instrument).isEqualTo(new FuturesContract("BTC/USDT/PERPETUAL"));
// TODO make the other Instruments to pass
// instrument = DeribitAdapters.adaptInstrument("ETH-PERPETUAL");
// assertThat(instrument).isExactlyInstanceOf(FuturesContract.class);
// assertThat(instrument).isEqualTo(new FuturesContract("ETH/USD/perpetual"));
// 
// instrument = DeribitAdapters.adaptInstrument("ETH-31DEC21");
// assertThat(instrument).isExactlyInstanceOf(FuturesContract.class);
// assertThat(instrument).isEqualTo(new FuturesContract("ETH/USD/211231"));
// 
// instrument = DeribitAdapters.adaptInstrument("ETH-9SEP21-2040-P");
// assertThat(instrument).isExactlyInstanceOf(OptionsContract.class);
// assertThat(instrument).isEqualTo(new OptionsContract("ETH/USD/210909/2040/P"));
// 
// instrument = DeribitAdapters.adaptInstrument("BTC-PERPETUAL");
// assertThat(instrument).isExactlyInstanceOf(FuturesContract.class);
// assertThat(instrument).isEqualTo(new FuturesContract("BTC/USD/perpetual"));
// 
// instrument = DeribitAdapters.adaptInstrument("BTC-25MAR22");
// assertThat(instrument).isExactlyInstanceOf(FuturesContract.class);
// assertThat(instrument).isEqualTo(new FuturesContract("BTC/USD/220325"));
// 
// instrument = DeribitAdapters.adaptInstrument("BTC-24SEP21-7000-P");
// assertThat(instrument).isExactlyInstanceOf(OptionsContract.class);
// assertThat(instrument).isEqualTo(new OptionsContract("BTC/USD/210924/7000/P"));
}
Also used : Instrument(org.knowm.xchange.instrument.Instrument) FuturesContract(org.knowm.xchange.derivative.FuturesContract) Test(org.junit.Test)

Example 5 with FuturesContract

use of org.knowm.xchange.derivative.FuturesContract in project XChange by knowm.

the class DeribitOrderBookFetchIntegration method getOrderBookTest.

@Test
public void getOrderBookTest() throws Exception {
    Instrument pair = new FuturesContract(CurrencyPair.BTC_USD, null);
    OrderBook orderBook = deribitMarketDataService.getOrderBook(pair, null);
    assertThat(orderBook).isNotNull();
    assertThat(orderBook.getBids()).isNotEmpty();
    assertThat(orderBook.getAsks()).isNotEmpty();
}
Also used : DeribitOrderBook(org.knowm.xchange.deribit.v2.dto.marketdata.DeribitOrderBook) OrderBook(org.knowm.xchange.dto.marketdata.OrderBook) Instrument(org.knowm.xchange.instrument.Instrument) FuturesContract(org.knowm.xchange.derivative.FuturesContract) Test(org.junit.Test)

Aggregations

FuturesContract (org.knowm.xchange.derivative.FuturesContract)12 Test (org.junit.Test)6 Instrument (org.knowm.xchange.instrument.Instrument)5 BigDecimal (java.math.BigDecimal)3 OrderBook (org.knowm.xchange.dto.marketdata.OrderBook)3 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 CurrencyPair (org.knowm.xchange.currency.CurrencyPair)2 DeribitOrderBook (org.knowm.xchange.deribit.v2.dto.marketdata.DeribitOrderBook)2 OptionsContract (org.knowm.xchange.derivative.OptionsContract)2 Trades (org.knowm.xchange.dto.marketdata.Trades)2 MarketDataService (org.knowm.xchange.service.marketdata.MarketDataService)2 JsonParser (com.fasterxml.jackson.core.JsonParser)1 ObjectCodec (com.fasterxml.jackson.core.ObjectCodec)1 DeserializationContext (com.fasterxml.jackson.databind.DeserializationContext)1 JsonDeserializer (com.fasterxml.jackson.databind.JsonDeserializer)1 JsonNode (com.fasterxml.jackson.databind.JsonNode)1 Date (java.util.Date)1 Currency (org.knowm.xchange.currency.Currency)1