如何使用Jawampa(Java WAMP实现)来订阅事件 [英] How to use Jawampa (Java WAMP implementation) to subcribe to an event

查看:147
本文介绍了如何使用Jawampa(Java WAMP实现)来订阅事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用poloniex API。 https://poloniex.com/support/api/

i want to use the poloniex API. https://poloniex.com/support/api/

到目前为止,我制作了Jawampa( https://github.com/Matthias247/jawampa )使用IntelliJ运行。

So far i made Jawampa ( https://github.com/Matthias247/jawampa ) running with IntelliJ.

我的第一个问题是,如何成功登录? (Jawampa的文件没有帮助)

My first Question is, how to login successfuly? (The Docu of Jawampa doesnt help)

我有一个API密钥和一个秘密。我必须在Jawampa的构建器中使用哪些函数:

I got a API Key and a Secret. Which functions i have to use in the builder of Jawampa:

withRealm
withRoles
withConnectorProvider
withConnectionConfiguration
withSerializations
withStrictUriValidation
withAuthId
withAuthMethod
withObjectMapper

withRealm withRoles withConnectorProvider withConnectionConfiguration withSerializations withStrictUriValidation withAuthId withAuthMethod withObjectMapper

我到目前为止这段代码

     try {
        WampClientBuilder builder = new WampClientBuilder();
        builder.withConnectorProvider(connectorProvider)
                .withUri("wss://api.poloniex.com")
                .withAuthId("APIKEY")
                .withRealm("realm2")
                .withInfiniteReconnects()
                .withReconnectInterval(1, TimeUnit.SECONDS);
        client1 = builder.build();
    } catch (Exception e) {
        e.printStackTrace();
        return;
    }

wss://api.poloniex.com是正确还是我应该使用wss ://api.poloniex.com/returnTicker为该客户端?

Is wss://api.poloniex.com correct or should i use wss://api.poloniex.com/returnTicker for that client?

我是否必须为每个URI设置一个新的客户端?

Do I have to make always a new client for every URI?

提前非常感谢。

推荐答案


  1. 我的第一个问题是,如何成功登录?

您无需通过WAMP协议进行身份验证即可访问Poloniex Push API。 Push API方法是公共的,因此您不必提供API密钥和密钥。只需连接到wss://api.poloniex.com并订阅所需的订阅源(Ticker,订单簿和交易,Trollbox)。

You don't have to authenticate to access Poloniex Push API via WAMP protocol. Push API methods are public, so you don't have to supply the API key and secret. Just connect to wss://api.poloniex.com and subscribe to a desired feed (Ticker, Order Book and Trades, Trollbox).

顺便说一下,您只需要使用Trading API方法提供API密钥。秘密用于签署POST数据。

Btw, you need to supply the API Key only with Trading API methods. And the Secret is used to sign a POST data.


  1. 我必须在Jawampa的建造者中使用哪些功能:

这是你连接Push API的方式:

This is how you connect to the Push API:

    WampClient client;
    try {
        WampClientBuilder builder = new WampClientBuilder();
        IWampConnectorProvider connectorProvider = new NettyWampClientConnectorProvider();
        builder.withConnectorProvider(connectorProvider)
                .withUri("wss://api.poloniex.com")
                .withRealm("realm1")
                .withInfiniteReconnects()
                .withReconnectInterval(5, TimeUnit.SECONDS);
        client = builder.build();

    } catch (Exception e) {
        return;
    }

连接客户端后,您订阅了这样的Feed:

Once your client is connected, you subscribe to a feed like this:

    client.statusChanged().subscribe(new Action1<WampClient.State>() {
        @Override
        public void call(WampClient.State t1) {
            if (t1 instanceof WampClient.ConnectedState) {
                subscription = client.makeSubscription("trollbox")
                        .subscribe((s) -> { System.out.println(s.arguments()); }
            }
        }
    });
    client.open();




  1. wss://api.poloniex.com是否正确或我应该使用$ b该客户的$ b wss://api.poloniex.com/returnTicker?

wss://api.poloniex.com is另外,returnTicker属于Public API,可通过HTTP GET请求访问。

wss://api.poloniex.com is correct. Besides, returnTicker belongs to the Public API and is accessed via HTTP GET requests.


  1. 我是否必须制作每个URI总是一个新的客户端吗?

关于Push API,将客户端连接到wss://api.poloniex.com后,您可以使用此客户端进行订阅多个Feed。例如:

In respect to the Push API, once you connected a client to wss://api.poloniex.com, you can use this client to make subscriptions to multiple feeds. For example:

client.statusChanged().subscribe(new Action1<WampClient.State>() {
        @Override
        public void call(WampClient.State t1) {
            if (t1 instanceof WampClient.ConnectedState) {
                client.makeSubscription("trollbox")
                        .subscribe((s) -> { System.out.println(s.arguments()); });
                client.makeSubscription("ticker")
                        .subscribe((s) -> { System.out.println(s.arguments()); });
            }
        }
    });

然而,根据Jawampa Docs:

However, according to Jawampa Docs:


关闭WampClient后,无法再次重新打开。如果需要,应该创建一个新的WampClient实例。

After a WampClient was closed it can not be reopened again. Instead of this a new instance of the WampClient should be created if necessary.

这篇关于如何使用Jawampa(Java WAMP实现)来订阅事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆