Job "opquote (trigger: or[cron[day_of_week='mon-fri', hour='16', minute='17']], next run at: 2020-05-07 16:17:00 CDT)" raised an exception
Traceback (most recent call last):
File "c:\users\e\appdata\local\programs\python\python37\lib\site-packages\apscheduler\executors\base_py3.py", line 29, in run_coroutine_job
retval = await job.func(*job.args, **job.kwargs)
File "", line 4, in opquote
ib.qualifyContracts(gld)
File "c:\users\e\appdata\local\programs\python\python37\lib\site-packages\ib_insync\ib.py", line 537, in qualifyContracts
return self._run(self.qualifyContractsAsync(*contracts))
File "c:\users\e\appdata\local\programs\python\python37\lib\site-packages\ib_insync\ib.py", line 292, in _run
return util.run(*awaitables, timeout=self.RequestTimeout)
File "c:\users\e\appdata\local\programs\python\python37\lib\site-packages\ib_insync\util.py", line 311, in run
result = loop.run_until_complete(task)
File "c:\users\e\appdata\local\programs\python\python37\lib\asyncio\base_events.py", line 579, in run_until_complete
return future.result()
File "c:\users\e\appdata\local\programs\python\python37\lib\asyncio\futures.py", line 178, in result
raise self._exception
File "c:\users\e\appdata\local\programs\python\python37\lib\asyncio\tasks.py", line 249, in __step
result = coro.send(None)
File "c:\users\e\appdata\local\programs\python\python37\lib\site-packages\ib_insync\ib.py", line 1630, in qualifyContractsAsync
*(self.reqContractDetailsAsync(c) for c in contracts))
File "c:\users\e\appdata\local\programs\python\python37\lib\site-packages\ib_insync\ib.py", line 1630, in
*(self.reqContractDetailsAsync(c) for c in contracts))
File "c:\users\e\appdata\local\programs\python\python37\lib\site-packages\ib_insync\ib.py", line 1744, in reqContractDetailsAsync
reqId = self.client.getReqId()
File "c:\users\e\appdata\local\programs\python\python37\lib\site-packages\ib_insync\client.py", line 157, in getReqId
raise ConnectionError('Not connected')
ConnectionError: Not connected
I think you have understood misfire_grace_time. It only makes sure that the task is started within the grace time. It has no effect on the completion of the task – there is no way to set a deadline for the completion of a job in APScheduler.
Without seeing your code, it's next to impossible to know why it
raises ConnectionError('Not connected'). It's your code, so maybe
you should figure that out first? I doubt the scheduler has
anything to do with that. If you want further help, try
constructing a minimum viable representation of the problem that
others could run and then identify the problem.
--
You received this message because you are subscribed to the Google Groups "APScheduler" group.
To unsubscribe from this group and stop receiving emails from it, send an email to apscheduler...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/apscheduler/163011a1-6f58-4b0d-bd7b-1a1fe207e06e%40googlegroups.com.
fpath = 'Z://dedup/e/Python/csv/'stamp = datetime.today().strftime('%Y%m%d')exch = 'SMART'sfx = stamp + 'TESTgldoptions' + exch + '.csv'
gld = Stock('GLD', exch, currency='USD')ib.qualifyContracts(gld)
ib.reqMarketDataType(4)
[ticker] = ib.reqTickers(gld)gldValue = ticker.marketPrice()
chains = ib.reqSecDefOptParams(gld.symbol, '', gld.secType, gld.conId)chain = next(c for c in chains if c.tradingClass == 'GLD' and c.exchange == 'SMART')strikes = [strike for strike in chain.strikes if strike % 1 == 0 and gldValue - 1 < strike < gldValue + 1]expirations = sorted(exp for exp in chain.expirations)[:10]rights = ['P', 'C']
contracts = [Option('GLD', expiration, strike, right, 'SMART', tradingClass='GLD') for right in rights for expiration in expirations for strike in strikes]
contracts = ib.qualifyContracts(*contracts)
tickers = ib.reqTickers(*contracts)util.df(tickers)
df_gld = util.df(tickers)
fs = fpath + sfx
with open(fs, 'a')as f: df_gld.to_csv(f, mode='a', header=True)from ib_insync import *util.patchAsyncio()from datetime import datetime
import asynciofrom apscheduler.schedulers.asyncio import AsyncIOSchedulerfrom apscheduler.triggers.combining import OrTrigger
from apscheduler.triggers.cron import CronTriggerimport pandas as pdutil.startLoop()
ib = IB()
ib.connect('127.0.0.1', 7497, clientId=1)
async def opquote(): exch = 'SMART' gld = Stock('GLD', exch, currency='USD') ib.qualifyContracts(gld)
ib.reqMarketDataType(2)
now = datetime.now()
[ticker] = ib.reqTickers(gld) print(now, '\n', ticker)
# placeholder task representing regex to format csv file:async def testrun2(): ib.sleep(20) # placeholder representing code to make sure the csv file is present now = datetime.now() print ('This is a second task at', now)
sched = AsyncIOScheduler(timezone="America/Chicago")trigger = OrTrigger([ CronTrigger(day_of_week='mon-fri', hour='8', minute='31, 37, 43, 49, 55'), CronTrigger(day_of_week='mon-fri', hour='9-14', minute='1, 7, 13, 19, 25, 31, 37, 43, 49, 55'), CronTrigger(day_of_week='mon-fri', hour='14', minute='15'),])sched.add_job(opquote, trigger)sched.add_job(testrun2, trigger)sched.start()I'm pretty sure you should not try to use AsyncIOScheduler here.
You don't have a single "await" in your code which leads me to
believe you are not actually using any asynchronous code. Instead,
use BlockingScheduler or BackgroundScheduler as appropriate, and
without "async" in the function definitions.
--
You received this message because you are subscribed to the Google Groups "APScheduler" group.
To unsubscribe from this group and stop receiving emails from it, send an email to apscheduler...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/apscheduler/a8e916c0-bb5c-4039-9851-e3577c570384%40googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to apsch...@googlegroups.com.
When writing async code, you really need to be mindful about not blocking the event loop thread for long periods of time. This line in particular looked highly dubious:
ib.sleep(20)
To unsubscribe from this group and stop receiving emails from it, send an email to apscheduler...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/apscheduler/0949f9d2-4d3d-4e7b-81c7-b711cba43f59%40googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/apscheduler/0949f9d2-4d3d-4e7b-81c7-b711cba43f59%40googlegroups.com.