Package com.xeiam.xchange.examples.btcchina.streaming

Source Code of com.xeiam.xchange.examples.btcchina.streaming.BTCChinaSocketIOClientBuilderDemo

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

}
TOP

Related Classes of com.xeiam.xchange.examples.btcchina.streaming.BTCChinaSocketIOClientBuilderDemo

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.