-
Notifications
You must be signed in to change notification settings - Fork 217
[bitfinex] Added some methods of authenticated api #209
Conversation
Nice, @Mikelle! 👍 I'm quite excited by this development; my own application really struggles due to poll limits on exchanges for private authenticated data, so adding streaming support would make a big difference. Two questions I think we need to answer:
|
Hmmm, crossover with #160. @bryantharris - your thought here? |
@badgerwithagun I think the right approach is a two layered approach the same as the REST XChange project that this streaming project is based on. Basically, layer 0 is exchange specific supporting 1:1 streaming events as to what is supported on the exchange ws API. You'd typically use the common API but could always drop to the lower level if there were specific event messages you wanted to follow. With respect to authenticated streaming, I give a resounding thumbs up that it should be supported. To me the primary advantage of authenticated streaming is real time updates to order status changes without polling. I get viewing tickers (non authenticated), but the real power seems to be in having the stream be authenticated and receiving private events IMHO. |
@badgerwithagun @bryantharris So what should I do to make you accept the pull request? Develop new generic API for authenticated streaming? |
@Mikelle: thanks for sticking with this. It would make sense to follow the same approach as @bryantharris has followed on #160 for trades: that is, if we are authenticated, then subscribe to the private trades stream and supply both However, when it comes to orders, we currently lack any generic API, so you will need to define a new one. I think the I don't have the power to approve change requests though; just helping out. There are others on here who are closer to the code who would have clearer ideas. |
So we are waiting for approve pool request of #160 for using the same approach for Bitfinex, right? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a really nice-looking PR. Great work.
If it could just be adjusted to fit into the existing patterns for authentication and L1 APIs, I reckon it's good for a merge.
Do you have time to follow this up?
@@ -57,4 +59,28 @@ public StreamingMarketDataService getStreamingMarketDataService() { | |||
@Override | |||
public void useCompressedMessages(boolean compressedMessages) { streamingService.useCompressedMessages(compressedMessages); } | |||
|
|||
public Completable connectToAuthenticated() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it possible to make this connection/authentication transparent, so it occurs automatically if authentication details are available, as we do for GDAX?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done on my uplift fork
|
||
public BitfinexStreamingExchange() { | ||
this.streamingService = new BitfinexStreamingService(API_URI); | ||
this.streamingAuthenticatedDataService = new BitfinexStreamingRawService(API_URI); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to have a second connection to BFX for the authenticated stream, or is it possible to just authenticate the existing connection?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
According to the BFX documentation, it very much looks like this is the case, so I'm going to try it.
} | ||
} | ||
|
||
public Observable<BitfinexWebSocketAuthOrder> getAuthenticatedOrders() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's an existing pattern for exposing L1 (exchange specific) methods. Example: BinanceStreamingMarketDataService.getRawTicker()
. Could we move these to the StreamingMarketDataService
? e.g. getRawAuthenticatedOrders()
?
return subjectPreTrade.share(); | ||
} | ||
|
||
public Observable<BitfinexWebSocketAuthTrade> getAuthenticatedTrades() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd like it if we could do as we do for GDAX, and merge the authenticated trades (as UserTrade
) with the public trades (as Trade
s) and return them in the getTrades()
stream. However, just implementing the L1 API is valuable on its own, so if you don't fancy doing this, that's fine. We can raise an issue for it and see if someone else picks it up (I might).
@@ -0,0 +1,303 @@ | |||
package info.bitrich.xchangestream.bitfinex; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've not reviewed this code - I suspect it might move around quite a lot based on my other comments.
Will review properly once the structure is right.
exchange.setCredentials("API-KEY", "API-SECRET"); | ||
|
||
exchange.connectToAuthenticated().blockingAwait(); | ||
exchange.getStreamingAuthenticatedDataService().getAuthenticatedTrades().subscribe( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SO, to clarify my earlier comments, this would be more "standard" like this:
ExchangeSpecification specification = StreamingExchangeFactory.INSTANCE.createExchange(BitfinexStreamingExchange.class.getName()).getDefaultExchangeSpecification();
specification.setApiKey("API-KEY");
specification.setSecretKey("API-SECRET");
BitfinexStreamingExchange exchange = (BitfinexStreamingExchange)StreamingExchangeFactory.INSTANCE.createExchange(specification);
exchange.getStreamingMarketDataService().getRawAuthenticatedTrades().subscribe(
...
);
So, use the existing authentication details provided by the exchange specification, authenticate by default if the authentication details are available, and use L1 "raw" methods on the StreamingMarketDataService
itself.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done on my uplift fork
Any plans on merging this? |
@davidjirocev If it's tested and reviewed, then most likely. |
I'm running this branch a few months :) |
@Mikelle any chance you could work on the comments @badgerwithagun made? |
OK, the uplift of this PR to resolve conflicts, answer the review comments and bring it in line with other exchanges is now underway and can be tracked on https://github.com/badgerwithagun/xchange-stream/tree/bitfinex-authenticated. |
@Mikelle, is there a reason why you used a separate |
OK, I have created my modified version as #273. This covers all my review issues. I guess this one can be closed if everyone's happy with the modifications. |
Closing this in the absence of any complaints. Can re-open if necessary. Please head over to #273. |
Added web socket support for getting orders, pre trades and trades, balaces updates