Bitcoin Forum
May 04, 2024, 11:19:04 AM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
  Home Help Search Login Register More  
  Show Posts
Pages: [1]
1  Economy / Exchanges / Bitfinex api v2 not returning candles on: May 03, 2017, 11:19:57 AM
I am using bitfinex websockets v2 api in a Java application, to get the candles from a market. But I don't get any message back from the socket(not even an error). I wonder what I am doing wrong. Also I noticed that I can't subscribe to the ticker.

v1 of the api works fine for me I can subscribe to messages with no problem. But in v2, I only get the ping pong to work but I can't subscribe to messages such as ticker or candles.

Let me show you the code that I have, maybe I am forgetting something:

Here I create a client and open a websocket to the new api address:
Code:
@SpringBootApplication(scanBasePackages = "application")
public class Application {

    private static Object waitLock = new Object();

    public static void main(String[] args) {
        ApplicationContext applicationContext = SpringApplication.run(Application.class, args);

        WebSocketClient webSocketClient = new WebSocketClient();
        webSocketClient.startWebSocketClient("wss://api.bitfinex.com/ws/2");
    }
}
This is the client that manages the connection to the socket
Code:
   public class WebSocketClient {

        final static CountDownLatch messageLatch = new CountDownLatch(1);

        public void startWebSocketClient(String address) {
            try {
                WebSocketContainer container = ContainerProvider.getWebSocketContainer();
                System.out.println("Connecting to " + address);
                container.connectToServer(WebSocketEndpoint.class, URI.create(address));
                messageLatch.await();
            } catch (DeploymentException | InterruptedException | IOException ex) {
                Logger.getLogger(WebSocketClient.class.getName()).log(Level.SEVERE, null, ex);
            }
        }

    }
This is the endpoint that I create to handle the responses
Code:
@ClientEndpoint
public class WebSocketEndpoint {

    private Session session;

    @OnOpen
    public void onOpen(Session session) {
        this.session = session;
        System.out.println("Connected to endpoint: " + session.getBasicRemote());
        RemoteEndpoint.Async asyncRemote = session.getAsyncRemote();
        asyncRemote.sendText("{event:\"subscribe\",channel:\"candles\",key:\"trade:1m:tBTCUSD\"}");
    }

    @OnMessage
    public void processMessage(String message) {
        System.out.println("Received message: " + message);
    }

    @OnError
    public void processError(Throwable t) {
        t.printStackTrace();
    }

}
Pages: [1]
Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!