Search in sources :

Example 1 with DeribitInstrument

use of org.knowm.xchange.deribit.v2.dto.marketdata.DeribitInstrument in project XChange by knowm.

the class DeribitMarketdataDemo method raw.

private static void raw(Exchange exchange) throws IOException {
    DeribitMarketDataService service = (DeribitMarketDataService) exchange.getMarketDataService();
    String instrumentName = "BTC-PERPETUAL";
    String currency = "BTC";
    DeribitTicker ticker = service.getDeribitTicker(instrumentName);
    System.out.println(ticker);
    DeribitOrderBook orderBook = service.getDeribitOrderBook(instrumentName, null);
    System.out.println(orderBook);
    DeribitTrades trades = service.getLastTradesByInstrument(instrumentName, null, null, null, null, null);
    System.out.println(trades);
    List<DeribitCurrency> currencies = service.getDeribitCurrencies();
    System.out.println(currencies);
    List<DeribitInstrument> instruments = service.getDeribitInstruments(currency, Kind.future, false);
    System.out.println(instruments);
    List<DeribitSummary> summaries = service.getSummaryByInstrument(instrumentName);
    System.out.println(summaries);
}
Also used : DeribitTrades(org.knowm.xchange.deribit.v2.dto.marketdata.DeribitTrades) DeribitInstrument(org.knowm.xchange.deribit.v2.dto.marketdata.DeribitInstrument) DeribitCurrency(org.knowm.xchange.deribit.v2.dto.marketdata.DeribitCurrency) DeribitMarketDataService(org.knowm.xchange.deribit.v2.service.DeribitMarketDataService) DeribitTicker(org.knowm.xchange.deribit.v2.dto.marketdata.DeribitTicker) DeribitOrderBook(org.knowm.xchange.deribit.v2.dto.marketdata.DeribitOrderBook) DeribitSummary(org.knowm.xchange.deribit.v2.dto.marketdata.DeribitSummary)

Example 2 with DeribitInstrument

use of org.knowm.xchange.deribit.v2.dto.marketdata.DeribitInstrument in project XChange by knowm.

the class DeribitAdapters method adaptInstrument.

public static Instrument adaptInstrument(String instrumentName) {
    String[] parts = instrumentName.split("-");
    if (parts.length == 2) {
        DeribitInstrument future = new DeribitInstrument();
        future.setBaseCurrency(parts[0]);
        future.setQuoteCurrency(IMPLIED_COUNTER);
        if (PERPETUAL.equalsIgnoreCase(parts[1])) {
            future.setSettlementPeriod(PERPETUAL);
        } else {
            try {
                future.setExpirationTimestamp(parseDate(parts[1]).getTime());
            } catch (ParseException e) {
                throw new IllegalArgumentException("Could not adapt instrument from name '" + instrumentName + "'");
            }
        }
        return adaptFuturesContract(future);
    } else if (parts.length >= 3 && PERPETUAL.equalsIgnoreCase(parts[2])) {
        DeribitInstrument future = new DeribitInstrument();
        future.setBaseCurrency(parts[0]);
        future.setQuoteCurrency(parts[1]);
        future.setSettlementPeriod(PERPETUAL);
        return adaptFuturesContract(future);
    } else if (parts.length == 4) {
        DeribitInstrument option = new DeribitInstrument();
        option.setBaseCurrency(parts[0]);
        try {
            option.setExpirationTimestamp(parseDate(parts[1]).getTime());
        } catch (ParseException e) {
            throw new IllegalArgumentException("Could not adapt instrument from name '" + instrumentName + "'");
        }
        option.setInstrumentName(instrumentName);
        return adaptOptionsContract(option);
    }
    throw new IllegalArgumentException("Could not adapt instrument from name '" + instrumentName + "'");
}
Also used : DeribitInstrument(org.knowm.xchange.deribit.v2.dto.marketdata.DeribitInstrument) ParseException(java.text.ParseException)

Example 3 with DeribitInstrument

use of org.knowm.xchange.deribit.v2.dto.marketdata.DeribitInstrument in project XChange by knowm.

the class DeribitExchange method updateExchangeMetaData.

public void updateExchangeMetaData() throws IOException {
    Map<Currency, CurrencyMetaData> currencies = exchangeMetaData.getCurrencies();
    Map<FuturesContract, DerivativeMetaData> futures = exchangeMetaData.getFutures();
    Map<OptionsContract, DerivativeMetaData> options = exchangeMetaData.getOptions();
    List<DeribitCurrency> activeDeribitCurrencies = ((DeribitMarketDataServiceRaw) marketDataService).getDeribitCurrencies();
    currencies.clear();
    futures.clear();
    options.clear();
    for (DeribitCurrency deribitCurrency : activeDeribitCurrencies) {
        currencies.put(new Currency(deribitCurrency.getCurrency()), DeribitAdapters.adaptMeta(deribitCurrency));
        List<DeribitInstrument> deribitInstruments = ((DeribitMarketDataServiceRaw) marketDataService).getDeribitInstruments(deribitCurrency.getCurrency(), null, null);
        for (DeribitInstrument deribitInstrument : deribitInstruments) {
            if (deribitInstrument.getKind() == Kind.future) {
                futures.put(DeribitAdapters.adaptFuturesContract(deribitInstrument), DeribitAdapters.adaptMeta(deribitInstrument));
            } else {
                options.put(DeribitAdapters.adaptOptionsContract(deribitInstrument), DeribitAdapters.adaptMeta(deribitInstrument));
            }
        }
    }
}
Also used : DerivativeMetaData(org.knowm.xchange.dto.meta.DerivativeMetaData) DeribitInstrument(org.knowm.xchange.deribit.v2.dto.marketdata.DeribitInstrument) CurrencyMetaData(org.knowm.xchange.dto.meta.CurrencyMetaData) FuturesContract(org.knowm.xchange.derivative.FuturesContract) OptionsContract(org.knowm.xchange.derivative.OptionsContract) DeribitCurrency(org.knowm.xchange.deribit.v2.dto.marketdata.DeribitCurrency) Currency(org.knowm.xchange.currency.Currency) DeribitCurrency(org.knowm.xchange.deribit.v2.dto.marketdata.DeribitCurrency) DeribitMarketDataServiceRaw(org.knowm.xchange.deribit.v2.service.DeribitMarketDataServiceRaw)

Aggregations

DeribitInstrument (org.knowm.xchange.deribit.v2.dto.marketdata.DeribitInstrument)3 DeribitCurrency (org.knowm.xchange.deribit.v2.dto.marketdata.DeribitCurrency)2 ParseException (java.text.ParseException)1 Currency (org.knowm.xchange.currency.Currency)1 DeribitOrderBook (org.knowm.xchange.deribit.v2.dto.marketdata.DeribitOrderBook)1 DeribitSummary (org.knowm.xchange.deribit.v2.dto.marketdata.DeribitSummary)1 DeribitTicker (org.knowm.xchange.deribit.v2.dto.marketdata.DeribitTicker)1 DeribitTrades (org.knowm.xchange.deribit.v2.dto.marketdata.DeribitTrades)1 DeribitMarketDataService (org.knowm.xchange.deribit.v2.service.DeribitMarketDataService)1 DeribitMarketDataServiceRaw (org.knowm.xchange.deribit.v2.service.DeribitMarketDataServiceRaw)1 FuturesContract (org.knowm.xchange.derivative.FuturesContract)1 OptionsContract (org.knowm.xchange.derivative.OptionsContract)1 CurrencyMetaData (org.knowm.xchange.dto.meta.CurrencyMetaData)1 DerivativeMetaData (org.knowm.xchange.dto.meta.DerivativeMetaData)1