Key error Timestamp


  • This is the error i am facing while running my backtesting code
    File ~\anaconda3\Lib\site-packages\spyder_kernels\py3compat.py:356 in compat_exec
    exec(code, globals, locals)

    File c:\users\kswat\downloads\orb_strategy.py:16
    key_secret = open("key.txt","r").read().split()

    FileNotFoundError: [Errno 2] No such file or directory: 'key.txt'

    runfile('C:/Users/kswat/Downloads/orb_strategy.py', wdir='C:/Users/kswat/Downloads')
    [I 250106 13:24:29 smartConnect:121] in pool
    Traceback (most recent call last):

    File index.pyx:609 in pandas._libs.index.DatetimeEngine.get_loc

    File pandas\_libs\hashtable_class_helper.pxi:2606 in pandas._libs.hashtable.Int64HashTable.get_item

    File pandas\_libs\hashtable_class_helper.pxi:2630 in pandas._libs.hashtable.Int64HashTable.get_item

    KeyError: 1736154900000000000

    During handling of the above exception, another exception occurred:

    Traceback (most recent call last):

    File ~\anaconda3\Lib\site-packages\pandas\core\indexes\base.py:3805 in get_loc
    return self._engine.get_loc(casted_key)

    File index.pyx:577 in pandas._libs.index.DatetimeEngine.get_loc

    File index.pyx:611 in pandas._libs.index.DatetimeEngine.get_loc

    KeyError: Timestamp('2025-01-06 09:15:00')

    The above exception was the direct cause of the following exception:

    Traceback (most recent call last):

    File ~\anaconda3\Lib\site-packages\pandas\core\indexes\datetimes.py:630 in get_loc
    return Index.get_loc(self, key)

    File ~\anaconda3\Lib\site-packages\pandas\core\indexes\base.py:3812 in get_loc
    raise KeyError(key) from err

    KeyError: Timestamp('2025-01-06 09:15:00')

    The above exception was the direct cause of the following exception:

    Traceback (most recent call last):

    File ~\anaconda3\Lib\site-packages\spyder_kernels\py3compat.py:356 in compat_exec
    exec(code, globals, locals)

    File c:\users\kswat\downloads\orb_strategy.py:144
    tickers = filtered_tickers(data_0920) #identify tickers with maximum gap up/down

    File c:\users\kswat\downloads\orb_strategy.py:107 in filtered_tickers
    temp.loc[ticker] = data[ticker].loc[date,"gap"]

    File ~\anaconda3\Lib\site-packages\pandas\core\indexing.py:1183 in getitem
    return self.obj._get_value(*key, takeable=self._takeable)

    File ~\anaconda3\Lib\site-packages\pandas\core\frame.py:4221 in _get_value
    row = self.index.get_loc(index)

    File ~\anaconda3\Lib\site-packages\pandas\core\indexes\datetimes.py:632 in get_loc
    raise KeyError(orig_key) from err

    KeyError: Timestamp('2025-01-06 09:15:00')


  • @swathi-priya this is not a SmartAPI issue. The issue is with your code. Please take a help of a professional developer, or guidance from someone on the forum for this issue.