Search in sources :

Example 1 with BitstampExchange

use of org.knowm.xchange.bitstamp.BitstampExchange in project XChange by knowm.

the class DepthChartDemo method main.

public static void main(String[] args) throws IOException {
    // Use the factory to get the version 1 Bitstamp exchange API using default settings
    Exchange bitstampExchange = ExchangeFactory.INSTANCE.createExchange(BitstampExchange.class);
    // Interested in the public market data feed (no authentication)
    MarketDataService marketDataService = bitstampExchange.getMarketDataService();
    System.out.println("fetching data...");
    // Get the current orderbook
    OrderBook orderBook = marketDataService.getOrderBook(CurrencyPair.BTC_USD);
    System.out.println("orderBook = " + orderBook);
    System.out.println("received data.");
    System.out.println("plotting...");
    // Create Chart
    XYChart chart = new XYChartBuilder().width(800).height(600).title("Bitstamp Order Book").xAxisTitle("BTC").yAxisTitle("USD").build();
    // Customize Chart
    chart.getStyler().setDefaultSeriesRenderStyle(XYSeriesRenderStyle.Area);
    // BIDS
    List<Number> xData = new ArrayList<>();
    List<Number> yData = new ArrayList<>();
    BigDecimal accumulatedBidUnits = new BigDecimal("0");
    for (LimitOrder limitOrder : orderBook.getBids()) {
        if (limitOrder.getLimitPrice().doubleValue() > 5000) {
            xData.add(limitOrder.getLimitPrice());
            accumulatedBidUnits = accumulatedBidUnits.add(limitOrder.getOriginalAmount());
            yData.add(accumulatedBidUnits);
        }
    }
    Collections.reverse(xData);
    Collections.reverse(yData);
    // Bids Series
    XYSeries series = chart.addSeries("bids", xData, yData);
    series.setMarker(SeriesMarkers.NONE);
    // ASKS
    xData = new ArrayList<>();
    yData = new ArrayList<>();
    BigDecimal accumulatedAskUnits = new BigDecimal("0");
    for (LimitOrder limitOrder : orderBook.getAsks()) {
        if (limitOrder.getLimitPrice().doubleValue() < 20000) {
            xData.add(limitOrder.getLimitPrice());
            accumulatedAskUnits = accumulatedAskUnits.add(limitOrder.getOriginalAmount());
            yData.add(accumulatedAskUnits);
        }
    }
    // Asks Series
    series = chart.addSeries("asks", xData, yData);
    series.setMarker(SeriesMarkers.NONE);
    new SwingWrapper(chart).displayChart();
}
Also used : XYSeries(org.knowm.xchart.XYSeries) OrderBook(org.knowm.xchange.dto.marketdata.OrderBook) ArrayList(java.util.ArrayList) SwingWrapper(org.knowm.xchart.SwingWrapper) BigDecimal(java.math.BigDecimal) Exchange(org.knowm.xchange.Exchange) BitstampExchange(org.knowm.xchange.bitstamp.BitstampExchange) MarketDataService(org.knowm.xchange.service.marketdata.MarketDataService) XYChart(org.knowm.xchart.XYChart) XYChartBuilder(org.knowm.xchart.XYChartBuilder) LimitOrder(org.knowm.xchange.dto.trade.LimitOrder)

Example 2 with BitstampExchange

use of org.knowm.xchange.bitstamp.BitstampExchange in project bitcoin-spring-boot-starter by theborakompanioni.

the class XChangeAutoConfigurationTest method propertiesAreParsedSuccessfully.

@Test
public void propertiesAreParsedSuccessfully() {
    this.contextRunner.withUserConfiguration(XChangeAutoConfiguration.class).withPropertyValues("org.tbk.xchange.enabled=true", // first exchange
    "org.tbk.xchange.specifications.firstTestExchange.exchangeClass=org.knowm.xchange.kraken.KrakenExchange", "org.tbk.xchange.specifications.firstTestExchange.exchangeName=Kraken", "org.tbk.xchange.specifications.firstTestExchange.exchangeDescription=Custom Kraken Exchange", "org.tbk.xchange.specifications.firstTestExchange.userName=any", "org.tbk.xchange.specifications.firstTestExchange.password=any", "org.tbk.xchange.specifications.firstTestExchange.secretKey=any", "org.tbk.xchange.specifications.firstTestExchange.apiKey=any", "org.tbk.xchange.specifications.firstTestExchange.shouldLoadRemoteMetaData=false", "org.tbk.xchange.specifications.firstTestExchange.resilience.retryEnabled=true", "org.tbk.xchange.specifications.firstTestExchange.resilience.rateLimiterEnabled=false", // second exchange
    "org.tbk.xchange.specifications.secondTestExchange.exchangeClass=org.knowm.xchange.bitstamp.BitstampExchange", "org.tbk.xchange.specifications.secondTestExchange.exchangeName=Bitstamp", "org.tbk.xchange.specifications.secondTestExchange.exchangeDescription=Custom Bitstamp Exchange", "org.tbk.xchange.specifications.secondTestExchange.httpConnTimeout=30000", "org.tbk.xchange.specifications.secondTestExchange.httpReadTimeout=100000", "org.tbk.xchange.specifications.secondTestExchange.shouldLoadRemoteMetaData=false", "org.tbk.xchange.specifications.secondTestExchange.resilience.retryEnabled=true", "org.tbk.xchange.specifications.secondTestExchange.resilience.rateLimiterEnabled=true").run(context -> {
        XChangeAutoConfigProperties bean = context.getBean(XChangeAutoConfigProperties.class);
        assertThat(bean, is(notNullValue()));
        assertThat(bean.isEnabled(), is(true));
        assertThat(bean.getSpecifications().values(), hasSize(2));
        bean.getSpecifications().forEach((beanName, spec) -> {
            assertThat("bean with specified name has been created", context.containsBean(beanName), is(true));
        });
        Map<String, Exchange> beans = context.getBeansOfType(Exchange.class);
        assertThat(beans.values(), hasSize(2));
        KrakenExchange firstTestExchange = context.getBean("firstTestExchange", KrakenExchange.class);
        assertThat(firstTestExchange, is(beans.get("firstTestExchange")));
        ExchangeSpecification firstTestExchangeSpec = firstTestExchange.getExchangeSpecification();
        assertThat(firstTestExchangeSpec.getSslUri(), is("https://api.kraken.com"));
        assertThat(firstTestExchangeSpec.getExchangeDescription(), is("Custom Kraken Exchange"));
        BitstampExchange secondTestExchange = context.getBean("secondTestExchange", BitstampExchange.class);
        assertThat(secondTestExchange, is(beans.get("secondTestExchange")));
        ExchangeSpecification secondTestExchangeSpec = secondTestExchange.getExchangeSpecification();
        assertThat(secondTestExchangeSpec.getSslUri(), is("https://www.bitstamp.net"));
        assertThat(secondTestExchangeSpec.getExchangeDescription(), is("Custom Bitstamp Exchange"));
    });
}
Also used : BitstampExchange(org.knowm.xchange.bitstamp.BitstampExchange) KrakenExchange(org.knowm.xchange.kraken.KrakenExchange) Exchange(org.knowm.xchange.Exchange) KrakenExchange(org.knowm.xchange.kraken.KrakenExchange) ExchangeSpecification(org.knowm.xchange.ExchangeSpecification) BitstampExchange(org.knowm.xchange.bitstamp.BitstampExchange) Test(org.junit.jupiter.api.Test)

Example 3 with BitstampExchange

use of org.knowm.xchange.bitstamp.BitstampExchange in project XChange by knowm.

the class BitstampDemoUtils method createExchange.

public static Exchange createExchange() {
    ExchangeSpecification exSpec = new BitstampExchange().getDefaultExchangeSpecification();
    exSpec.setUserName("34387");
    exSpec.setApiKey("a4SDmpl9s6xWJS5fkKRT6yn41vXuY0AM");
    exSpec.setSecretKey("sisJixU6Xd0d1yr6w02EHCb9UwYzTNuj");
    return ExchangeFactory.INSTANCE.createExchange(exSpec);
}
Also used : ExchangeSpecification(org.knowm.xchange.ExchangeSpecification) BitstampExchange(org.knowm.xchange.bitstamp.BitstampExchange)

Aggregations

BitstampExchange (org.knowm.xchange.bitstamp.BitstampExchange)3 Exchange (org.knowm.xchange.Exchange)2 ExchangeSpecification (org.knowm.xchange.ExchangeSpecification)2 BigDecimal (java.math.BigDecimal)1 ArrayList (java.util.ArrayList)1 Test (org.junit.jupiter.api.Test)1 OrderBook (org.knowm.xchange.dto.marketdata.OrderBook)1 LimitOrder (org.knowm.xchange.dto.trade.LimitOrder)1 KrakenExchange (org.knowm.xchange.kraken.KrakenExchange)1 MarketDataService (org.knowm.xchange.service.marketdata.MarketDataService)1 SwingWrapper (org.knowm.xchart.SwingWrapper)1 XYChart (org.knowm.xchart.XYChart)1 XYChartBuilder (org.knowm.xchart.XYChartBuilder)1 XYSeries (org.knowm.xchart.XYSeries)1