Skip to content
This repository has been archived by the owner on Mar 14, 2024. It is now read-only.

ValueError: time data '20221217:CLOSED' does not match format '%Y%m%d:%H%M' #534

Closed
jlixfeld opened this issue Dec 17, 2022 · 0 comments
Closed

Comments

@jlixfeld
Copy link

Whoopsie :)

def tradingSessions(self) -> List[TradingSession]:
return self._parseSessions(self.tradingHours)
def liquidSessions(self) -> List[TradingSession]:
return self._parseSessions(self.liquidHours)
def _parseSessions(self, s: str) -> List[TradingSession]:
tz = util.ZoneInfo(self.timeZoneId)
sessions = [
TradingSession(*[
dt.datetime.strptime(t, '%Y%m%d:%H%M').replace(tzinfo=tz)
for t in sess.split('-')])
for sess in s.split(';')]
return sessions

d = ib.reqContractDetails(Forex('EURUSD'))
print(d[-1].tradingSessions())

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
Cell In[16], line 2
      1 d = ib.reqContractDetails(Forex('EURUSD'))
----> 2 print(d[-1].tradingSessions())

File ~/Library/Caches/pypoetry/virtualenvs/ariobot-RQMH0swU-py3.10/lib/python3.10/site-packages/ib_insync/contract.py:519, in ContractDetails.tradingSessions(self)
    518 def tradingSessions(self) -> List[TradingSession]:
--> 519     return self._parseSessions(self.tradingHours)

File ~/Library/Caches/pypoetry/virtualenvs/ariobot-RQMH0swU-py3.10/lib/python3.10/site-packages/ib_insync/contract.py:526, in ContractDetails._parseSessions(self, s)
    524 def _parseSessions(self, s: str) -> List[TradingSession]:
    525     tz = util.ZoneInfo(self.timeZoneId)
--> 526     sessions = [
    527         TradingSession(*[
    528             dt.datetime.strptime(t, '%Y%m%d:%H%M').replace(tzinfo=tz)
    529             for t in sess.split('-')])
    530         for sess in s.split(';')]
    531     return sessions

File ~/Library/Caches/pypoetry/virtualenvs/ariobot-RQMH0swU-py3.10/lib/python3.10/site-packages/ib_insync/contract.py:527, in <listcomp>(.0)
    524 def _parseSessions(self, s: str) -> List[TradingSession]:
    525     tz = util.ZoneInfo(self.timeZoneId)
    526     sessions = [
--> 527         TradingSession(*[
    528             dt.datetime.strptime(t, '%Y%m%d:%H%M').replace(tzinfo=tz)
    529             for t in sess.split('-')])
    530         for sess in s.split(';')]
    531     return sessions

File ~/Library/Caches/pypoetry/virtualenvs/ariobot-RQMH0swU-py3.10/lib/python3.10/site-packages/ib_insync/contract.py:528, in <listcomp>(.0)
    524 def _parseSessions(self, s: str) -> List[TradingSession]:
    525     tz = util.ZoneInfo(self.timeZoneId)
    526     sessions = [
    527         TradingSession(*[
--> 528             dt.datetime.strptime(t, '%Y%m%d:%H%M').replace(tzinfo=tz)
    529             for t in sess.split('-')])
    530         for sess in s.split(';')]
    531     return sessions

File ~/.pyenv/versions/3.10.2/lib/python3.10/_strptime.py:568, in _strptime_datetime(cls, data_string, format)
    565 def _strptime_datetime(cls, data_string, format="%a %b %d %H:%M:%S %Y"):
    566     """Return a class cls instance based on the input string and the
    567     format string."""
--> 568     tt, fraction, gmtoff_fraction = _strptime(data_string, format)
    569     tzname, gmtoff = tt[-2:]
    570     args = tt[:6] + (fraction,)

File ~/.pyenv/versions/3.10.2/lib/python3.10/_strptime.py:349, in _strptime(data_string, format)
    347 found = format_regex.match(data_string)
    348 if not found:
--> 349     raise ValueError("time data %r does not match format %r" %
    350                      (data_string, format))
    351 if len(data_string) != found.end():
    352     raise ValueError("unconverted data remains: %s" %
    353                       data_string[found.end():])

ValueError: time data '20221217:CLOSED' does not match format '%Y%m%d:%H%M'
[in]:
d = ib.reqContractDetails(Forex('EURUSD'))
print(d[0].tradingHours)
print(d[0].liquidHours)

[out]:
20221215:1715-20221216:1700;20221217:CLOSED;20221218:1715-20221219:1700;20221219:1715-20221220:1700;20221220:1715-20221221:1700;20221221:1715-20221222:1700
20221215:1715-20221216:1700;20221217:CLOSED;20221218:1715-20221219:1700;20221219:1715-20221220:1700;20221220:1715-20221221:1700;20221221:1715-20221222:1700
flepied pushed a commit to flepied/ib_insync that referenced this issue Apr 4, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant