robcarver17 / pysystemtrade

Systematic Trading in python
GNU General Public License v3.0
2.57k stars 816 forks source link

Missing Cache Element, Event Loop Already Running #1107

Closed emretezel closed 1 year ago

emretezel commented 1 year ago

Hi Everyone,

I believe this issue has been fixed in develop branch but not in master. Could the fix be pleased merged into master. We should all treat master as the production branch in my opinion and keep it stable.

The below messages pop out when running update_sampled_contracts in standard out

Traceback (most recent call last):
  File "/home/pysystemtrade/opt/pysystemtrade/syscore/cache.py", line 30, in get
    value_from_store = self._get_from_store(key)
  File "/home/pysystemtrade/opt/pysystemtrade/syscore/cache.py", line 50, in _get_from_store
    raise missingData("Missing cache element %s" % key)
syscore.exceptions.missingData: Missing cache element _get_ib_futures_contract_from_broker/(WHEAT_mini/20231200,)/{'trade_list_for_multiple_legs': None, 'allow_expired': False}

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/pysystemtrade/anaconda3/envs/pysystemtrade-prod/lib/python3.8/site-packages/eventkit/event.py", line 189, in emit
    result = func(obj, *args)
  File "/home/pysystemtrade/opt/pysystemtrade/sysbrokers/IB/client/ib_client.py", line 121, in error_handler
    log_to_use = self._get_log_for_contract(contract)
  File "/home/pysystemtrade/opt/pysystemtrade/sysbrokers/IB/client/ib_client.py", line 138, in _get_log_for_contract
    instrument_code = self.get_instrument_code_from_broker_contract_object(
  File "/home/pysystemtrade/opt/pysystemtrade/sysbrokers/IB/client/ib_client.py", line 159, in get_instrument_code_from_broker_contract_object
    broker_identity = self.broker_identity_for_contract(broker_contract_object)
  File "/home/pysystemtrade/opt/pysystemtrade/sysbrokers/IB/client/ib_client.py", line 198, in broker_identity_for_contract
    contract_details = self.get_contract_details(
  File "/home/pysystemtrade/opt/pysystemtrade/sysbrokers/IB/client/ib_client.py", line 218, in get_contract_details
    contract_details = self._get_contract_details(
  File "/home/pysystemtrade/opt/pysystemtrade/sysbrokers/IB/client/ib_client.py", line 239, in _get_contract_details
    return self.ib.reqContractDetails(ib_contract_pattern)
  File "/home/pysystemtrade/anaconda3/envs/pysystemtrade-prod/lib/python3.8/site-packages/ib_insync/ib.py", line 927, in reqContractDetails
    return self._run(self.reqContractDetailsAsync(contract))
  File "/home/pysystemtrade/anaconda3/envs/pysystemtrade-prod/lib/python3.8/site-packages/ib_insync/ib.py", line 308, in _run
    return util.run(*awaitables, timeout=self.RequestTimeout)
  File "/home/pysystemtrade/anaconda3/envs/pysystemtrade-prod/lib/python3.8/site-packages/ib_insync/util.py", line 332, in run
    result = loop.run_until_complete(task)
  File "/home/pysystemtrade/anaconda3/envs/pysystemtrade-prod/lib/python3.8/asyncio/base_events.py", line 592, in run_until_complete
    self._check_running()
  File "/home/pysystemtrade/anaconda3/envs/pysystemtrade-prod/lib/python3.8/asyncio/base_events.py", line 552, in _check_running
    raise RuntimeError('This event loop is already running')
tgibson11 commented 1 year ago

I believe this issue has been fixed in develop branch but not in master.

Correct. So why are you opening another issue for it?

If this is urgent for you, it should be safe to download the develop branch. I've been using it for several days with no issues.

We should all treat master as the production branch in my opinion and keep it stable.

Agreed, but also see A note on support

emretezel commented 1 year ago

Thank you, I will wait until Rob merges latest develop changes into master, just being a little paranoid. Closing the issue.

tgibson11 commented 1 year ago

Thanks for closing. Sorry if I was a bit harsh there.

Also, for anyone else seeing my comment about develop being good at the moment...there is one change in there that might cause problems for some people.

PR #1095 will cause config files to be read from the PYSYS_CODE directory if you have the environment variable defined. If your config files there are different from the config files installed in your python environment, you definitely do not want that.

I've recommended that Rob revert that pull request. I did not realize at the time that config files were being read from the Python environment (and that some people are even editing them directly in the Python environment).