Package com.github.nkzawa.socketio.client

Examples of com.github.nkzawa.socketio.client.Socket


    if ((!this.orderFeed.isEmpty() || this.subscribeAccountInfo) && (this.accessKey == null || this.secretKey == null)) {
      throw new IllegalArgumentException("Access key and secret key are required to subscribe order feed and account info.");
    }

    final Socket socket;
    try {
      socket = IO.socket(uri, opt);
    } catch (URISyntaxException e) {
      throw new IllegalArgumentException(e);
    }

    socket.on(Socket.EVENT_CONNECT, new Emitter.Listener() {

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

        subscribeMarketData();
        subscribeGrouporder();
        subscribePrivateData();
      }

      private void subscribeMarketData() {

        subscribe("marketdata", marketData);
      }

      private void subscribeGrouporder() {

        subscribe("grouporder", grouporder);
      }

      private void subscribe(String name, Iterable<CurrencyPair> currencyPairs) {

        for (CurrencyPair currencyPair : currencyPairs) {
          String market = toMarket(currencyPair);
          String subscribeData = String.format("%s_%s", name, market);
          log.debug("subscribing {}", subscribeData);
          socket.emit("subscribe", subscribeData);
        }
      }

      private void subscribePrivateData() {

        final List<String> params = buildPrivateDataParams();

        if (!params.isEmpty()) {
          BTCChinaPayload payload = getPayload(params.toArray(new String[0]));

          final List<String> arg = new ArrayList<String>(2);
          arg.add(toPostData(payload));
          arg.add(getSign(payload));

          // Use 'private' method to subscribe the order feed
          socket.emit("private", arg);
        } else {
          log.debug("No private data specified to subscribe.");
        }
      }
View Full Code Here


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();
  }
View Full Code Here

TOP

Related Classes of com.github.nkzawa.socketio.client.Socket

Copyright © 2018 www.massapicom. 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.