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