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

real-time all symbol price monitoring #13

Closed
pavlexander opened this issue Jan 2, 2018 · 5 comments
Closed

real-time all symbol price monitoring #13

pavlexander opened this issue Jan 2, 2018 · 5 comments

Comments

@pavlexander
Copy link

Is there an API to monitor prices for all symbols real-time?

For example, when you open up the main page (href: /) then there is a new WebSocket connection established:

wss://stream2.binance.com:9443/ws/!miniTicker@arr@3000ms

which seems to be monitoring price changes for all currencies simultaneously. Output format for each currency is:

E:1514912813087
c:"0.00239528"
e:"24hrMiniTicker"
h:"0.00274990"
l:"0.00214001"
o:"0.00252900"
q:"73675.51226164"
s:"XRPETH"
v:"30218342.00000000"

Unfortunately, I can not find the websocket endpoint in the official list of endpoints and so I could not find an API in this binance project which would provide a similar kind of results.

So my question is - is there support for this functionality planned, if not, then what would be the best approach to get this data real-time?
I can of course spam GetPricesAsync API but then that would certainly not be a correct way of doing it..

@sonvister sonvister self-assigned this Jan 2, 2018
@sonvister
Copy link
Owner

sonvister commented Jan 2, 2018

@pavlexander, my plan is to support all official functionality. There is official support for All Market Tickers Stream. I just recently incorporated this functionality into ISymbolStatisticsWebSocketClient and ISymbolStatisticsCache as of 0.2.0-alpha.9. The Binance24HourStatistics sample application provides an example use of this cache for one symbol. To get all symbols do not specify a symbol (the websocket client works similarly). I do plan to update my documentation as well. Let me know if this works for you.

@pavlexander
Copy link
Author

pavlexander commented Jan 2, 2018

@sonvister it is not working correctly for me, unfortunately.

               var cache = services.GetService<ISymbolStatisticsCache>();

                using (var controller = new RetryTaskController())
                {
                    var api = services.GetService<IBinanceApi>();

                    // Query and display the 24-hour statistics.
                    Display(await api.Get24HourStatisticsAsync());

                    // Monitor 24-hour statistics and display updates in real-time.
                    controller.Begin(
                        tkn => cache.SubscribeAsync(evt => Display(evt.Statistics.AsEnumerable()), tkn),
                        err => Console.WriteLine(err.Message));

                    Console.ReadKey(true);
                }

The non-web-socket version prints out the data correctly, however, the real-time version of it is either showing results several times and stops, or not showing any results at all no matter how many times I restart the application.. For the sake of testing I have created several output methods:

        private static void Display(IEnumerable<SymbolStatistics> statistics)
        {
            Console.WriteLine("1 " + statistics.Count());
        }

        private static void Display(params SymbolStatistics[] statistics)
        {
            Console.WriteLine("2 " + statistics.Count());
        }

I was trying to use array results (evt.Statistics) as it is, and as IEnumerable (hence the evt.Statistics.AsEnumerable() in the code), with no success.

@sonvister
Copy link
Owner

sonvister commented Jan 2, 2018

@pavlexander, for debugging the sample application you can refer to the Binance24HourStatistics.log.txt file. This shows that occasionally the trade count is invalid (not lastTradeId - firstTradeId + 1). I have seen this before in the Binance API response for 24-hour stats, but it seemed to be fixed. I posted this new info on the API Telegram, but in the meantime you can comment-out the check in SymbolStatistics.cs or calculate a different trade count in SymbolStatisticsWebSocketClient.cs taking into account possible NullId trade IDs.

@pavlexander
Copy link
Author

Thank you. I didn't know about the log.. Yes, this seems to be the same issue as I have in my log as well!

@sonvister
Copy link
Owner

For now, I have commented-out the check (allowing for the invalid trade counts). I also modified ISymbolStatisticsCache to maintain a dictionary of all symbols rather than just the latest update array. With this change the event from the cache will contain all symbols and the count will always be the total number of symbols. If you wish to get only the updated symbol stats then you will want to use the ISymbolSatisticsWebSocketClient directly (the API and behavior is otherwise the same). These changes will be in 0.2.0-alpha.10.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants