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;
}
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");
}
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();
}
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"));
}
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();
}
Aggregations