Advertisement
anjalmorang

Untitled

Jul 18th, 2024
22
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1. import json
  2. from quotexpy.ws.channels.base import Base
  3.  
  4. class GetCandles(Base):
  5. """Class for Quotex candles websocket channel."""
  6.  
  7. name = "candles"
  8.  
  9. def __init__(self):
  10. super().__init__()
  11. self.candles_data = None # Store received candle data
  12.  
  13. def __call__(self, asset, index, offset, period, time):
  14. """Method to send message to candles websocket channel."""
  15. payload = {"asset": asset, "index": index, "offset": offset, "period": period, "time": time}
  16. data = f'42["history/load",{json.dumps(payload)}]'
  17. self.send_websocket_request(data)
  18.  
  19. def on_receive(self, message):
  20. """Method to handle the received websocket message."""
  21. try:
  22. data = json.loads(message)
  23. if isinstance(data, list) and len(data) > 1 and data[0] == "history/load":
  24. self.candles_data = data[1] # Assuming data[1] contains the candle data
  25. except json.JSONDecodeError:
  26. print("Failed to decode the message")
  27.  
  28. def get_candles_data(self):
  29. """Method to get the stored candle data."""
  30. return self.candles_data
  31.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement