org.knowm.xchange.ExchangeSpecification Java Examples

The following examples show how to use org.knowm.xchange.ExchangeSpecification. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: OkCoinExchange.java    From zheshiyigeniubidexiangmu with MIT License 6 votes vote down vote up
/** Adjust host parameters depending on exchange specific parameters */
private static void concludeHostParams(ExchangeSpecification exchangeSpecification) {

  if (exchangeSpecification.getExchangeSpecificParameters() != null) {
    if (exchangeSpecification.getExchangeSpecificParametersItem("Use_Intl").equals(true)
        && exchangeSpecification.getExchangeSpecificParametersItem("Use_Futures").equals(false)) {

      exchangeSpecification.setSslUri("https://www.okex.com/api");
      exchangeSpecification.setHost("www.okex.com");

    } else if (exchangeSpecification.getExchangeSpecificParametersItem("Use_Intl").equals(true)
        && exchangeSpecification.getExchangeSpecificParametersItem("Use_Futures").equals(true)) {

      exchangeSpecification.setSslUri("https://www.okex.com/api");
      exchangeSpecification.setHost("www.okex.com");
    }
  }
}
 
Example #2
Source File: ReactiveKnowmExchangeProvider.java    From consensusj with Apache License 2.0 6 votes vote down vote up
public ReactiveKnowmExchangeProvider(ExchangeSpecification exchangeSpecification,
                                      String exchangeClassName,
                                      Map<CurrencyUnit, String> tickerSymbolConversions,
                                      Collection<CurrencyUnitPair> pairs,
                                      Observable<Long> interval) {
    this.exchangeSpecification = exchangeSpecification;
    if (exchangeSpecification != null) {
        this.exchangeClassName = exchangeSpecification.getExchangeClassName();
    } else {
        this.exchangeClassName = exchangeClassName;
    }
    this.tickerSymbolConversions = (tickerSymbolConversions != null) ? tickerSymbolConversions : Collections.emptyMap();
    this.interval = interval;
    for (CurrencyUnitPair pair : pairs) {
        MonitoredCurrency observablePair = new MonitoredCurrency(pair, xchangePair(pair));
        observablePairs.put(pair, observablePair);
    }
}
 
Example #3
Source File: OkCoinExchange.java    From zheshiyigeniubidexiangmu with MIT License 6 votes vote down vote up
@Override
public ExchangeSpecification getDefaultExchangeSpecification() {

  ExchangeSpecification exchangeSpecification =
      new ExchangeSpecification(this.getClass().getCanonicalName());
  exchangeSpecification.setSslUri("https://www.okex.com/api");
  exchangeSpecification.setHost("www.okex.com");
  exchangeSpecification.setExchangeName("OKCoin");
  exchangeSpecification.setExchangeDescription(
      "OKCoin is a globally oriented crypto-currency trading platform.");

  // set to true to automatically use the Intl_ parameters for ssluri and host
  exchangeSpecification.setExchangeSpecificParametersItem("Use_Intl", false);
  exchangeSpecification.setExchangeSpecificParametersItem("Use_Futures", false);

  return exchangeSpecification;
}
 
Example #4
Source File: OkCoinExchange.java    From zheshiyigeniubidexiangmu with MIT License 5 votes vote down vote up
/** Extract futures leverage used by spec */
private static int futuresLeverageOfConfig(ExchangeSpecification exchangeSpecification) {

  if (exchangeSpecification.getExchangeSpecificParameters().containsKey("Futures_Leverage")) {
    return Integer.valueOf(
        (String) exchangeSpecification.getExchangeSpecificParameters().get("Futures_Leverage"));
  } else {
    // default choice of 10x leverage is "safe" choice and default by OkCoin.
    return 10;
  }
}
 
Example #5
Source File: ExchangeFeeCacheTest.java    From arbitrader with MIT License 5 votes vote down vote up
@Test
public void testGetUnknownExchange() {
    Exchange altExchange = mock(Exchange.class);
    ExchangeSpecification altSpec = mock(ExchangeSpecification.class);

    when(altExchange.getExchangeSpecification()).thenReturn(altSpec);
    when(altSpec.getExchangeName()).thenReturn("AltEx");

    assertNull(exchangeFeeCache.getCachedFee(altExchange, currencyPair));
}
 
Example #6
Source File: BlockchainExchange.java    From zheshiyigeniubidexiangmu with MIT License 5 votes vote down vote up
@Override
public ExchangeSpecification getDefaultExchangeSpecification() {

  ExchangeSpecification exchangeSpecification =
      new ExchangeSpecification(this.getClass().getCanonicalName());
  exchangeSpecification.setPlainTextUri("https://blockchain.info");
  exchangeSpecification.setHost("blockchain.info");
  exchangeSpecification.setPort(80);
  exchangeSpecification.setExchangeName("Blockchain");
  exchangeSpecification.setExchangeDescription(
      "Blockchain provide an API for accessing the Botcoin Network.");
  return exchangeSpecification;
}
 
Example #7
Source File: FCoinExchange.java    From zheshiyigeniubidexiangmu with MIT License 5 votes vote down vote up
@Override
public ExchangeSpecification getDefaultExchangeSpecification() {

  ExchangeSpecification exchangeSpecification =
      new ExchangeSpecification(this.getClass().getCanonicalName());
  exchangeSpecification.setSslUri("https://api.fcoin.com");
  exchangeSpecification.setHost("api.fcoin.com");
  exchangeSpecification.setExchangeName("FCoin");
  exchangeSpecification.setMetaDataJsonFileOverride(null);
  exchangeSpecification.setExchangeDescription(
      "FCoin is a globally oriented crypto-currency trading platform.");

  return exchangeSpecification;
}
 
Example #8
Source File: CoinbaseExchange.java    From zheshiyigeniubidexiangmu with MIT License 5 votes vote down vote up
@Override
public ExchangeSpecification getDefaultExchangeSpecification() {

  final ExchangeSpecification exchangeSpecification =
      new ExchangeSpecification(this.getClass().getCanonicalName());
  exchangeSpecification.setSslUri("https://api.coinbase.com/v2");
  exchangeSpecification.setHost("api.coinbase.com");
  exchangeSpecification.setExchangeName("Coinbase");
  exchangeSpecification.setExchangeDescription(
      "Founded in June of 2012, Coinbase is a bitcoin wallet and platform where merchants and consumers can transact with the new digital currency bitcoin.");
  return exchangeSpecification;
}
 
Example #9
Source File: CoinbaseExchange.java    From zheshiyigeniubidexiangmu with MIT License 5 votes vote down vote up
@Override
public ExchangeSpecification getDefaultExchangeSpecification() {

  final ExchangeSpecification exchangeSpecification =
      new ExchangeSpecification(this.getClass().getCanonicalName());
  exchangeSpecification.setSslUri("https://coinbase.com");
  exchangeSpecification.setHost("coinbase.com");
  exchangeSpecification.setExchangeName("Coinbase");
  exchangeSpecification.setExchangeDescription(
      "Founded in June of 2012, Coinbase is a bitcoin wallet and platform where merchants and consumers can transact with the new digital currency bitcoin.");
  return exchangeSpecification;
}
 
Example #10
Source File: OkCoinExchange.java    From zheshiyigeniubidexiangmu with MIT License 5 votes vote down vote up
@Override
public String getMetaDataFileName(ExchangeSpecification exchangeSpecification) {

  if (exchangeSpecification.getExchangeSpecificParametersItem("Use_Intl").equals(false)) {
    return exchangeSpecification
            .getExchangeName()
            .toLowerCase()
            .replace(" ", "")
            .replace("-", "")
            .replace(".", "")
        + "_china";
  } else {
    if (exchangeSpecification.getExchangeSpecificParametersItem("Use_Futures").equals(true)) {
      return exchangeSpecification
              .getExchangeName()
              .toLowerCase()
              .replace(" ", "")
              .replace("-", "")
              .replace(".", "")
          + "_futures";
    } else {
      return exchangeSpecification
              .getExchangeName()
              .toLowerCase()
              .replace(" ", "")
              .replace("-", "")
              .replace(".", "")
          + "_intl";
    }
  }
}
 
Example #11
Source File: BitmexExchange.java    From zheshiyigeniubidexiangmu with MIT License 5 votes vote down vote up
/** Adjust host parameters depending on exchange specific parameters */
private static void concludeHostParams(ExchangeSpecification exchangeSpecification) {

  if (exchangeSpecification.getExchangeSpecificParameters() != null) {
    if (exchangeSpecification.getExchangeSpecificParametersItem("Use_Sandbox").equals(true)) {
      exchangeSpecification.setSslUri("https://testnet.bitmex.com/");
      exchangeSpecification.setHost("testnet.bitmex.com");
    }
  }
}
 
Example #12
Source File: OkCoinExchange.java    From zheshiyigeniubidexiangmu with MIT License 5 votes vote down vote up
@Override
public void applySpecification(ExchangeSpecification exchangeSpecification) {

  super.applySpecification(exchangeSpecification);

  if (exchangeSpecification.getExchangeSpecificParametersItem("Use_Intl").equals(false)
      && exchangeSpecification.getExchangeSpecificParametersItem("Use_Futures").equals(true)) {
    throw new RuntimeException(
        "Futures only available on international version. Set `Use_Intl` to true.");
  }

  concludeHostParams(exchangeSpecification);
}
 
Example #13
Source File: OkCoinExchange.java    From zheshiyigeniubidexiangmu with MIT License 5 votes vote down vote up
/** Extract contract used by spec */
public static FuturesContract futuresContractOfConfig(
    ExchangeSpecification exchangeSpecification) {

  FuturesContract contract;

  if (exchangeSpecification.getExchangeSpecificParameters().containsKey("Futures_Contract")) {
    contract =
        (FuturesContract)
            exchangeSpecification.getExchangeSpecificParameters().get("Futures_Contract");
  } else if (exchangeSpecification
      .getExchangeSpecificParameters()
      .containsKey("Futures_Contract_String")) {
    contract =
        FuturesContract.valueOfIgnoreCase(
            FuturesContract.class,
            (String)
                exchangeSpecification
                    .getExchangeSpecificParameters()
                    .get("Futures_Contract_String"));
  } else {
    throw new RuntimeException(
        "`Futures_Contract` or `Futures_Contract_String` not defined in exchange specific parameters.");
  }

  return contract;
}
 
Example #14
Source File: BitZExchange.java    From zheshiyigeniubidexiangmu with MIT License 5 votes vote down vote up
@Override
public ExchangeSpecification getDefaultExchangeSpecification() {
  ExchangeSpecification exchangeSpecification =
      new ExchangeSpecification(this.getClass().getCanonicalName());
  exchangeSpecification.setSslUri("https://www.bit-z.com");
  exchangeSpecification.setHost("http://www.bit-z.com");
  exchangeSpecification.setPort(80);
  exchangeSpecification.setExchangeName("Bit-Z");
  exchangeSpecification.setExchangeDescription(
      "Bit-Z is a Bitcoin exchange registered in Hong Kong.");

  return exchangeSpecification;
}
 
Example #15
Source File: BitfinexExchange.java    From zheshiyigeniubidexiangmu with MIT License 5 votes vote down vote up
@Override
public ExchangeSpecification getDefaultExchangeSpecification() {

  ExchangeSpecification exchangeSpecification =
      new ExchangeSpecification(this.getClass().getCanonicalName());
  exchangeSpecification.setSslUri("https://api.bitfinex.com/");
  exchangeSpecification.setHost("api.bitfinex.com");
  exchangeSpecification.setPort(80);
  exchangeSpecification.setExchangeName("Bitfinex");
  exchangeSpecification.setExchangeDescription("Bitfnex is a cryptocurrency and fiat exchange.");

  return exchangeSpecification;
}
 
Example #16
Source File: BitfinexExchange.java    From zheshiyigeniubidexiangmu with MIT License 5 votes vote down vote up
@Override
public ExchangeSpecification getDefaultExchangeSpecification() {

  ExchangeSpecification exchangeSpecification =
      new ExchangeSpecification(this.getClass().getCanonicalName());
  exchangeSpecification.setSslUri("https://api.bitfinex.com/");
  exchangeSpecification.setHost("api.bitfinex.com");
  exchangeSpecification.setPort(80);
  exchangeSpecification.setExchangeName("BitFinex");
  exchangeSpecification.setExchangeDescription("BitFinex is a bitcoin exchange.");

  return exchangeSpecification;
}
 
Example #17
Source File: AuthUtils.java    From zheshiyigeniubidexiangmu with MIT License 5 votes vote down vote up
/**
 * Read the API & Secret key from a resource called {@code prefix}-{@code secret.keys}. NOTE: This
 * file MUST NEVER be commited to source control. It is therefore added to .gitignore.
 */
public static void setApiAndSecretKey(ExchangeSpecification exchangeSpec, String prefix) {

  Properties props = getSecretProperties(prefix);

  if (props != null) {
    exchangeSpec.setApiKey(props.getProperty("apiKey"));
    exchangeSpec.setSecretKey(props.getProperty("secretKey"));
  }
}
 
Example #18
Source File: HuobiExchange.java    From zheshiyigeniubidexiangmu with MIT License 5 votes vote down vote up
@Override
public ExchangeSpecification getDefaultExchangeSpecification() {
  ExchangeSpecification exchangeSpecification =
      new ExchangeSpecification(this.getClass().getCanonicalName());
  exchangeSpecification.setSslUri("https://api.huobi.pro");
  exchangeSpecification.setHost("api.huobi.pro");
  exchangeSpecification.setPort(80);
  exchangeSpecification.setExchangeName("Huobi");
  exchangeSpecification.setExchangeDescription(
      "Huobi is a Chinese digital currency trading platform and exchange based in Beijing");
  return exchangeSpecification;
}
 
Example #19
Source File: BiboxExchange.java    From zheshiyigeniubidexiangmu with MIT License 5 votes vote down vote up
@Override
public ExchangeSpecification getDefaultExchangeSpecification() {
  ExchangeSpecification exchangeSpecification =
      new ExchangeSpecification(this.getClass().getCanonicalName());
  exchangeSpecification.setSslUri("https://api.bibox.com/");
  exchangeSpecification.setHost("bibox.com");
  exchangeSpecification.setPort(80);
  exchangeSpecification.setExchangeName("Bibox");
  exchangeSpecification.setExchangeDescription("AI ENHANCED ENCRYPTED DIGITAL ASSET EXCHANGE.");

  return exchangeSpecification;
}
 
Example #20
Source File: BinanceExchange.java    From zheshiyigeniubidexiangmu with MIT License 5 votes vote down vote up
@Override
public ExchangeSpecification getDefaultExchangeSpecification() {

  ExchangeSpecification spec = new ExchangeSpecification(this.getClass().getCanonicalName());
  spec.setSslUri("https://api.binance.com");
  spec.setHost("www.binance.com");
  spec.setPort(80);
  spec.setExchangeName("Binance");
  spec.setExchangeDescription("Binance Exchange.");
  AuthUtils.setApiAndSecretKey(spec, "binance");
  return spec;
}
 
Example #21
Source File: BitmexExchange.java    From zheshiyigeniubidexiangmu with MIT License 5 votes vote down vote up
@Override
public ExchangeSpecification getDefaultExchangeSpecification() {

  ExchangeSpecification exchangeSpecification =
      new ExchangeSpecification(this.getClass().getCanonicalName());
  exchangeSpecification.setSslUri("https://www.bitmex.com/");
  exchangeSpecification.setHost("bitmex.com");
  exchangeSpecification.setPort(80);
  exchangeSpecification.setExchangeName("Bitmex");
  exchangeSpecification.setExchangeDescription("Bitmex is a bitcoin exchange");
  exchangeSpecification.setExchangeSpecificParametersItem("Use_Sandbox", false);
  return exchangeSpecification;
}
 
Example #22
Source File: ExchangeBuilder.java    From arbitrader with MIT License 4 votes vote down vote up
public Exchange build() throws IOException {
    Exchange exchange = mock(Exchange.class);
    ExchangeSpecification specification = mock(ExchangeSpecification.class);
    ExchangeConfiguration metadata = new ExchangeConfiguration();
    MarketDataService marketDataService = mock(MarketDataService.class);

    metadata.setHomeCurrency(homeCurrency);
    metadata.setTradingPairs(tradingPairs);
    metadata.setMargin(isMarginSupported);

    when(exchange.getExchangeSpecification()).thenReturn(specification);
    when(specification.getExchangeName()).thenReturn(name);
    when(specification.getExchangeSpecificParametersItem(METADATA_KEY)).thenReturn(metadata);
    when(exchange.getMarketDataService()).thenReturn(marketDataService);

    if (tickerException != null) {
        when(marketDataService.getTicker(any())).thenThrow(tickerException);
        when(marketDataService.getTickers(any(Params.class))).thenThrow(tickerException);
    }

    if (tickers != null && !tickers.isEmpty()) {
        tickers.forEach(ticker -> {
            try {
                when(marketDataService.getTicker(eq(ticker.getCurrencyPair()))).thenReturn(ticker);
            } catch (IOException e) {
                // nothing to do here if we couldn't build the mock
            }
        });

        if (isGetTickersImplemented) {
            when(marketDataService.getTickers(any())).thenReturn(tickers);
        } else {
            when(marketDataService.getTickers(any())).thenThrow(new NotYetImplementedForExchangeException());
        }
    }

    if (bids != null || asks != null) {
        OrderBook orderBook = new OrderBook(
            new Date(),
            generateOrders(currencyPair, Order.OrderType.ASK),
            generateOrders(currencyPair, Order.OrderType.BID)
        );

        when(marketDataService.getOrderBook(eq(currencyPair))).thenReturn(orderBook);
    }

    if (!balances.isEmpty()) {
        Wallet wallet = Wallet.Builder.from(balances).build();
        AccountInfo accountInfo = new AccountInfo(wallet);
        AccountService accountService = mock(AccountService.class);

        when(accountService.getAccountInfo()).thenReturn(accountInfo);
        when(exchange.getAccountService()).thenReturn(accountService);
    }

    if (tickerStrategy != null) {
        when(specification.getExchangeSpecificParametersItem(TICKER_STRATEGY_KEY)).thenReturn(tickerStrategy);
    }

    if (exchangeMetaData != null) {
        when(exchange.getExchangeMetaData()).thenReturn(exchangeMetaData);
    }

    if (tradeService != null) {
        when(exchange.getTradeService()).thenReturn(tradeService);
    }

    return exchange;
}
 
Example #23
Source File: AuthUtils.java    From zheshiyigeniubidexiangmu with MIT License 4 votes vote down vote up
/**
 * Read the API & Secret key from a resource called {@code secret.keys}. NOTE: This file MUST
 * NEVER be commited to source control. It is therefore added to .gitignore.
 */
public static void setApiAndSecretKey(ExchangeSpecification exchangeSpec) {

  setApiAndSecretKey(exchangeSpec, null);
}
 
Example #24
Source File: FCoinExchange.java    From zheshiyigeniubidexiangmu with MIT License 4 votes vote down vote up
@Override
public void applySpecification(ExchangeSpecification exchangeSpecification) {

  super.applySpecification(exchangeSpecification);
}
 
Example #25
Source File: ReactiveKnowmExchangeProvider.java    From consensusj with Apache License 2.0 4 votes vote down vote up
public ReactiveKnowmExchangeProvider(ExchangeSpecification exchangeSpecification,
                                     Map<CurrencyUnit, String> tickerSymbolConversions,
                                     Collection<CurrencyUnitPair> pairs,
                                     Observable<Long> interval) {
    this(exchangeSpecification, null, tickerSymbolConversions, pairs, interval);
}
 
Example #26
Source File: BitmexExchange.java    From zheshiyigeniubidexiangmu with MIT License 3 votes vote down vote up
@Override
public void applySpecification(ExchangeSpecification exchangeSpecification) {

  super.applySpecification(exchangeSpecification);

  concludeHostParams(exchangeSpecification);
}