Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import json
- from quotexpy.ws.channels.base import Base
- class GetCandles(Base):
- """Class for Quotex candles websocket channel."""
- name = "candles"
- def __init__(self):
- super().__init__()
- self.candles_data = None # Store received candle data
- def __call__(self, asset, index, offset, period, time):
- """Method to send message to candles websocket channel."""
- payload = {"asset": asset, "index": index, "offset": offset, "period": period, "time": time}
- data = f'42["history/load",{json.dumps(payload)}]'
- self.send_websocket_request(data)
- def on_receive(self, message):
- """Method to handle the received websocket message."""
- try:
- data = json.loads(message)
- if isinstance(data, list) and len(data) > 1 and data[0] == "history/load":
- self.candles_data = data[1] # Assuming data[1] contains the candle data
- except json.JSONDecodeError:
- print("Failed to decode the message")
- def get_candles_data(self):
- """Method to get the stored candle data."""
- return self.candles_data
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement