Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Getting Account Subscribe Stream ? #80

Open
inmyth opened this issue Jun 10, 2017 · 1 comment
Open

Getting Account Subscribe Stream ? #80

inmyth opened this issue Jun 10, 2017 · 1 comment

Comments

@inmyth
Copy link

inmyth commented Jun 10, 2017

Is there a way (using this library or any other) to get a stream from subscribe command similar to Ripple's websocket tool. ? With any websocket client I can only get the initial response but not the stream itself.

@inmyth
Copy link
Author

inmyth commented Jun 12, 2017

I think I'm getting a clue here. This library is using TooTallNate websocket. It looks with this client subscribe to account never returns anything. However subscribe to anything else works. This is the snippet. To test it, run the program and send some order with your account.

import java.net.URI;
import java.net.URISyntaxException;

import org.java_websocket.client.WebSocketClient;
import org.java_websocket.drafts.Draft;
import org.java_websocket.drafts.Draft_6455;
import org.java_websocket.handshake.ServerHandshake;

public class Main extends WebSocketClient {
	static String SERVERLEDGER = "{\r\n  \"command\": \"subscribe\",\r\n  \"streams\": [\r\n    \"server\",\r\n    \"ledger\"\r\n  ]\r\n}";
	static String ACCOUNT = "{\r\n  \"command\": \"subscribe\",\r\n  \"accounts\": [\"raNDu1gNyZ5hipBTKxm5zx7NovA1rNnNRf\"]\r\n}";
	static String ORDERBOOK= "{\r\n    \"command\": \"subscribe\",\r\n    \"books\": [\r\n        {\r\n            \"taker_pays\": {\r\n                \"currency\": \"XRP\"\r\n            },\r\n            \"taker_gets\": {\r\n                \"currency\": \"JPY\",\r\n                \"issuer\": \"rB3gZey7VWHYRqJHLoHDEJXJ2pEPNieKiS\"\r\n            },\r\n            \"snapshot\": true\r\n        }\r\n    ]\r\n}";
	
	
	static Main main ;
	public Main(URI serverUri, Draft protocolDraft) {
		super(serverUri, protocolDraft);
		// TODO Auto-generated constructor stub
	}

	@Override
	public void onClose(int arg0, String arg1, boolean arg2) {
		System.out.println("disconnected " + arg1);
	}

	@Override
	public void onError(Exception e) {
		System.out.println(e.getMessage());	
	}

	@Override
	public void onMessage(String raw) {
		System.out.println(raw);
	}

	@Override
	public void onOpen(ServerHandshake arg0) {
		System.out.println("connected");
		main.send(ACCOUNT);	
	}
	
	public static void main(String[] args) throws URISyntaxException {
		main = new Main(new URI("wss://s1.ripple.com"), new Draft_6455());
		main.connect();
	}

}

Later I'm testing this with node and ws websocket client and it can subscribe to account just fine.

const WebSocket = require('ws')

const ws = new WebSocket('wss://s1.ripple.com' )

const subscribeTx = '{\r\n  \"command\": \"subscribe\",\r\n  \"accounts\": [\"raNDu1gNyZ5hipBTKxm5zx7NovA1rNnNRf\"]\r\n}'

ws.on('open', function open() {
  console.log('connected')
  ws.send(subscribeTx)
})

ws.on('message', function incoming(data) {
  console.log(data)
})

@inmyth inmyth changed the title Getting Subscribe Stream ? Getting Account Subscribe Stream ? Jun 12, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant