Idirect-Tech / Breeze-Python-SDK

The official Python client library for the ICICI Securities trading APIs
MIT License
53 stars 28 forks source link

On-Tick Callback Not Executing in Python Virtual Environment #50

Open sumitServicenet opened 7 months ago

sumitServicenet commented 7 months ago

class Command(BaseCommand): def handle(self, *args: Any, **options: Any):

  api_key = ""
  api_secret = ""
  session_token = ""

  print("Connecting to Breeze")
  breeze = BreezeConnect(api_key="")
  print("WebSocket connected successfully")

  breeze.generate_session(api_secret="", session_token="")

  breeze.ws_connect()
  print("WebSocket connected successfully")
  def on_ticks(ticks):
      print("Ticks: {}".format(ticks))

  breeze.on_ticks = on_ticks

  breeze.subscribe_feeds(exchange_code="NFO", stock_code="ADAENT", product_type="options",
                  expiry_date="28-Dec-2023", strike_price="3000", right="Call",
                  get_exchange_quotes=True, get_market_depth=False)

  print("Subscribed to ADAENT options")

  breeze.ws_disconnect()
  print("Disconnected from WebSocket")

I have a Django management command located in the management/commands folder. When I run this file using python3 manage.py file_name in my virtual environment, the on_ticks callback function is not getting called, and no data is printed. However, the code works fine in my local environment. The virtual environment is active during the file execution, and all required packages are installed. What could be causing the on_ticks function not to execute in the virtual environment?

mavinkai commented 6 months ago

You need to do something on the main thread. If the main thread exits, on some platforms/environments the entire program exits. It can be as simple as adding inp = input('Press any key to exit') to the last line of your main()

Idirect-Tech commented 6 months ago

Dear Sir,

Requested to mail us at breezeapi@icicisecurities.com.