Re: Django channel 2 - Provide seperate feeds to each users every 5 second

2018-05-20 Thread Ryan Nowakowski
On Fri, May 18, 2018 at 10:28:00PM -0700, sahadev sahu wrote:
> Hello,
> 
> I am implementing a websocket application for live data feed updates to 
> each client according to their watchlist in every 5 second. Here I am 
> explaining my requirement:
> 
>1. Once user register with my application, he can view list of currency 
>pairs e.g (ETH, BTC etc)
>2. From that list, user can add one or more pairs into his watchlist.
>3. And based on user's watchlist, user should get only that data through 
>"Channel" which is in his watchlist in every 5 second
>
> Possible approach as per me:
> 
>1. Should i create multiple channel for each user ? or
>2. Is there possibility to create multiple events in single channel to 
>handle each user separately to send different feeds to each user
> 
> Note: Every feed will fetch its results from another exchange website, then 
> the end user will get that feed into their watchlist. How can i run my 
> script continuously for each user seprately 
> 
> 
> Please kindly suggest, what is the right approach to implement this kind of 
> situation.

Here's one way to do it.  Each channel should be associated with
a group[1]. There should be one group per User[2] associated via a
database model[3](called UserWebsocketGroup).  Then you can poll the
exchange website using a background task[4] that goes something like this:

def poll_exchange_site():
user_websocket_groups = UserWebsocketGroup.objects.all()
for user_websocket_group in user_websocket_groups:
currency_pairs = user_websocket_group.user.currency_pairs.all()
for pair in currency_pairs:
pair_values = get_pair_values_from_exchange(pair)
user_websocket_group.group.send({pair: pair_values})
time.sleep(5)
poll_exchange_website()


[1] http://channels.readthedocs.io/en/latest/topics/channel_layers.html#groups
[2] https://docs.djangoproject.com/en/2.0/ref/contrib/auth/#user-model
[3] https://docs.djangoproject.com/en/2.0/topics/db/models/
[4] http://channels.readthedocs.io/en/latest/topics/worker.html#

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/20180520194250.GC23641%40fattuba.com.
For more options, visit https://groups.google.com/d/optout.


Django channel 2 - Provide seperate feeds to each users every 5 second

2018-05-19 Thread sahadev sahu
Hello,

I am implementing a websocket application for live data feed updates to 
each client according to their watchlist in every 5 second. Here I am 
explaining my requirement:

   1. Once user register with my application, he can view list of currency 
   pairs e.g (ETH, BTC etc)
   2. From that list, user can add one or more pairs into his watchlist.
   3. And based on user's watchlist, user should get only that data through 
   "Channel" which is in his watchlist in every 5 second
   
Possible approach as per me:

   1. Should i create multiple channel for each user ? or
   2. Is there possibility to create multiple events in single channel to 
   handle each user separately to send different feeds to each user

Note: Every feed will fetch its results from another exchange website, then 
the end user will get that feed into their watchlist. How can i run my 
script continuously for each user seprately 


Please kindly suggest, what is the right approach to implement this kind of 
situation.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/d9386e9c-35eb-473f-a456-8187eb79142f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.