0

I have django application with channels. It opens websocket connection to Crypto-market data provider. I received tick data, I insert those ticks in the database.

I also want to send that tick data to other application (say frontend). But I am not able to it efficiently.

Currently only single frontend application is present. So when it connects to django channels, I add that connection to group named('root') and send all the market-tick data to that group.

So the problem here is, If I decide to connect second frontend application, I get all the data that first user was requesting (as both clients are present in group 'root' on django).

I tried a method were when a users requests data for particular crypto, then I added him to that crypt-named group (if user want bitcoin data only, I added him to bitcoin group) But I get lots crpto-data on django server and very big number of ticks per second. It feels kind of slow to send each tick data to that particular crypto group channel ( on tick check symbol and forward that tick to that symbol-named django channel).

Any suggestion on how to approach to this problem.?

Rushikesh Koli
  • 23
  • 1
  • 1
  • 6

1 Answers1

0

You can send data to channels groups from anywhere in your Django code

from channels.layers import get_channel_layer
from asgiref.sync import async_to_sync
async_to_sync(channel_layer.group_send)("root", {'messages' : message, 'type' : 'chat_message'})
mohamed naser
  • 359
  • 3
  • 9