All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.xeiam.xchange.examples.btcchina.streaming.BTCChinaSocketIOClientBuilderDemo Maven / Gradle / Ivy

Go to download

Provides a set of examples that demonstrate how to use XChange in client applications

The newest version!
package com.xeiam.xchange.examples.btcchina.streaming;

import static com.xeiam.xchange.btcchina.service.streaming.BTCChinaSocketIOClientBuilder.EVENT_TICKER;

import java.net.URI;
import java.util.concurrent.TimeUnit;

import org.json.JSONObject;

import com.github.nkzawa.emitter.Emitter;
import com.github.nkzawa.socketio.client.Socket;
import com.xeiam.xchange.btcchina.service.streaming.BTCChinaSocketIOClientBuilder;
import com.xeiam.xchange.currency.CurrencyPair;

public class BTCChinaSocketIOClientBuilderDemo {

  public static void main(String[] args) throws InterruptedException {

    Socket socket = BTCChinaSocketIOClientBuilder.create().setUri(URI.create("https://websocket.btcchina.com"))
        .subscribeMarketData(CurrencyPair.BTC_CNY).build();

    socket.on(EVENT_TICKER, new Emitter.Listener() {

      @Override
      public void call(Object... args) {

        JSONObject jsonObject = (JSONObject) args[0];
        System.out.println(jsonObject);
      }
    });

    socket.connect();

    // Demonstrate for 30 seconds.
    TimeUnit.SECONDS.sleep(30);

    socket.disconnect();
  }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy