首页 > 解决方案 > 无法删除 backtrader 中日期时间格式的错误

问题描述

class dataFeed(btfeed.GenericCSVData):
    params = (
        ('dtformat', '%m%d%Y %H:%M:%S'),
        ('datetime', 0),
        ('open', 1),
        ('high', 2),
        ('low', 3),
        ('close', 4),
        ('volume', 5),
        ('openinterest', -1)
    )
    
ValueError: time data '12/24/2020 10:00' does not match format '%m%d%Y %H:%M:%S'

这是他时间戳的样子——12/24/2020 10:00:00 AM

标签: pythonbacktrader

解决方案


从字符串中删除斜杠:

dt_string = dt_string.replace("/", "")

或更改'dtformat'

('dtformat', '%m/%d/%Y %H:%M'),

推荐阅读