Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

copy_rates_range() does not work with datetime objects #7

Open
ahmadazizi opened this issue Sep 14, 2020 · 0 comments
Open

copy_rates_range() does not work with datetime objects #7

ahmadazizi opened this issue Sep 14, 2020 · 0 comments

Comments

@ahmadazizi
Copy link

Hi,
There is an issue when passing python datetime objects to copy_rates_range(symbol, timeframe, date_from, date_to)

Here is a part of the stack trace:

--- Logging error ---
Traceback (most recent call last):
  File "C:\Program Files\Python\lib\logging\__init__.py", line 1081, in emit
    msg = self.format(record)
  File "C:\Program Files\Python\lib\logging\__init__.py", line 925, in format
    return fmt.format(record)
  File "C:\Program Files\Python\lib\logging\__init__.py", line 664, in format
    record.message = record.getMessage()
  File "C:\Program Files\Python\lib\logging\__init__.py", line 367, in getMessage
    msg = str(self.msg)
  File "d:\pydev\exol\backend\.venv\lib\site-packages\pymt5adapter\helpers.py", line 26, in __str__
    res = f"{msg}\t{json.dumps(self)}"
  File "C:\Program Files\Python\lib\json\__init__.py", line 231, in dumps
    return _default_encoder.encode(obj)
  File "C:\Program Files\Python\lib\json\encoder.py", line 199, in encode
    chunks = self.iterencode(o, _one_shot=True)
  File "C:\Program Files\Python\lib\json\encoder.py", line 257, in iterencode
    return _iterencode(o, 0)
  File "C:\Program Files\Python\lib\json\encoder.py", line 179, in default
    raise TypeError(f'Object of type {o.__class__.__name__} '
TypeError: Object of type datetime is not JSON serializable
Call stack:
  File "C:\Program Files\Python\lib\runpy.py", line 194, in _run_module_as_main
    return _run_code(code, main_globals, None,
  File "C:\Program Files\Python\lib\runpy.py", line 87, in _run_code
    exec(code, run_globals)

I was able to solve this by passing timestamps instead of datetime objects, The docs says that either timestamp or datetime is acceptable. Have to mention that copy_rates_from() is fine with datetime.

@ahmadazizi ahmadazizi changed the title copy_rates_range() does not work with datetime() objects copy_rates_range() does not work with datetime objects Sep 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant